comparison nss/lib/freebl/seed.h @ 0:1e5118fa0cb1

This is NSS with a Cmake Buildsyste To compile a static NSS library for Windows we've used the Chromium-NSS fork and added a Cmake buildsystem to compile it statically for Windows. See README.chromium for chromium changes and README.trustbridge for our modifications.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 28 Jul 2014 10:47:06 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1e5118fa0cb1
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 #ifndef HEADER_SEED_H
6 #define HEADER_SEED_H
7
8 #include <string.h>
9 #include "blapi.h"
10
11 #if !defined(NO_SYS_TYPES_H)
12 # include <sys/types.h>
13 #endif
14
15 typedef PRUint32 seed_word;
16
17 #define G_FUNC(v) \
18 SS[0][((v) & 0xff)] ^ \
19 SS[1][((v)>> 8 & 0xff)] ^ \
20 SS[2][((v)>>16 & 0xff)] ^ \
21 SS[3][((v)>>24 & 0xff)]
22
23 #define char2word(c, i) \
24 (i) = ((((seed_word)((c)[0])) << 24) | \
25 (((seed_word)((c)[1])) << 16) | \
26 (((seed_word)((c)[2])) << 8) | \
27 ((seed_word)((c)[3])))
28
29 #define word2char(l, c) \
30 *((c)+0) = (unsigned char)((l)>>24); \
31 *((c)+1) = (unsigned char)((l)>>16); \
32 *((c)+2) = (unsigned char)((l)>> 8); \
33 *((c)+3) = (unsigned char)((l) )
34
35 #define KEYSCHEDULE_UPDATE0(T0, T1, K0, K1, K2, K3, KC) \
36 (T0) = (K2); \
37 (K2) = (((K2)<<8) ^ ((K3)>>24)); \
38 (K3) = (((K3)<<8) ^ ((T0)>>24)); \
39 (T0) = ((K0) + (K2) - (KC)); \
40 (T1) = ((K1) + (KC) - (K3))
41
42 #define KEYSCHEDULE_UPDATE1(T0, T1, K0, K1, K2, K3, KC) \
43 (T0) = (K0); \
44 (K0) = (((K0)>>8) ^ ((K1)<<24)); \
45 (K1) = (((K1)>>8) ^ ((T0)<<24)); \
46 (T0) = ((K0) + (K2) - (KC)); \
47 (T1) = ((K1) + (KC) - (K3))
48
49 #define KEYUPDATE_TEMP(T0, T1, K) \
50 (K)[0] = G_FUNC((T0)); \
51 (K)[1] = G_FUNC((T1))
52
53 #define XOR_SEEDBLOCK(DST, SRC) \
54 (DST)[0] ^= (SRC)[0]; \
55 (DST)[1] ^= (SRC)[1]; \
56 (DST)[2] ^= (SRC)[2]; \
57 (DST)[3] ^= (SRC)[3]
58
59 #define MOV_SEEDBLOCK(DST, SRC) \
60 (DST)[0] = (SRC)[0]; \
61 (DST)[1] = (SRC)[1]; \
62 (DST)[2] = (SRC)[2]; \
63 (DST)[3] = (SRC)[3]
64
65 # define CHAR2WORD(C, I) \
66 char2word((C), (I)[0]); \
67 char2word((C)+4, (I)[1]); \
68 char2word((C)+8, (I)[2]); \
69 char2word((C)+12, (I)[3])
70
71 # define WORD2CHAR(I, C) \
72 word2char((I)[0], (C)); \
73 word2char((I)[1], (C+4)); \
74 word2char((I)[2], (C+8)); \
75 word2char((I)[3], (C+12))
76
77 # define E_SEED(T0, T1, X1, X2, X3, X4, rbase) \
78 (T0) = (X3) ^ (ks->data)[(rbase)]; \
79 (T1) = (X4) ^ (ks->data)[(rbase)+1]; \
80 (T1) ^= (T0); \
81 (T1) = G_FUNC(T1); \
82 (T0) += (T1); \
83 (T0) = G_FUNC(T0); \
84 (T1) += (T0); \
85 (T1) = G_FUNC(T1); \
86 (T0) += (T1); \
87 (X1) ^= (T0); \
88 (X2) ^= (T1)
89
90
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
94
95 typedef struct seed_key_st {
96 PRUint32 data[32];
97 } SEED_KEY_SCHEDULE;
98
99
100
101 struct SEEDContextStr {
102 unsigned char iv[SEED_BLOCK_SIZE];
103 SEED_KEY_SCHEDULE ks;
104 int mode;
105 unsigned int encrypt;
106 };
107
108 void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH],
109 SEED_KEY_SCHEDULE *ks);
110
111 void SEED_encrypt(const unsigned char s[SEED_BLOCK_SIZE],
112 unsigned char d[SEED_BLOCK_SIZE],
113 const SEED_KEY_SCHEDULE *ks);
114 void SEED_decrypt(const unsigned char s[SEED_BLOCK_SIZE],
115 unsigned char d[SEED_BLOCK_SIZE],
116 const SEED_KEY_SCHEDULE *ks);
117
118 void SEED_ecb_encrypt(const unsigned char *in, unsigned char *out,
119 const SEED_KEY_SCHEDULE *ks, int enc);
120 void SEED_cbc_encrypt(const unsigned char *in, unsigned char *out,
121 size_t len, const SEED_KEY_SCHEDULE *ks,
122 unsigned char ivec[SEED_BLOCK_SIZE], int enc);
123
124 #ifdef __cplusplus
125 }
126 #endif
127
128 #endif /* HEADER_SEED_H */
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)