ltc sync
Karel Miko
6 years ago
23 | 23 |
unsigned char *ct,
|
24 | 24 |
int direction)
|
25 | 25 |
{
|
26 | |
unsigned char z, b;
|
27 | |
unsigned long y;
|
|
26 |
unsigned char z, b;
|
|
27 |
unsigned long y;
|
28 | 28 |
int err;
|
29 | 29 |
|
30 | 30 |
LTC_ARGCHK(ccm != NULL);
|
|
44 | 44 |
if (ptlen > 0) {
|
45 | 45 |
LTC_ARGCHK(pt != NULL);
|
46 | 46 |
LTC_ARGCHK(ct != NULL);
|
47 | |
y = 0;
|
48 | 47 |
|
49 | |
for (; y < ptlen; y++) {
|
|
48 |
for (y = 0; y < ptlen; y++) {
|
50 | 49 |
/* increment the ctr? */
|
51 | 50 |
if (ccm->CTRlen == 16) {
|
52 | 51 |
for (z = 15; z > 15-ccm->L; z--) {
|
1047 | 1047 |
unsigned ptr;
|
1048 | 1048 |
} sosemanuk_state;
|
1049 | 1049 |
|
1050 | |
int sosemanuk_setup(sosemanuk_state *ss, unsigned char *key, unsigned long key_len);
|
1051 | |
int sosemanuk_setiv(sosemanuk_state *ss, unsigned char *iv, unsigned long iv_len);
|
1052 | |
int sosemanuk_crypt(sosemanuk_state *ss, const unsigned char *in, unsigned long data_len, unsigned char *out);
|
1053 | |
int sosemanuk_keystream(sosemanuk_state *ss, unsigned char *out, unsigned long out_len);
|
|
1050 |
int sosemanuk_setup(sosemanuk_state *ss, unsigned char *key, unsigned long keylen);
|
|
1051 |
int sosemanuk_setiv(sosemanuk_state *ss, unsigned char *iv, unsigned long ivlen);
|
|
1052 |
int sosemanuk_crypt(sosemanuk_state *ss, const unsigned char *in, unsigned long datalen, unsigned char *out);
|
|
1053 |
int sosemanuk_keystream(sosemanuk_state *ss, unsigned char *out, unsigned long outlen);
|
1054 | 1054 |
int sosemanuk_done(sosemanuk_state *ss);
|
1055 | 1055 |
int sosemanuk_test(void);
|
1056 | 1056 |
|
11 | 11 |
hash_state md;
|
12 | 12 |
int hash;
|
13 | 13 |
hash_state hashstate;
|
14 | |
unsigned char *key;
|
|
14 |
unsigned char key[MAXBLOCKSIZE];
|
15 | 15 |
} hmac_state;
|
16 | 16 |
|
17 | 17 |
int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned long keylen);
|
86 | 86 |
|
87 | 87 |
err = CRYPT_OK;
|
88 | 88 |
LBL_ERR:
|
89 | |
XFREE(hmac->key);
|
90 | 89 |
#ifdef LTC_CLEAN_STACK
|
91 | 90 |
zeromem(isha, hashsize);
|
92 | 91 |
zeromem(buf, hashsize);
|
52 | 52 |
return CRYPT_MEM;
|
53 | 53 |
}
|
54 | 54 |
|
55 | |
/* allocate memory for key */
|
56 | |
hmac->key = XMALLOC(LTC_HMAC_BLOCKSIZE);
|
57 | |
if (hmac->key == NULL) {
|
58 | |
XFREE(buf);
|
59 | |
return CRYPT_MEM;
|
|
55 |
/* check hash block fits */
|
|
56 |
if (sizeof(hmac->key) < LTC_HMAC_BLOCKSIZE) {
|
|
57 |
err = CRYPT_BUFFER_OVERFLOW;
|
|
58 |
goto LBL_ERR;
|
60 | 59 |
}
|
61 | 60 |
|
62 | 61 |
/* (1) make sure we have a large enough key */
|
|
87 | 86 |
if ((err = hash_descriptor[hash].process(&hmac->md, buf, LTC_HMAC_BLOCKSIZE)) != CRYPT_OK) {
|
88 | 87 |
goto LBL_ERR;
|
89 | 88 |
}
|
90 | |
goto done;
|
|
89 |
|
91 | 90 |
LBL_ERR:
|
92 | |
/* free the key since we failed */
|
93 | |
XFREE(hmac->key);
|
94 | |
done:
|
95 | 91 |
#ifdef LTC_CLEAN_STACK
|
96 | 92 |
zeromem(buf, LTC_HMAC_BLOCKSIZE);
|
97 | 93 |
#endif
|
42 | 42 |
return err;
|
43 | 43 |
}
|
44 | 44 |
|
45 | |
bits = ((bits/8)+((bits&7)!=0?1:0)) * 2;
|
|
45 |
bits = ((bits+7)/8) * 2;
|
46 | 46 |
if (rng_get_bytes(buf, (unsigned long)bits, callback) != (unsigned long)bits) {
|
47 | 47 |
return CRYPT_ERROR_READPRNG;
|
48 | 48 |
}
|
256 | 256 |
|
257 | 257 |
LTC_ARGCHK(ss != NULL);
|
258 | 258 |
LTC_ARGCHK(key != NULL);
|
259 | |
|
260 | |
/*
|
261 | |
* Initialize the pointer to 666 as a flag that can be checked
|
262 | |
* by sosemanuk_crypt() as an indication sosemanuk_setiv() was
|
263 | |
* not called. (sosemanuk_setiv() will set the pointer to a
|
264 | |
* more reasonable value.)
|
265 | |
*/
|
266 | |
ss->ptr = 666;
|
267 | 259 |
|
268 | 260 |
/*
|
269 | 261 |
* The key is copied into the wbuf[] buffer and padded to 256 bits
|
|
329 | 321 |
#undef WUP0
|
330 | 322 |
#undef WUP1
|
331 | 323 |
|
332 | |
return CRYPT_OK;
|
|
324 |
/*
|
|
325 |
* Initialize with a zero-value iv to ensure state is correct in the
|
|
326 |
* event user fails to call setiv().
|
|
327 |
*/
|
|
328 |
return sosemanuk_setiv(ss, NULL, 0);
|
333 | 329 |
}
|
334 | 330 |
|
335 | 331 |
|
|
756 | 752 |
LTC_ARGCHK(ss != NULL);
|
757 | 753 |
LTC_ARGCHK(in != NULL);
|
758 | 754 |
LTC_ARGCHK(out != NULL);
|
759 | |
LTC_ARGCHK(ss->ptr != 666); /* check whether sosemanuk_setiv was called */
|
760 | 755 |
|
761 | 756 |
if (ss->ptr < (sizeof(ss->buf))) {
|
762 | 757 |
unsigned long rlen = (sizeof(ss->buf)) - ss->ptr;
|