comparison libtomcrypt/src/encauth/ocb/ocb_encrypt_authenticate_memory.c @ 297:79bf1023cf11 agent-client

propagate from branch 'au.asn.ucc.matt.dropbear' (head 0501e6f661b5415eb76f3b312d183c3adfbfb712) to branch 'au.asn.ucc.matt.dropbear.cli-agent' (head 01038174ec27245b51bd43a66c01ad930880f67b)
author Matt Johnston <matt@ucc.asn.au>
date Tue, 21 Mar 2006 16:20:59 +0000
parents 1b9e69c058d2
children 0cbe8f6dbf9e
comparison
equal deleted inserted replaced
225:ca7e76d981d9 297:79bf1023cf11
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
81
82 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_encrypt_authenticate_memory.c,v $ */
83 /* $Revision: 1.3 $ */
84 /* $Date: 2005/05/05 14:35:58 $ */