| /optee_os/core/lib/libtomcrypt/src/encauth/ocb/ |
| H A D | ocb_init.c | 39 int ocb_init(ocb_state *ocb, int cipher, in ocb_init() argument 44 LTC_ARGCHK(ocb != NULL); in ocb_init() 54 ocb->block_len = cipher_descriptor[cipher]->block_length; in ocb_init() 57 if (polys[poly].len == ocb->block_len) { in ocb_init() 64 if (polys[poly].len != ocb->block_len) { in ocb_init() 69 if ((err = cipher_descriptor[cipher]->setup(key, keylen, 0, &ocb->key)) != CRYPT_OK) { in ocb_init() 74 zeromem(ocb->L, ocb->block_len); in ocb_init() 75 if ((err = cipher_descriptor[cipher]->ecb_encrypt(ocb->L, ocb->L, &ocb->key)) != CRYPT_OK) { in ocb_init() 80 for (x = 0; x < ocb->block_len; x++) { in ocb_init() 81 ocb->R[x] = ocb->L[x] ^ nonce[x]; in ocb_init() [all …]
|
| H A D | s_ocb_done.c | 31 int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen, in s_ocb_done() argument 38 LTC_ARGCHK(ocb != NULL); in s_ocb_done() 43 if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) { in s_ocb_done() 46 if (ocb->block_len != cipher_descriptor[ocb->cipher]->block_length || in s_ocb_done() 47 (int)ptlen > ocb->block_len || (int)ptlen < 0) { in s_ocb_done() 69 ocb_shift_xor(ocb, X); in s_ocb_done() 70 XMEMCPY(Z, X, ocb->block_len); in s_ocb_done() 72 X[ocb->block_len-1] ^= (ptlen*8)&255; in s_ocb_done() 73 X[ocb->block_len-2] ^= ((ptlen*8)>>8)&255; in s_ocb_done() 74 for (x = 0; x < ocb->block_len; x++) { in s_ocb_done() [all …]
|
| H A D | ocb_decrypt.c | 19 int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt) in ocb_decrypt() argument 24 LTC_ARGCHK(ocb != NULL); in ocb_decrypt() 29 if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) { in ocb_decrypt() 32 LTC_ARGCHK(cipher_descriptor[ocb->cipher]->ecb_decrypt != NULL); in ocb_decrypt() 35 if (ocb->block_len != cipher_descriptor[ocb->cipher]->block_length) { in ocb_decrypt() 40 ocb_shift_xor(ocb, Z); in ocb_decrypt() 43 for (x = 0; x < ocb->block_len; x++) { in ocb_decrypt() 46 if ((err = cipher_descriptor[ocb->cipher]->ecb_decrypt(tmp, pt, &ocb->key)) != CRYPT_OK) { in ocb_decrypt() 49 for (x = 0; x < ocb->block_len; x++) { in ocb_decrypt() 54 for (x = 0; x < ocb->block_len; x++) { in ocb_decrypt() [all …]
|
| H A D | ocb_encrypt_authenticate_memory.c | 33 ocb_state *ocb; in ocb_encrypt_authenticate_memory() local 43 ocb = XMALLOC(sizeof(ocb_state)); in ocb_encrypt_authenticate_memory() 44 if (ocb == NULL) { in ocb_encrypt_authenticate_memory() 48 if ((err = ocb_init(ocb, cipher, key, keylen, nonce)) != CRYPT_OK) { in ocb_encrypt_authenticate_memory() 52 while (ptlen > (unsigned long)ocb->block_len) { in ocb_encrypt_authenticate_memory() 53 if ((err = ocb_encrypt(ocb, pt, ct)) != CRYPT_OK) { in ocb_encrypt_authenticate_memory() 56 ptlen -= ocb->block_len; in ocb_encrypt_authenticate_memory() 57 pt += ocb->block_len; in ocb_encrypt_authenticate_memory() 58 ct += ocb->block_len; in ocb_encrypt_authenticate_memory() 61 err = ocb_done_encrypt(ocb, pt, ptlen, ct, tag, taglen); in ocb_encrypt_authenticate_memory() [all …]
|
| H A D | ocb_encrypt.c | 19 int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct) in ocb_encrypt() argument 24 LTC_ARGCHK(ocb != NULL); in ocb_encrypt() 27 if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) { in ocb_encrypt() 30 if (ocb->block_len != cipher_descriptor[ocb->cipher].block_length) { in ocb_encrypt() 35 for (x = 0; x < ocb->block_len; x++) { in ocb_encrypt() 36 ocb->checksum[x] ^= pt[x]; in ocb_encrypt() 40 ocb_shift_xor(ocb, Z); in ocb_encrypt() 43 for (x = 0; x < ocb->block_len; x++) { in ocb_encrypt() 46 if ((err = cipher_descriptor[ocb->cipher].ecb_encrypt(tmp, ct, &ocb->key)) != CRYPT_OK) { in ocb_encrypt() 49 for (x = 0; x < ocb->block_len; x++) { in ocb_encrypt()
|
| H A D | ocb_decrypt_verify_memory.c | 35 ocb_state *ocb; in ocb_decrypt_verify_memory() local 45 ocb = XMALLOC(sizeof(ocb_state)); in ocb_decrypt_verify_memory() 46 if (ocb == NULL) { in ocb_decrypt_verify_memory() 50 if ((err = ocb_init(ocb, cipher, key, keylen, nonce)) != CRYPT_OK) { in ocb_decrypt_verify_memory() 54 while (ctlen > (unsigned long)ocb->block_len) { in ocb_decrypt_verify_memory() 55 if ((err = ocb_decrypt(ocb, ct, pt)) != CRYPT_OK) { in ocb_decrypt_verify_memory() 58 ctlen -= ocb->block_len; in ocb_decrypt_verify_memory() 59 pt += ocb->block_len; in ocb_decrypt_verify_memory() 60 ct += ocb->block_len; in ocb_decrypt_verify_memory() 63 err = ocb_done_decrypt(ocb, ct, ctlen, pt, tag, taglen, stat); in ocb_decrypt_verify_memory() [all …]
|
| H A D | ocb_shift_xor.c | 17 void ocb_shift_xor(ocb_state *ocb, unsigned char *Z) in ocb_shift_xor() argument 20 y = ocb_ntz(ocb->block_index++); in ocb_shift_xor() 21 for (x = 0; x < ocb->block_len; x++) { in ocb_shift_xor() 22 ocb->Li[x] ^= ocb->Ls[y][x]; in ocb_shift_xor() 23 Z[x] = ocb->Li[x] ^ ocb->R[x]; in ocb_shift_xor()
|
| H A D | ocb_done_encrypt.c | 22 int ocb_done_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen, in ocb_done_encrypt() argument 25 LTC_ARGCHK(ocb != NULL); in ocb_done_encrypt() 30 return s_ocb_done(ocb, pt, ptlen, ct, tag, taglen, 0); in ocb_done_encrypt()
|
| H A D | ocb_done_decrypt.c | 23 int ocb_done_decrypt(ocb_state *ocb, in ocb_done_decrypt() argument 32 LTC_ARGCHK(ocb != NULL); in ocb_done_decrypt() 48 if ((err = s_ocb_done(ocb, ct, ctlen, pt, tagbuf, &tagbuflen, 1)) != CRYPT_OK) { in ocb_done_decrypt()
|
| /optee_os/core/lib/libtomcrypt/src/encauth/ocb3/ |
| H A D | ocb3_add_aad.c | 18 static int s_ocb3_int_aad_add_block(ocb3_state *ocb, const unsigned char *aad_block) in s_ocb3_int_aad_add_block() argument 24 …ocb3_int_xor_blocks(ocb->aOffset_current, ocb->aOffset_current, ocb->L_[ocb3_int_ntz(ocb->ablock_i… in s_ocb3_int_aad_add_block() 27 ocb3_int_xor_blocks(tmp, aad_block, ocb->aOffset_current, ocb->block_len); in s_ocb3_int_aad_add_block() 28 if ((err = cipher_descriptor[ocb->cipher]->ecb_encrypt(tmp, tmp, &ocb->key)) != CRYPT_OK) { in s_ocb3_int_aad_add_block() 31 ocb3_int_xor_blocks(ocb->aSum_current, ocb->aSum_current, tmp, ocb->block_len); in s_ocb3_int_aad_add_block() 33 ocb->ablock_index++; in s_ocb3_int_aad_add_block() 45 int ocb3_add_aad(ocb3_state *ocb, const unsigned char *aad, unsigned long aadlen) in ocb3_add_aad() argument 51 LTC_ARGCHK(ocb != NULL); in ocb3_add_aad() 55 if (ocb->adata_buffer_bytes > 0) { in ocb3_add_aad() 56 l = ocb->block_len - ocb->adata_buffer_bytes; in ocb3_add_aad() [all …]
|
| H A D | ocb3_done.c | 19 int ocb3_done(ocb3_state *ocb, unsigned char *tag, unsigned long *taglen) in ocb3_done() argument 24 LTC_ARGCHK(ocb != NULL); in ocb3_done() 27 if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) { in ocb3_done() 32 if ((int)*taglen < ocb->tag_len) { in ocb3_done() 33 *taglen = (unsigned long)ocb->tag_len; in ocb3_done() 39 if (ocb->adata_buffer_bytes>0) { in ocb3_done() 41 ocb3_int_xor_blocks(ocb->aOffset_current, ocb->aOffset_current, ocb->L_star, ocb->block_len); in ocb3_done() 44 ocb3_int_xor_blocks(tmp, ocb->adata_buffer, ocb->aOffset_current, ocb->adata_buffer_bytes); in ocb3_done() 45 for(x=ocb->adata_buffer_bytes; x<ocb->block_len; x++) { in ocb3_done() 46 if (x == ocb->adata_buffer_bytes) { in ocb3_done() [all …]
|
| H A D | ocb3_init.c | 12 static void s_ocb3_int_calc_offset_zero(ocb3_state *ocb, const unsigned char *nonce, unsigned long … in s_ocb3_int_calc_offset_zero() argument 22 for (x = ocb->block_len-1, y=0; y<(int)noncelen; x--, y++) { in s_ocb3_int_calc_offset_zero() 29 bottom = iNonce[ocb->block_len-1] & 0x3F; in s_ocb3_int_calc_offset_zero() 32 iNonce[ocb->block_len-1] = iNonce[ocb->block_len-1] & 0xC0; in s_ocb3_int_calc_offset_zero() 33 if ((cipher_descriptor[ocb->cipher]->ecb_encrypt(iNonce, iKtop, &ocb->key)) != CRYPT_OK) { in s_ocb3_int_calc_offset_zero() 34 zeromem(ocb->Offset_current, ocb->block_len); in s_ocb3_int_calc_offset_zero() 39 for (x = 0; x < ocb->block_len; x++) { in s_ocb3_int_calc_offset_zero() 49 for (x = 0; x < ocb->block_len; x++) { in s_ocb3_int_calc_offset_zero() 50 ocb->Offset_current[x] = iStretch[idx+x] << shift; in s_ocb3_int_calc_offset_zero() 52 ocb->Offset_current[x] |= iStretch[idx+x+1] >> (8-shift); in s_ocb3_int_calc_offset_zero() [all …]
|
| H A D | ocb3_decrypt_last.c | 20 int ocb3_decrypt_last(ocb3_state *ocb, const unsigned char *ct, unsigned long ctlen, unsigned char … in ocb3_decrypt_last() argument 26 LTC_ARGCHK(ocb != NULL); in ocb3_decrypt_last() 33 if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) { in ocb3_decrypt_last() 37 full_blocks = ctlen/ocb->block_len; in ocb3_decrypt_last() 38 full_blocks_len = full_blocks * ocb->block_len; in ocb3_decrypt_last() 43 if ((err = ocb3_decrypt(ocb, ct, full_blocks_len, pt)) != CRYPT_OK) { in ocb3_decrypt_last() 50 ocb3_int_xor_blocks(iOffset_star, ocb->Offset_current, ocb->L_star, ocb->block_len); in ocb3_decrypt_last() 53 …if ((err = cipher_descriptor[ocb->cipher]->ecb_encrypt(iOffset_star, iPad, &ocb->key)) != CRYPT_OK… in ocb3_decrypt_last() 61 ocb3_int_xor_blocks(ocb->checksum, ocb->checksum, pt+full_blocks_len, last_block_len); in ocb3_decrypt_last() 62 for(x=last_block_len; x<ocb->block_len; x++) { in ocb3_decrypt_last() [all …]
|
| H A D | ocb3_encrypt_last.c | 20 int ocb3_encrypt_last(ocb3_state *ocb, const unsigned char *pt, unsigned long ptlen, unsigned char … in ocb3_encrypt_last() argument 26 LTC_ARGCHK(ocb != NULL); in ocb3_encrypt_last() 33 if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) { in ocb3_encrypt_last() 37 full_blocks = ptlen/ocb->block_len; in ocb3_encrypt_last() 38 full_blocks_len = full_blocks * ocb->block_len; in ocb3_encrypt_last() 43 if ((err = ocb3_encrypt(ocb, pt, full_blocks_len, ct)) != CRYPT_OK) { in ocb3_encrypt_last() 52 ocb3_int_xor_blocks(iOffset_star, ocb->Offset_current, ocb->L_star, ocb->block_len); in ocb3_encrypt_last() 55 …if ((err = cipher_descriptor[ocb->cipher]->ecb_encrypt(iOffset_star, iPad, &ocb->key)) != CRYPT_OK… in ocb3_encrypt_last() 63 ocb3_int_xor_blocks(ocb->checksum, ocb->checksum, pt+full_blocks_len, last_block_len); in ocb3_encrypt_last() 64 for(x=last_block_len; x<ocb->block_len; x++) { in ocb3_encrypt_last() [all …]
|
| H A D | ocb3_decrypt.c | 20 int ocb3_decrypt(ocb3_state *ocb, const unsigned char *ct, unsigned long ctlen, unsigned char *pt) in ocb3_decrypt() argument 26 LTC_ARGCHK(ocb != NULL); in ocb3_decrypt() 31 if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) { in ocb3_decrypt() 34 if (ocb->block_len != cipher_descriptor[ocb->cipher]->block_length) { in ocb3_decrypt() 38 if (ctlen % ocb->block_len) { /* ctlen has to bu multiple of block_len */ in ocb3_decrypt() 42 full_blocks = ctlen/ocb->block_len; in ocb3_decrypt() 44 pt_b = (unsigned char *)pt+i*ocb->block_len; in ocb3_decrypt() 45 ct_b = (unsigned char *)ct+i*ocb->block_len; in ocb3_decrypt() 48 …ocb3_int_xor_blocks(ocb->Offset_current, ocb->Offset_current, ocb->L_[ocb3_int_ntz(ocb->block_inde… in ocb3_decrypt() 51 ocb3_int_xor_blocks(tmp, ct_b, ocb->Offset_current, ocb->block_len); in ocb3_decrypt() [all …]
|
| H A D | ocb3_encrypt.c | 20 int ocb3_encrypt(ocb3_state *ocb, const unsigned char *pt, unsigned long ptlen, unsigned char *ct) in ocb3_encrypt() argument 26 LTC_ARGCHK(ocb != NULL); in ocb3_encrypt() 31 if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) { in ocb3_encrypt() 34 if (ocb->block_len != cipher_descriptor[ocb->cipher]->block_length) { in ocb3_encrypt() 38 if (ptlen % ocb->block_len) { /* ptlen has to bu multiple of block_len */ in ocb3_encrypt() 42 full_blocks = ptlen/ocb->block_len; in ocb3_encrypt() 44 pt_b = (unsigned char *)pt+i*ocb->block_len; in ocb3_encrypt() 45 ct_b = (unsigned char *)ct+i*ocb->block_len; in ocb3_encrypt() 48 …ocb3_int_xor_blocks(ocb->Offset_current, ocb->Offset_current, ocb->L_[ocb3_int_ntz(ocb->block_inde… in ocb3_encrypt() 51 ocb3_int_xor_blocks(tmp, pt_b, ocb->Offset_current, ocb->block_len); in ocb3_encrypt() [all …]
|
| H A D | ocb3_decrypt_verify_memory.c | 39 ocb3_state *ocb; in ocb3_decrypt_verify_memory() local 53 ocb = XMALLOC(sizeof(ocb3_state)); in ocb3_decrypt_verify_memory() 54 if (ocb == NULL || buf == NULL) { in ocb3_decrypt_verify_memory() 55 if (ocb != NULL) { in ocb3_decrypt_verify_memory() 56 XFREE(ocb); in ocb3_decrypt_verify_memory() 64 if ((err = ocb3_init(ocb, cipher, key, keylen, nonce, noncelen, taglen)) != CRYPT_OK) { in ocb3_decrypt_verify_memory() 69 if ((err = ocb3_add_aad(ocb, adata, adatalen)) != CRYPT_OK) { in ocb3_decrypt_verify_memory() 74 if ((err = ocb3_decrypt_last(ocb, ct, ctlen, pt)) != CRYPT_OK) { in ocb3_decrypt_verify_memory() 79 if ((err = ocb3_done(ocb, buf, &buflen)) != CRYPT_OK) { in ocb3_decrypt_verify_memory() 92 zeromem(ocb, sizeof(ocb3_state)); in ocb3_decrypt_verify_memory() [all …]
|
| H A D | ocb3_encrypt_authenticate_memory.c | 37 ocb3_state *ocb; in ocb3_encrypt_authenticate_memory() local 42 ocb = XMALLOC(sizeof(ocb3_state)); in ocb3_encrypt_authenticate_memory() 43 if (ocb == NULL) { in ocb3_encrypt_authenticate_memory() 47 if ((err = ocb3_init(ocb, cipher, key, keylen, nonce, noncelen, *taglen)) != CRYPT_OK) { in ocb3_encrypt_authenticate_memory() 52 if ((err = ocb3_add_aad(ocb, adata, adatalen)) != CRYPT_OK) { in ocb3_encrypt_authenticate_memory() 57 if ((err = ocb3_encrypt_last(ocb, pt, ptlen, ct)) != CRYPT_OK) { in ocb3_encrypt_authenticate_memory() 61 err = ocb3_done(ocb, tag, taglen); in ocb3_encrypt_authenticate_memory() 65 zeromem(ocb, sizeof(ocb3_state)); in ocb3_encrypt_authenticate_memory() 68 XFREE(ocb); in ocb3_encrypt_authenticate_memory()
|
| H A D | ocb3_test.c | 203 ocb3_state ocb; in ocb3_test() 278 if ((err = ocb3_init(&ocb, idx, K, sizeof(K), N, sizeof(N), 12)) != CRYPT_OK) return err; in ocb3_test() 279 if ((err = ocb3_add_aad(&ocb, A, sizeof(A))) != CRYPT_OK) return err; in ocb3_test() 280 if ((err = ocb3_encrypt(&ocb, P, 32, outct)) != CRYPT_OK) return err; in ocb3_test() 281 if ((err = ocb3_encrypt_last(&ocb, P+32, sizeof(P)-32, outct+32)) != CRYPT_OK) return err; in ocb3_test() 283 if ((err = ocb3_done(&ocb, outtag, &len)) != CRYPT_OK) return err; in ocb3_test() 286 if ((err = ocb3_init(&ocb, idx, K, sizeof(K), N, sizeof(N), 12)) != CRYPT_OK) return err; in ocb3_test() 287 if ((err = ocb3_add_aad(&ocb, A, sizeof(A))) != CRYPT_OK) return err; in ocb3_test() 288 if ((err = ocb3_decrypt(&ocb, C, 32, outct)) != CRYPT_OK) return err; in ocb3_test() 289 if ((err = ocb3_decrypt_last(&ocb, C+32, sizeof(C)-32, outct+32)) != CRYPT_OK) return err; in ocb3_test() [all …]
|
| /optee_os/core/lib/libtomcrypt/src/headers/ |
| H A D | tomcrypt_mac.h | 306 int ocb_init(ocb_state *ocb, int cipher, 309 int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct); 310 int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt); 312 int ocb_done_encrypt(ocb_state *ocb, 317 int ocb_done_decrypt(ocb_state *ocb, 340 void ocb_shift_xor(ocb_state *ocb, unsigned char *Z); 342 int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen, 371 int ocb3_init(ocb3_state *ocb, int cipher, 376 int ocb3_encrypt(ocb3_state *ocb, const unsigned char *pt, unsigned long ptlen, unsigned char *ct); 377 int ocb3_decrypt(ocb3_state *ocb, const unsigned char *ct, unsigned long ctlen, unsigned char *pt); [all …]
|