Mercurial > dropbear
comparison libtomcrypt/src/encauth/gcm/gcm_gf_mult.c @ 285:1b9e69c058d2
propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3)
to branch 'au.asn.ucc.matt.dropbear' (head fdf4a7a3b97ae5046139915de7e40399cceb2c01)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 08 Mar 2006 13:23:58 +0000 |
parents | |
children | 0cbe8f6dbf9e |
comparison
equal
deleted
inserted
replaced
281:997e6f7dc01e | 285:1b9e69c058d2 |
---|---|
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_gf_mult.c | |
14 GCM implementation, initialize state, by Tom St Denis | |
15 */ | |
16 #include "tomcrypt.h" | |
17 | |
18 #ifdef GCM_MODE | |
19 | |
20 /* right shift */ | |
21 static void gcm_rightshift(unsigned char *a) | |
22 { | |
23 int x; | |
24 for (x = 15; x > 0; x--) { | |
25 a[x] = (a[x]>>1) | ((a[x-1]<<7)&0x80); | |
26 } | |
27 a[0] >>= 1; | |
28 } | |
29 | |
30 /* c = b*a */ | |
31 static const unsigned char mask[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; | |
32 static const unsigned char poly[] = { 0x00, 0xE1 }; | |
33 | |
34 | |
35 /** | |
36 GCM GF multiplier (internal use only) | |
37 @param a First value | |
38 @param b Second value | |
39 @param c Destination for a * b | |
40 */ | |
41 void gcm_gf_mult(const unsigned char *a, const unsigned char *b, unsigned char *c) | |
42 { | |
43 unsigned char Z[16], V[16]; | |
44 unsigned x, y, z; | |
45 | |
46 zeromem(Z, 16); | |
47 XMEMCPY(V, a, 16); | |
48 for (x = 0; x < 128; x++) { | |
49 if (b[x>>3] & mask[x&7]) { | |
50 for (y = 0; y < 16; y++) { | |
51 Z[y] ^= V[y]; | |
52 } | |
53 } | |
54 z = V[15] & 0x01; | |
55 gcm_rightshift(V); | |
56 V[0] ^= poly[z]; | |
57 } | |
58 XMEMCPY(c, Z, 16); | |
59 } | |
60 | |
61 /** | |
62 GCM multiply by H | |
63 @param gcm The GCM state which holds the H value | |
64 @param I The value to multiply H by | |
65 */ | |
66 void gcm_mult_h(gcm_state *gcm, unsigned char *I) | |
67 { | |
68 unsigned char T[16]; | |
69 #ifdef GCM_TABLES | |
70 int x, y; | |
71 XMEMCPY(T, &gcm->PC[0][I[0]][0], 16); | |
72 for (x = 1; x < 16; x++) { | |
73 #ifdef LTC_FAST | |
74 for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) { | |
75 *((LTC_FAST_TYPE *)(T + y)) ^= *((LTC_FAST_TYPE *)(&gcm->PC[x][I[x]][y])); | |
76 } | |
77 #else | |
78 for (y = 0; y < 16; y++) { | |
79 T[y] ^= gcm->PC[x][I[x]][y]; | |
80 } | |
81 #endif | |
82 } | |
83 #else | |
84 gcm_gf_mult(gcm->H, I, T); | |
85 #endif | |
86 XMEMCPY(I, T, 16); | |
87 } | |
88 | |
89 | |
90 #endif | |
91 | |
92 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_gf_mult.c,v $ */ | |
93 /* $Revision: 1.16 $ */ | |
94 /* $Date: 2005/05/21 14:33:42 $ */ |