comparison libtomcrypt/src/encauth/gcm/gcm_memory.c @ 293:9d110777f345 contrib-blacklist

propagate from branch 'au.asn.ucc.matt.dropbear' (head 7ad1775ed65e75dbece27fe6b65bf1a234db386a) to branch 'au.asn.ucc.matt.dropbear.contrib.blacklist' (head 1d86a4f0a401cc68c2670d821a2f6366c37af143)
author Matt Johnston <matt@ucc.asn.au>
date Fri, 10 Mar 2006 06:31:29 +0000
parents 1b9e69c058d2
children 0cbe8f6dbf9e
comparison
equal deleted inserted replaced
247:c07de41b53d7 293:9d110777f345
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 gcm_memory.c
14 GCM implementation, process a packet, by Tom St Denis
15 */
16 #include "tomcrypt.h"
17
18 #ifdef GCM_MODE
19
20 /**
21 Process an entire GCM packet in one call.
22 @param cipher Index of cipher to use
23 @param key The secret key
24 @param keylen The length of the secret key
25 @param IV The initial vector
26 @param IVlen The length of the initial vector
27 @param adata The additional authentication data (header)
28 @param adatalen The length of the adata
29 @param pt The plaintext
30 @param ptlen The length of the plaintext (ciphertext length is the same)
31 @param ct The ciphertext
32 @param tag [out] The MAC tag
33 @param taglen [in/out] The MAC tag length
34 @param direction Encrypt or Decrypt mode (GCM_ENCRYPT or GCM_DECRYPT)
35 @return CRYPT_OK on success
36 */
37 int gcm_memory( int cipher,
38 const unsigned char *key, unsigned long keylen,
39 const unsigned char *IV, unsigned long IVlen,
40 const unsigned char *adata, unsigned long adatalen,
41 unsigned char *pt, unsigned long ptlen,
42 unsigned char *ct,
43 unsigned char *tag, unsigned long *taglen,
44 int direction)
45 {
46 gcm_state *gcm;
47 int err;
48
49 if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
50 return err;
51 }
52
53 if (cipher_descriptor[cipher].accel_gcm_memory != NULL) {
54 cipher_descriptor[cipher].accel_gcm_memory
55 (key, keylen,
56 IV, IVlen,
57 adata, adatalen,
58 pt, ptlen,
59 ct,
60 tag, taglen,
61 direction);
62 return CRYPT_OK;
63 }
64
65
66 gcm = XMALLOC(sizeof(*gcm));
67 if (gcm == NULL) {
68 return CRYPT_MEM;
69 }
70
71 if ((err = gcm_init(gcm, cipher, key, keylen)) != CRYPT_OK) {
72 goto LTC_ERR;
73 }
74 if ((err = gcm_add_iv(gcm, IV, IVlen)) != CRYPT_OK) {
75 goto LTC_ERR;
76 }
77 if ((err = gcm_add_aad(gcm, adata, adatalen)) != CRYPT_OK) {
78 goto LTC_ERR;
79 }
80 if ((err = gcm_process(gcm, pt, ptlen, ct, direction)) != CRYPT_OK) {
81 goto LTC_ERR;
82 }
83 err = gcm_done(gcm, tag, taglen);
84 LTC_ERR:
85 XFREE(gcm);
86 return err;
87 }
88 #endif
89
90
91 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_memory.c,v $ */
92 /* $Revision: 1.19 $ */
93 /* $Date: 2005/05/05 14:35:58 $ */