Mercurial > dropbear
comparison libtomcrypt/src/encauth/gcm/gcm_gf_mult.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_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 $ */ |