comparison src/encauth/gcm/gcm_memory.c @ 381:999a5eb4ed10 libtomcrypt-dropbear

propagate from branch 'au.asn.ucc.matt.ltc.orig' (head 52840647ac7f5c707c3bd158d119a15734a7ef28) to branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 02:39:21 +0000
parents d5faf4814ddb
children
comparison
equal deleted inserted replaced
281:997e6f7dc01e 381:999a5eb4ed10
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 * 8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org 9 * Tom St Denis, [email protected], http://libtomcrypt.com
10 */ 10 */
11 11
12 /** 12 /**
13 @file gcm_memory.c 13 @file gcm_memory.c
14 GCM implementation, process a packet, by Tom St Denis 14 GCM implementation, process a packet, by Tom St Denis
41 unsigned char *pt, unsigned long ptlen, 41 unsigned char *pt, unsigned long ptlen,
42 unsigned char *ct, 42 unsigned char *ct,
43 unsigned char *tag, unsigned long *taglen, 43 unsigned char *tag, unsigned long *taglen,
44 int direction) 44 int direction)
45 { 45 {
46 void *orig;
46 gcm_state *gcm; 47 gcm_state *gcm;
47 int err; 48 int err;
48 49
49 if ((err = cipher_is_valid(cipher)) != CRYPT_OK) { 50 if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
50 return err; 51 return err;
51 } 52 }
52 53
53 if (cipher_descriptor[cipher].accel_gcm_memory != NULL) { 54 if (cipher_descriptor[cipher].accel_gcm_memory != NULL) {
54 cipher_descriptor[cipher].accel_gcm_memory 55 return
56 cipher_descriptor[cipher].accel_gcm_memory
55 (key, keylen, 57 (key, keylen,
56 IV, IVlen, 58 IV, IVlen,
57 adata, adatalen, 59 adata, adatalen,
58 pt, ptlen, 60 pt, ptlen,
59 ct, 61 ct,
60 tag, taglen, 62 tag, taglen,
61 direction); 63 direction);
62 return CRYPT_OK;
63 } 64 }
64 65
65 66
66 gcm = XMALLOC(sizeof(*gcm)); 67
68 #ifndef GCM_TABLES_SSE2
69 orig = gcm = XMALLOC(sizeof(*gcm));
70 #else
71 orig = gcm = XMALLOC(sizeof(*gcm) + 16);
72 #endif
67 if (gcm == NULL) { 73 if (gcm == NULL) {
68 return CRYPT_MEM; 74 return CRYPT_MEM;
69 } 75 }
76
77 /* Force GCM to be on a multiple of 16 so we can use 128-bit aligned operations
78 * note that we only modify gcm and keep orig intact. This code is not portable
79 * but again it's only for SSE2 anyways, so who cares?
80 */
81 #ifdef GCM_TABLES_SSE2
82 if ((unsigned long)gcm & 15) {
83 gcm = (gcm_state *)((unsigned long)gcm + (16 - ((unsigned long)gcm & 15)));
84 }
85 #endif
70 86
71 if ((err = gcm_init(gcm, cipher, key, keylen)) != CRYPT_OK) { 87 if ((err = gcm_init(gcm, cipher, key, keylen)) != CRYPT_OK) {
72 goto LTC_ERR; 88 goto LTC_ERR;
73 } 89 }
74 if ((err = gcm_add_iv(gcm, IV, IVlen)) != CRYPT_OK) { 90 if ((err = gcm_add_iv(gcm, IV, IVlen)) != CRYPT_OK) {
80 if ((err = gcm_process(gcm, pt, ptlen, ct, direction)) != CRYPT_OK) { 96 if ((err = gcm_process(gcm, pt, ptlen, ct, direction)) != CRYPT_OK) {
81 goto LTC_ERR; 97 goto LTC_ERR;
82 } 98 }
83 err = gcm_done(gcm, tag, taglen); 99 err = gcm_done(gcm, tag, taglen);
84 LTC_ERR: 100 LTC_ERR:
85 XFREE(gcm); 101 XFREE(orig);
86 return err; 102 return err;
87 } 103 }
88 #endif 104 #endif
89 105
90 106
91 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_memory.c,v $ */ 107 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_memory.c,v $ */
92 /* $Revision: 1.19 $ */ 108 /* $Revision: 1.23 $ */
93 /* $Date: 2005/05/05 14:35:58 $ */ 109 /* $Date: 2006/09/07 10:00:57 $ */