comparison ocb_encrypt_authenticate_memory.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
20 const unsigned char *pt, unsigned long ptlen, 20 const unsigned char *pt, unsigned long ptlen,
21 unsigned char *ct, 21 unsigned char *ct,
22 unsigned char *tag, unsigned long *taglen) 22 unsigned char *tag, unsigned long *taglen)
23 { 23 {
24 int err; 24 int err;
25 ocb_state ocb; 25 ocb_state *ocb;
26 26
27 _ARGCHK(key != NULL); 27 _ARGCHK(key != NULL);
28 _ARGCHK(nonce != NULL); 28 _ARGCHK(nonce != NULL);
29 _ARGCHK(pt != NULL); 29 _ARGCHK(pt != NULL);
30 _ARGCHK(ct != NULL); 30 _ARGCHK(ct != NULL);
31 _ARGCHK(tag != NULL); 31 _ARGCHK(tag != NULL);
32 _ARGCHK(taglen != NULL); 32 _ARGCHK(taglen != NULL);
33 33
34 if ((err = ocb_init(&ocb, cipher, key, keylen, nonce)) != CRYPT_OK) { 34 /* allocate ram */
35 return err; 35 ocb = XMALLOC(sizeof(ocb_state));
36 if (ocb == NULL) {
37 return CRYPT_MEM;
36 } 38 }
37 39
38 while (ptlen > (unsigned long)ocb.block_len) { 40 if ((err = ocb_init(ocb, cipher, key, keylen, nonce)) != CRYPT_OK) {
39 if ((err = ocb_encrypt(&ocb, pt, ct)) != CRYPT_OK) { 41 goto __ERR;
40 return err;
41 }
42 ptlen -= ocb.block_len;
43 pt += ocb.block_len;
44 ct += ocb.block_len;
45 } 42 }
46 43
47 return ocb_done_encrypt(&ocb, pt, ptlen, ct, tag, taglen); 44 while (ptlen > (unsigned long)ocb->block_len) {
45 if ((err = ocb_encrypt(ocb, pt, ct)) != CRYPT_OK) {
46 goto __ERR;
47 }
48 ptlen -= ocb->block_len;
49 pt += ocb->block_len;
50 ct += ocb->block_len;
51 }
52
53 err = ocb_done_encrypt(ocb, pt, ptlen, ct, tag, taglen);
54 __ERR:
55 #ifdef CLEAN_STACK
56 zeromem(ocb, sizeof(ocb_state));
57 #endif
58
59 XFREE(ocb);
60
61 return err;
48 } 62 }
49 63
50 #endif 64 #endif