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 ocb_decrypt_verify_memory.c
12 OCB implementation, helper to decrypt block of memory, by Tom St Denis
19 Decrypt and compare the tag with OCB.
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 size of the block cipher)
24 @param ct The ciphertext
25 @param ctlen The length of the ciphertext (octets)
26 @param pt [out] The plaintext
27 @param tag The tag to compare against
28 @param taglen The length of the tag (octets)
29 @param stat [out] The result of the tag comparison (1==valid, 0==invalid)
30 @return CRYPT_OK if successful regardless of the tag comparison
32 int ocb_decrypt_verify_memory(int cipher,
33 const unsigned char *key, unsigned long keylen,
34 const unsigned char *nonce,
35 const unsigned char *ct, unsigned long ctlen,
37 const unsigned char *tag, unsigned long taglen,
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(stat != NULL);
51 ocb = XMALLOC(sizeof(ocb_state));
56 if ((err = ocb_init(ocb, cipher, key, keylen, nonce)) != CRYPT_OK) {
60 while (ctlen > (unsigned long)ocb->block_len) {
61 if ((err = ocb_decrypt(ocb, ct, pt)) != CRYPT_OK) {
64 ctlen -= ocb->block_len;
69 err = ocb_done_decrypt(ocb, ct, ctlen, pt, tag, taglen, stat);
71 #ifdef LTC_CLEAN_STACK
72 zeromem(ocb, sizeof(ocb_state));
82 /* ref: $Format:%D$ */
83 /* git commit: $Format:%H$ */
84 /* commit time: $Format:%ai$ */