comparison ocb_encrypt_authenticate_memory.c @ 3:7faae8f46238 libtomcrypt-orig

Branch renaming
author Matt Johnston <matt@ucc.asn.au>
date Mon, 31 May 2004 18:25:41 +0000
parents
children 5d99163f7e32
comparison
equal deleted inserted replaced
-1:000000000000 3:7faae8f46238
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org
10 */
11
12 /* OCB Implementation by Tom St Denis */
13 #include "mycrypt.h"
14
15 #ifdef OCB_MODE
16
17 int ocb_encrypt_authenticate_memory(int cipher,
18 const unsigned char *key, unsigned long keylen,
19 const unsigned char *nonce,
20 const unsigned char *pt, unsigned long ptlen,
21 unsigned char *ct,
22 unsigned char *tag, unsigned long *taglen)
23 {
24 int err;
25 ocb_state ocb;
26
27 _ARGCHK(key != NULL);
28 _ARGCHK(nonce != NULL);
29 _ARGCHK(pt != NULL);
30 _ARGCHK(ct != NULL);
31 _ARGCHK(tag != NULL);
32 _ARGCHK(taglen != NULL);
33
34 if ((err = ocb_init(&ocb, cipher, key, keylen, nonce)) != CRYPT_OK) {
35 return err;
36 }
37
38 while (ptlen > (unsigned long)ocb.block_len) {
39 if ((err = ocb_encrypt(&ocb, pt, ct)) != CRYPT_OK) {
40 return err;
41 }
42 ptlen -= ocb.block_len;
43 pt += ocb.block_len;
44 ct += ocb.block_len;
45 }
46
47 return ocb_done_encrypt(&ocb, pt, ptlen, ct, tag, taglen);
48 }
49
50 #endif