1 #pragma ident "%Z%%M% %I% %E% SMI"
4 * Copyright2001 by the Massachusetts Institute of Technology.
5 * Copyright 1993 by OpenVision Technologies, Inc.
7 * Permission to use, copy, modify, distribute, and sell this software
8 * and its documentation for any purpose is hereby granted without fee,
9 * provided that the above copyright notice appears in all copies and
10 * that both that copyright notice and this permission notice appear in
11 * supporting documentation, and that the name of OpenVision not be used
12 * in advertising or publicity pertaining to distribution of the software
13 * without specific, written prior permission. OpenVision makes no
14 * representations about the suitability of this software for any
15 * purpose. It is provided "as is" without express or implied warranty.
17 * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19 * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
21 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23 * PERFORMANCE OF THIS SOFTWARE.
26 #include "gssapiP_krb5.h"
30 * $Id: util_seqnum.c 15007 2002-11-15 16:12:20Z epeisach $
34 kg_make_seq_num(context
, key
, direction
, seqnum
, cksum
, buf
)
42 unsigned char plain
[8];
48 if (key
->enctype
== ENCTYPE_ARCFOUR_HMAC
) {
49 /* Yes, Microsoft used big-endian sequence number.*/
50 plain
[0] = (seqnum
>>24) & 0xff;
51 plain
[1] = (seqnum
>>16) & 0xff;
52 plain
[2] = (seqnum
>>8) & 0xff;
53 plain
[3] = seqnum
& 0xff;
54 return kg_arcfour_docrypt (context
, key
, 0,
61 plain
[0] = (unsigned char) (seqnum
&0xff);
62 plain
[1] = (unsigned char) ((seqnum
>>8)&0xff);
63 plain
[2] = (unsigned char) ((seqnum
>>16)&0xff);
64 plain
[3] = (unsigned char) ((seqnum
>>24)&0xff);
66 return(kg_encrypt(context
, key
, KG_USAGE_SEQ
, cksum
, plain
, buf
, 8));
69 krb5_error_code
kg_get_seq_num(context
, key
, cksum
, buf
, direction
, seqnum
)
78 unsigned char plain
[8];
80 if (key
->enctype
== ENCTYPE_ARCFOUR_HMAC
) {
81 code
= kg_arcfour_docrypt (context
, key
, 0,
86 code
= kg_decrypt(context
, key
, KG_USAGE_SEQ
, cksum
, buf
, plain
, 8);
91 if ((plain
[4] != plain
[5]) ||
92 (plain
[4] != plain
[6]) ||
93 (plain
[4] != plain
[7]))
94 return((krb5_error_code
) KG_BAD_SEQ
);
96 *direction
= plain
[4];
97 if (key
->enctype
== ENCTYPE_ARCFOUR_HMAC
) {
98 *seqnum
= (plain
[3]|(plain
[2]<<8) | (plain
[1]<<16)| (plain
[0]<<24));
100 *seqnum
= ((plain
[0]) |