Mercurial > dropbear
comparison src/encauth/ocb/ocb_encrypt_authenticate_memory.c @ 192:9cc34777b479 libtomcrypt
propagate from branch 'au.asn.ucc.matt.ltc-orig' (head 9ba8f01f44320e9cb9f19881105ae84f84a43ea9)
to branch 'au.asn.ucc.matt.dropbear.ltc' (head dbf51c569bc34956ad948e4cc87a0eeb2170b768)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 08 May 2005 06:36:47 +0000 |
parents | 1c15b283127b |
children | 39d5d58461d6 |
comparison
equal
deleted
inserted
replaced
164:cd1143579f00 | 192:9cc34777b479 |
---|---|
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 /** | |
13 @file ocb_encrypt_authenticate_memory.c | |
14 OCB implementation, encrypt block of memory, by Tom St Denis | |
15 */ | |
16 #include "tomcrypt.h" | |
17 | |
18 #ifdef OCB_MODE | |
19 | |
20 /** | |
21 Encrypt and generate an authentication code for a buffer of memory | |
22 @param cipher The index of the cipher desired | |
23 @param key The secret key | |
24 @param keylen The length of the secret key (octets) | |
25 @param nonce The session nonce (length of the block ciphers block size) | |
26 @param pt The plaintext | |
27 @param ptlen The length of the plaintext (octets) | |
28 @param ct [out] The ciphertext | |
29 @param tag [out] The authentication tag | |
30 @param taglen [in/out] The max size and resulting size of the authentication tag | |
31 @return CRYPT_OK if successful | |
32 */ | |
33 int ocb_encrypt_authenticate_memory(int cipher, | |
34 const unsigned char *key, unsigned long keylen, | |
35 const unsigned char *nonce, | |
36 const unsigned char *pt, unsigned long ptlen, | |
37 unsigned char *ct, | |
38 unsigned char *tag, unsigned long *taglen) | |
39 { | |
40 int err; | |
41 ocb_state *ocb; | |
42 | |
43 LTC_ARGCHK(key != NULL); | |
44 LTC_ARGCHK(nonce != NULL); | |
45 LTC_ARGCHK(pt != NULL); | |
46 LTC_ARGCHK(ct != NULL); | |
47 LTC_ARGCHK(tag != NULL); | |
48 LTC_ARGCHK(taglen != NULL); | |
49 | |
50 /* allocate ram */ | |
51 ocb = XMALLOC(sizeof(ocb_state)); | |
52 if (ocb == NULL) { | |
53 return CRYPT_MEM; | |
54 } | |
55 | |
56 if ((err = ocb_init(ocb, cipher, key, keylen, nonce)) != CRYPT_OK) { | |
57 goto LBL_ERR; | |
58 } | |
59 | |
60 while (ptlen > (unsigned long)ocb->block_len) { | |
61 if ((err = ocb_encrypt(ocb, pt, ct)) != CRYPT_OK) { | |
62 goto LBL_ERR; | |
63 } | |
64 ptlen -= ocb->block_len; | |
65 pt += ocb->block_len; | |
66 ct += ocb->block_len; | |
67 } | |
68 | |
69 err = ocb_done_encrypt(ocb, pt, ptlen, ct, tag, taglen); | |
70 LBL_ERR: | |
71 #ifdef LTC_CLEAN_STACK | |
72 zeromem(ocb, sizeof(ocb_state)); | |
73 #endif | |
74 | |
75 XFREE(ocb); | |
76 | |
77 return err; | |
78 } | |
79 | |
80 #endif |