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
9
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
13
@file ocb_decrypt_verify_memory.c
14
OCB implementation, helper to decrypt block of memory, by Tom St Denis
21
Decrypt and compare the tag with OCB.
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 size of the block cipher)
26
@param ct The ciphertext
27
@param ctlen The length of the ciphertext (octets)
28
@param pt [out] The plaintext
29
@param tag The tag to compare against
30
@param taglen The length of the tag (octets)
31
@param stat [out] The result of the tag comparison (1==valid, 0==invalid)
32
@return CRYPT_OK if successful regardless of the tag comparison
34
int ocb_decrypt_verify_memory(int cipher,
35
const unsigned char *key, unsigned long keylen,
36
const unsigned char *nonce,
37
const unsigned char *ct, unsigned long ctlen,
39
const unsigned char *tag, unsigned long taglen,
45
LTC_ARGCHK(key != NULL);
46
LTC_ARGCHK(nonce != NULL);
47
LTC_ARGCHK(pt != NULL);
48
LTC_ARGCHK(ct != NULL);
49
LTC_ARGCHK(tag != NULL);
50
LTC_ARGCHK(stat != NULL);
53
ocb = XMALLOC(sizeof(ocb_state));
58
if ((err = ocb_init(ocb, cipher, key, keylen, nonce)) != CRYPT_OK) {
62
while (ctlen > (unsigned long)ocb->block_len) {
63
if ((err = ocb_decrypt(ocb, ct, pt)) != CRYPT_OK) {
66
ctlen -= ocb->block_len;
71
err = ocb_done_decrypt(ocb, ct, ctlen, pt, tag, taglen, stat);
73
#ifdef LTC_CLEAN_STACK
74
zeromem(ocb, sizeof(ocb_state));
84
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_decrypt_verify_memory.c,v $ */
85
/* $Revision: 1.3 $ */
86
/* $Date: 2005/05/05 14:35:58 $ */