]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | /* | |
13 | * Copyright 1993 by OpenVision Technologies, Inc. | |
cca5172a | 14 | * |
1da177e4 LT |
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. | |
cca5172a | 24 | * |
1da177e4 LT |
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. | |
32 | */ | |
33 | ||
34 | #include <linux/types.h> | |
1da177e4 LT |
35 | #include <linux/sunrpc/gss_krb5.h> |
36 | #include <linux/crypto.h> | |
37 | ||
38 | #ifdef RPC_DEBUG | |
39 | # define RPCDBG_FACILITY RPCDBG_AUTH | |
40 | #endif | |
41 | ||
42 | s32 | |
378c6697 | 43 | krb5_make_seq_num(struct crypto_blkcipher *key, |
1da177e4 | 44 | int direction, |
5743d65c | 45 | u32 seqnum, |
1da177e4 LT |
46 | unsigned char *cksum, unsigned char *buf) |
47 | { | |
48 | unsigned char plain[8]; | |
49 | ||
50 | plain[0] = (unsigned char) (seqnum & 0xff); | |
51 | plain[1] = (unsigned char) ((seqnum >> 8) & 0xff); | |
52 | plain[2] = (unsigned char) ((seqnum >> 16) & 0xff); | |
53 | plain[3] = (unsigned char) ((seqnum >> 24) & 0xff); | |
54 | ||
55 | plain[4] = direction; | |
56 | plain[5] = direction; | |
57 | plain[6] = direction; | |
58 | plain[7] = direction; | |
59 | ||
60 | return krb5_encrypt(key, cksum, plain, buf, 8); | |
61 | } | |
62 | ||
63 | s32 | |
378c6697 | 64 | krb5_get_seq_num(struct crypto_blkcipher *key, |
1da177e4 LT |
65 | unsigned char *cksum, |
66 | unsigned char *buf, | |
5743d65c | 67 | int *direction, u32 *seqnum) |
1da177e4 LT |
68 | { |
69 | s32 code; | |
70 | unsigned char plain[8]; | |
71 | ||
8885cb36 | 72 | dprintk("RPC: krb5_get_seq_num:\n"); |
1da177e4 LT |
73 | |
74 | if ((code = krb5_decrypt(key, cksum, buf, plain, 8))) | |
75 | return code; | |
76 | ||
f64f9e71 JP |
77 | if ((plain[4] != plain[5]) || (plain[4] != plain[6]) || |
78 | (plain[4] != plain[7])) | |
1da177e4 LT |
79 | return (s32)KG_BAD_SEQ; |
80 | ||
81 | *direction = plain[4]; | |
82 | ||
83 | *seqnum = ((plain[0]) | | |
84 | (plain[1] << 8) | (plain[2] << 16) | (plain[3] << 24)); | |
85 | ||
86 | return (0); | |
87 | } |