gss_krb5_seqnum.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * linux/net/sunrpc/gss_krb5_seqnum.c
  3. *
  4. * Adapted from MIT Kerberos 5-1.2.1 lib/gssapi/krb5/util_seqnum.c
  5. *
  6. * Copyright (c) 2000 The Regents of the University of Michigan.
  7. * All rights reserved.
  8. *
  9. * Andy Adamson <andros@umich.edu>
  10. */
  11. /*
  12. * Copyright 1993 by OpenVision Technologies, Inc.
  13. *
  14. * Permission to use, copy, modify, distribute, and sell this software
  15. * and its documentation for any purpose is hereby granted without fee,
  16. * provided that the above copyright notice appears in all copies and
  17. * that both that copyright notice and this permission notice appear in
  18. * supporting documentation, and that the name of OpenVision not be used
  19. * in advertising or publicity pertaining to distribution of the software
  20. * without specific, written prior permission. OpenVision makes no
  21. * representations about the suitability of this software for any
  22. * purpose. It is provided "as is" without express or implied warranty.
  23. *
  24. * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  25. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  26. * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  27. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  28. * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  29. * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  30. * PERFORMANCE OF THIS SOFTWARE.
  31. */
  32. #include <linux/types.h>
  33. #include <linux/sunrpc/gss_krb5.h>
  34. #include <linux/crypto.h>
  35. #ifdef RPC_DEBUG
  36. # define RPCDBG_FACILITY RPCDBG_AUTH
  37. #endif
  38. s32
  39. krb5_make_seq_num(struct crypto_blkcipher *key,
  40. int direction,
  41. u32 seqnum,
  42. unsigned char *cksum, unsigned char *buf)
  43. {
  44. unsigned char plain[8];
  45. plain[0] = (unsigned char) (seqnum & 0xff);
  46. plain[1] = (unsigned char) ((seqnum >> 8) & 0xff);
  47. plain[2] = (unsigned char) ((seqnum >> 16) & 0xff);
  48. plain[3] = (unsigned char) ((seqnum >> 24) & 0xff);
  49. plain[4] = direction;
  50. plain[5] = direction;
  51. plain[6] = direction;
  52. plain[7] = direction;
  53. return krb5_encrypt(key, cksum, plain, buf, 8);
  54. }
  55. s32
  56. krb5_get_seq_num(struct crypto_blkcipher *key,
  57. unsigned char *cksum,
  58. unsigned char *buf,
  59. int *direction, u32 *seqnum)
  60. {
  61. s32 code;
  62. unsigned char plain[8];
  63. dprintk("RPC: krb5_get_seq_num:\n");
  64. if ((code = krb5_decrypt(key, cksum, buf, plain, 8)))
  65. return code;
  66. if ((plain[4] != plain[5]) || (plain[4] != plain[6]) ||
  67. (plain[4] != plain[7]))
  68. return (s32)KG_BAD_SEQ;
  69. *direction = plain[4];
  70. *seqnum = ((plain[0]) |
  71. (plain[1] << 8) | (plain[2] << 16) | (plain[3] << 24));
  72. return (0);
  73. }