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