gss_krb5_seqnum.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/slab.h>
  34. #include <linux/sunrpc/gss_krb5.h>
  35. #include <linux/crypto.h>
  36. #ifdef RPC_DEBUG
  37. # define RPCDBG_FACILITY RPCDBG_AUTH
  38. #endif
  39. s32
  40. krb5_make_seq_num(struct crypto_blkcipher *key,
  41. int direction,
  42. s32 seqnum,
  43. unsigned char *cksum, unsigned char *buf)
  44. {
  45. unsigned char plain[8];
  46. plain[0] = (unsigned char) (seqnum & 0xff);
  47. plain[1] = (unsigned char) ((seqnum >> 8) & 0xff);
  48. plain[2] = (unsigned char) ((seqnum >> 16) & 0xff);
  49. plain[3] = (unsigned char) ((seqnum >> 24) & 0xff);
  50. plain[4] = direction;
  51. plain[5] = direction;
  52. plain[6] = direction;
  53. plain[7] = direction;
  54. return krb5_encrypt(key, cksum, plain, buf, 8);
  55. }
  56. s32
  57. krb5_get_seq_num(struct crypto_blkcipher *key,
  58. unsigned char *cksum,
  59. unsigned char *buf,
  60. int *direction, s32 * seqnum)
  61. {
  62. s32 code;
  63. unsigned char plain[8];
  64. dprintk("RPC: krb5_get_seq_num:\n");
  65. if ((code = krb5_decrypt(key, cksum, buf, plain, 8)))
  66. return code;
  67. if ((plain[4] != plain[5]) || (plain[4] != plain[6])
  68. || (plain[4] != plain[7]))
  69. return (s32)KG_BAD_SEQ;
  70. *direction = plain[4];
  71. *seqnum = ((plain[0]) |
  72. (plain[1] << 8) | (plain[2] << 16) | (plain[3] << 24));
  73. return (0);
  74. }