Package list libcryptx-perl / 23f7541
libtomcrypt fixes Karel Miko 2 years ago
7 changed file(s) with 33 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
2828
2929 LTC_ARGCHK(ccm != NULL);
3030 LTC_ARGCHK(key != NULL);
31 LTC_ARGCHK(taglen != 0);
3231
3332 XMEMSET(ccm, 0, sizeof(ccm_state));
3433
4039 return CRYPT_INVALID_CIPHER;
4140 }
4241
43 /* make sure the taglen is even and <= 16 */
44 ccm->taglen = taglen;
45 ccm->taglen &= ~1;
46 if (ccm->taglen > 16) {
47 ccm->taglen = 16;
48 }
49
50 /* can't use < 4 */
51 if (ccm->taglen < 4) {
42 /* make sure the taglen is valid */
43 if (taglen < 4 || taglen > 16 || (taglen % 2) == 1) {
5244 return CRYPT_INVALID_ARG;
5345 }
46 ccm->taglen = taglen;
5447
5548 /* schedule key */
5649 if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, &ccm->K)) != CRYPT_OK) {
7979 return CRYPT_INVALID_CIPHER;
8080 }
8181
82 /* make sure the taglen is even and <= 16 */
83 *taglen &= ~1;
84 if (*taglen > 16) {
85 *taglen = 16;
86 }
87
88 /* can't use < 4 */
89 if (*taglen < 4) {
82 /* make sure the taglen is valid */
83 if (*taglen < 4 || *taglen > 16 || (*taglen % 2) == 1) {
9084 return CRYPT_INVALID_ARG;
9185 }
9286
2424 unsigned long padlen;
2525 int err;
2626
27 if (inlen == 0) return CRYPT_OK; /* nothing to do */
2827 LTC_ARGCHK(st != NULL);
2928
3029 if (st->aadflg) {
2424 unsigned long padlen;
2525 int err;
2626
27 if (inlen == 0) return CRYPT_OK; /* nothing to do */
2827 LTC_ARGCHK(st != NULL);
2928
3029 if ((err = chacha_crypt(&st->chacha, in, inlen, out)) != CRYPT_OK) return err;
4242 LTC_ARGCHK(in != NULL);
4343 LTC_ARGCHK(out != NULL);
4444 LTC_ARGCHK(tag != NULL);
45 LTC_ARGCHK(taglen != NULL);
4546
4647 if ((err = chacha20poly1305_init(&st, key, keylen)) != CRYPT_OK) { goto LBL_ERR; }
4748 if ((err = chacha20poly1305_setiv(&st, iv, ivlen)) != CRYPT_OK) { goto LBL_ERR; }
5051 }
5152 if (direction == CHACHA20POLY1305_ENCRYPT) {
5253 if ((err = chacha20poly1305_encrypt(&st, in, inlen, out)) != CRYPT_OK) { goto LBL_ERR; }
54 if ((err = chacha20poly1305_done(&st, tag, taglen)) != CRYPT_OK) { goto LBL_ERR; }
5355 }
5456 else if (direction == CHACHA20POLY1305_DECRYPT) {
57 unsigned char buf[MAXBLOCKSIZE];
58 unsigned long buflen = sizeof(buf);
5559 if ((err = chacha20poly1305_decrypt(&st, in, inlen, out)) != CRYPT_OK) { goto LBL_ERR; }
60 if ((err = chacha20poly1305_done(&st, buf, &buflen)) != CRYPT_OK) { goto LBL_ERR; }
61 if (buflen != *taglen || XMEM_NEQ(buf, tag, buflen) != 0) {
62 err = CRYPT_ERROR;
63 goto LBL_ERR;
64 }
5665 }
5766 else {
5867 err = CRYPT_INVALID_ARG;
5968 goto LBL_ERR;
6069 }
61 err = chacha20poly1305_done(&st, tag, taglen);
6270 LBL_ERR:
6371 #ifdef LTC_CLEAN_STACK
6472 zeromem(&st, sizeof(chacha20poly1305_state));
9292 if ((err = gcm_process(gcm, pt, ptlen, ct, direction)) != CRYPT_OK) {
9393 goto LTC_ERR;
9494 }
95 err = gcm_done(gcm, tag, taglen);
95 if (direction == GCM_ENCRYPT) {
96 if ((err = gcm_done(gcm, tag, taglen)) != CRYPT_OK) {
97 goto LTC_ERR;
98 }
99 }
100 else if (direction == GCM_DECRYPT) {
101 unsigned char buf[MAXBLOCKSIZE];
102 unsigned long buflen = sizeof(buf);
103 if ((err = gcm_done(gcm, buf, &buflen)) != CRYPT_OK) {
104 goto LTC_ERR;
105 }
106 if (buflen != *taglen || XMEM_NEQ(buf, tag, buflen) != 0) {
107 err = CRYPT_ERROR;
108 }
109 }
110 else {
111 err = CRYPT_INVALID_ARG;
112 }
96113 LTC_ERR:
97114 XFREE(orig);
98115 return err;
2828 #endif
2929 unsigned char mask = 0xff; /* initialize mask at all ones */
3030
31 LTC_ARGCHK(src != NULL);
32 LTC_ARGCHK(dest != NULL);
31 if (src == NULL || dest == NULL) return;
3332
3433 if (coz != 0) coz = 1;
3534 y = 0;