Codebase list libcryptx-perl / 887dbb4
ltc sync Karel Miko 6 years ago
8 changed file(s) with 22 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
332332
333333 if (skey != uskey) {
334334 cipher_descriptor[cipher].done(skey);
335 #ifdef LTC_CLEAN_STACK
336 zeromem(skey, sizeof(*skey));
337 #endif
335338 }
336339
337340 if (direction == CCM_ENCRYPT) {
379382 fastMask = 0;
380383 #endif
381384 mask = 0;
382 zeromem(skey, sizeof(*skey));
383385 zeromem(PAD, sizeof(PAD));
384386 zeromem(CTRPAD, sizeof(CTRPAD));
385387 if (pt_work != NULL) {
2323 unsigned char *ct,
2424 int direction)
2525 {
26 unsigned char z, b;
27 unsigned long y;
26 unsigned char z, b;
27 unsigned long y;
2828 int err;
2929
3030 LTC_ARGCHK(ccm != NULL);
4444 if (ptlen > 0) {
4545 LTC_ARGCHK(pt != NULL);
4646 LTC_ARGCHK(ct != NULL);
47 y = 0;
4847
49 for (; y < ptlen; y++) {
48 for (y = 0; y < ptlen; y++) {
5049 /* increment the ctr? */
5150 if (ccm->CTRlen == 16) {
5251 for (z = 15; z > 15-ccm->L; z--) {
10471047 unsigned ptr;
10481048 } sosemanuk_state;
10491049
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);
10541054 int sosemanuk_done(sosemanuk_state *ss);
10551055 int sosemanuk_test(void);
10561056
1111 hash_state md;
1212 int hash;
1313 hash_state hashstate;
14 unsigned char *key;
14 unsigned char key[MAXBLOCKSIZE];
1515 } hmac_state;
1616
1717 int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned long keylen);
8686
8787 err = CRYPT_OK;
8888 LBL_ERR:
89 XFREE(hmac->key);
9089 #ifdef LTC_CLEAN_STACK
9190 zeromem(isha, hashsize);
9291 zeromem(buf, hashsize);
5252 return CRYPT_MEM;
5353 }
5454
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;
6059 }
6160
6261 /* (1) make sure we have a large enough key */
8786 if ((err = hash_descriptor[hash].process(&hmac->md, buf, LTC_HMAC_BLOCKSIZE)) != CRYPT_OK) {
8887 goto LBL_ERR;
8988 }
90 goto done;
89
9190 LBL_ERR:
92 /* free the key since we failed */
93 XFREE(hmac->key);
94 done:
9591 #ifdef LTC_CLEAN_STACK
9692 zeromem(buf, LTC_HMAC_BLOCKSIZE);
9793 #endif
4242 return err;
4343 }
4444
45 bits = ((bits/8)+((bits&7)!=0?1:0)) * 2;
45 bits = ((bits+7)/8) * 2;
4646 if (rng_get_bytes(buf, (unsigned long)bits, callback) != (unsigned long)bits) {
4747 return CRYPT_ERROR_READPRNG;
4848 }
256256
257257 LTC_ARGCHK(ss != NULL);
258258 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;
267259
268260 /*
269261 * The key is copied into the wbuf[] buffer and padded to 256 bits
329321 #undef WUP0
330322 #undef WUP1
331323
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);
333329 }
334330
335331
756752 LTC_ARGCHK(ss != NULL);
757753 LTC_ARGCHK(in != NULL);
758754 LTC_ARGCHK(out != NULL);
759 LTC_ARGCHK(ss->ptr != 666); /* check whether sosemanuk_setiv was called */
760755
761756 if (ss->ptr < (sizeof(ss->buf))) {
762757 unsigned long rlen = (sizeof(ss->buf)) - ss->ptr;