Mercurial > dropbear
comparison s_ocb_done.c @ 143:5d99163f7e32 libtomcrypt-orig
import of libtomcrypt 0.99
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 19 Dec 2004 11:34:45 +0000 |
parents | 7faae8f46238 |
children |
comparison
equal
deleted
inserted
replaced
15:6362d3854bb4 | 143:5d99163f7e32 |
---|---|
23 */ | 23 */ |
24 int __ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen, | 24 int __ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen, |
25 unsigned char *ct, unsigned char *tag, unsigned long *taglen, int mode) | 25 unsigned char *ct, unsigned char *tag, unsigned long *taglen, int mode) |
26 | 26 |
27 { | 27 { |
28 unsigned char Z[MAXBLOCKSIZE], Y[MAXBLOCKSIZE], X[MAXBLOCKSIZE]; | 28 unsigned char *Z, *Y, *X; |
29 int err, x; | 29 int err, x; |
30 | 30 |
31 _ARGCHK(ocb != NULL); | 31 _ARGCHK(ocb != NULL); |
32 _ARGCHK(pt != NULL); | 32 _ARGCHK(pt != NULL); |
33 _ARGCHK(ct != NULL); | 33 _ARGCHK(ct != NULL); |
39 if (ocb->block_len != cipher_descriptor[ocb->cipher].block_length || | 39 if (ocb->block_len != cipher_descriptor[ocb->cipher].block_length || |
40 (int)ptlen > ocb->block_len || (int)ptlen < 0) { | 40 (int)ptlen > ocb->block_len || (int)ptlen < 0) { |
41 return CRYPT_INVALID_ARG; | 41 return CRYPT_INVALID_ARG; |
42 } | 42 } |
43 | 43 |
44 /* allocate ram */ | |
45 Z = XMALLOC(MAXBLOCKSIZE); | |
46 Y = XMALLOC(MAXBLOCKSIZE); | |
47 X = XMALLOC(MAXBLOCKSIZE); | |
48 if (X == NULL || Y == NULL || Z == NULL) { | |
49 if (X != NULL) { | |
50 XFREE(X); | |
51 } | |
52 if (Y != NULL) { | |
53 XFREE(Y); | |
54 } | |
55 if (Z != NULL) { | |
56 XFREE(Z); | |
57 } | |
58 return CRYPT_MEM; | |
59 } | |
60 | |
44 /* compute X[m] = len(pt[m]) XOR Lr XOR Z[m] */ | 61 /* compute X[m] = len(pt[m]) XOR Lr XOR Z[m] */ |
45 ocb_shift_xor(ocb, X); | 62 ocb_shift_xor(ocb, X); |
46 memcpy(Z, X, ocb->block_len); | 63 XMEMCPY(Z, X, ocb->block_len); |
47 | 64 |
48 X[ocb->block_len-1] ^= (ptlen*8)&255; | 65 X[ocb->block_len-1] ^= (ptlen*8)&255; |
49 X[ocb->block_len-2] ^= ((ptlen*8)>>8)&255; | 66 X[ocb->block_len-2] ^= ((ptlen*8)>>8)&255; |
50 for (x = 0; x < ocb->block_len; x++) { | 67 for (x = 0; x < ocb->block_len; x++) { |
51 X[x] ^= ocb->Lr[x]; | 68 X[x] ^= ocb->Lr[x]; |
88 tag[x] = X[x]; | 105 tag[x] = X[x]; |
89 } | 106 } |
90 *taglen = x; | 107 *taglen = x; |
91 | 108 |
92 #ifdef CLEAN_STACK | 109 #ifdef CLEAN_STACK |
93 zeromem(X, sizeof(X)); | 110 zeromem(X, MAXBLOCKSIZE); |
94 zeromem(Y, sizeof(Y)); | 111 zeromem(Y, MAXBLOCKSIZE); |
95 zeromem(Z, sizeof(Z)); | 112 zeromem(Z, MAXBLOCKSIZE); |
96 zeromem(ocb, sizeof(*ocb)); | 113 zeromem(ocb, sizeof(*ocb)); |
97 #endif | 114 #endif |
115 | |
116 XFREE(X); | |
117 XFREE(Y); | |
118 XFREE(Z); | |
119 | |
98 return CRYPT_OK; | 120 return CRYPT_OK; |
99 } | 121 } |
100 | 122 |
101 #endif | 123 #endif |
102 | 124 |