1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
11 @file ocb3_encrypt_authenticate_memory.c
12 OCB implementation, encrypt block of memory, by Tom St Denis
19 Encrypt and generate an authentication code for a buffer of memory
20 @param cipher The index of the cipher desired
21 @param key The secret key
22 @param keylen The length of the secret key (octets)
23 @param nonce The session nonce (length of the block ciphers block size)
24 @param noncelen The length of the nonce (octets)
25 @param adata The AAD - additional associated data
26 @param adatalen The length of AAD (octets)
27 @param pt The plaintext
28 @param ptlen The length of the plaintext (octets)
29 @param ct [out] The ciphertext
30 @param tag [out] The authentication tag
31 @param taglen [in/out] The max size and resulting size of the authentication tag
32 @return CRYPT_OK if successful
34 int ocb3_encrypt_authenticate_memory(int cipher,
35 const unsigned char *key, unsigned long keylen,
36 const unsigned char *nonce, unsigned long noncelen,
37 const unsigned char *adata, unsigned long adatalen,
38 const unsigned char *pt, unsigned long ptlen,
40 unsigned char *tag, unsigned long *taglen)
45 LTC_ARGCHK(taglen != NULL);
48 ocb = XMALLOC(sizeof(ocb3_state));
53 if ((err = ocb3_init(ocb, cipher, key, keylen, nonce, noncelen, *taglen)) != CRYPT_OK) {
57 if (adata != NULL || adatalen != 0) {
58 if ((err = ocb3_add_aad(ocb, adata, adatalen)) != CRYPT_OK) {
63 if ((err = ocb3_encrypt_last(ocb, pt, ptlen, ct)) != CRYPT_OK) {
67 err = ocb3_done(ocb, tag, taglen);
70 #ifdef LTC_CLEAN_STACK
71 zeromem(ocb, sizeof(ocb3_state));
80 /* ref: $Format:%D$ */
81 /* git commit: $Format:%H$ */
82 /* commit time: $Format:%ai$ */