comparison src/encauth/ocb/ocb_decrypt_verify_memory.c @ 280:59400faa4b44 libtomcrypt-orig libtomcrypt-1.05

Re-import libtomcrypt 1.05 for cleaner propagating. From crypt-1.05.tar.bz2, SHA1 of 88250202bb51570dc64f7e8f1c943cda9479258f
author Matt Johnston <matt@ucc.asn.au>
date Wed, 08 Mar 2006 12:58:00 +0000
parents
children d5faf4814ddb
comparison
equal deleted inserted replaced
-1:000000000000 280:59400faa4b44
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_decrypt_verify_memory.c
14 OCB implementation, helper to decrypt block of memory, by Tom St Denis
15 */
16 #include "tomcrypt.h"
17
18 #ifdef OCB_MODE
19
20 /**
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
33 */
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,
38 unsigned char *pt,
39 const unsigned char *tag, unsigned long taglen,
40 int *stat)
41 {
42 int err;
43 ocb_state *ocb;
44
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);
51
52 /* allocate memory */
53 ocb = XMALLOC(sizeof(ocb_state));
54 if (ocb == NULL) {
55 return CRYPT_MEM;
56 }
57
58 if ((err = ocb_init(ocb, cipher, key, keylen, nonce)) != CRYPT_OK) {
59 goto LBL_ERR;
60 }
61
62 while (ctlen > (unsigned long)ocb->block_len) {
63 if ((err = ocb_decrypt(ocb, ct, pt)) != CRYPT_OK) {
64 goto LBL_ERR;
65 }
66 ctlen -= ocb->block_len;
67 pt += ocb->block_len;
68 ct += ocb->block_len;
69 }
70
71 err = ocb_done_decrypt(ocb, ct, ctlen, pt, tag, taglen, stat);
72 LBL_ERR:
73 #ifdef LTC_CLEAN_STACK
74 zeromem(ocb, sizeof(ocb_state));
75 #endif
76
77 XFREE(ocb);
78
79 return err;
80 }
81
82 #endif
83
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 $ */