/optee_os-3.20.0/core/lib/libtomcrypt/src/encauth/ocb/ |
A D | ocb_init.c | 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() 81 ocb->R[x] = ocb->L[x] ^ nonce[x]; in ocb_init() 88 XMEMCPY(ocb->Ls[0], ocb->L, ocb->block_len); in ocb_init() 92 ocb->Ls[x][y] = ((ocb->Ls[x-1][y] << 1) | (ocb->Ls[x-1][y+1] >> 7)) & 255; in ocb_init() 94 ocb->Ls[x][ocb->block_len-1] = (ocb->Ls[x-1][ocb->block_len-1] << 1) & 255; in ocb_init() 104 m = ocb->L[ocb->block_len-1] & 1; in ocb_init() 108 ocb->Lr[x] = ((ocb->L[x] >> 1) | (ocb->L[x-1] << 7)) & 255; in ocb_init() 110 ocb->Lr[0] = ocb->L[0] >> 1; in ocb_init() 119 zeromem(ocb->Li, ocb->block_len); in ocb_init() [all …]
|
A D | s_ocb_done.c | 38 LTC_ARGCHK(ocb != NULL); in s_ocb_done() 46 if (ocb->block_len != cipher_descriptor[ocb->cipher]->block_length || 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() 75 X[x] ^= ocb->Lr[x]; in s_ocb_done() 79 if ((err = cipher_descriptor[ocb->cipher]->ecb_encrypt(X, Y, &ocb->key)) != CRYPT_OK) { in s_ocb_done() 87 ocb->checksum[x] ^= ct[x]; in s_ocb_done() 100 ocb->checksum[x] ^= ct[x]; in s_ocb_done() 110 …if ((err = cipher_descriptor[ocb->cipher]->ecb_encrypt(ocb->checksum, X, &ocb->key)) != CRYPT_OK) { in s_ocb_done() 113 cipher_descriptor[ocb->cipher]->done(&ocb->key); in s_ocb_done() [all …]
|
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 …]
|
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() 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() 64 zeromem(ocb, sizeof(ocb_state)); in ocb_encrypt_authenticate_memory() [all …]
|
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() 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() 66 zeromem(ocb, sizeof(ocb_state)); in ocb_decrypt_verify_memory() [all …]
|
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()
|
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()
|
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()
|
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-3.20.0/core/lib/libtomcrypt/src/encauth/ocb3/ |
A D | ocb3_done.c | 24 LTC_ARGCHK(ocb != NULL); in ocb3_done() 32 if ((int)*taglen < 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() 55 if ((err = cipher_descriptor[ocb->cipher]->ecb_encrypt(tmp, tmp, &ocb->key)) != CRYPT_OK) { in ocb3_done() 58 ocb3_int_xor_blocks(ocb->aSum_current, ocb->aSum_current, tmp, ocb->block_len); in ocb3_done() 65 ocb3_int_xor_blocks(tmp, ocb->tag_part, ocb->aSum_current, ocb->block_len); in ocb3_done() [all …]
|
A D | ocb3_add_aad.c | 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() 51 LTC_ARGCHK(ocb != NULL); in ocb3_add_aad() 56 l = ocb->block_len - ocb->adata_buffer_bytes; in ocb3_add_aad() 58 XMEMCPY(ocb->adata_buffer+ocb->adata_buffer_bytes, aad, l); in ocb3_add_aad() 61 if (ocb->adata_buffer_bytes == ocb->block_len) { in ocb3_add_aad() 62 if ((err = s_ocb3_int_aad_add_block(ocb, ocb->adata_buffer)) != CRYPT_OK) { in ocb3_add_aad() [all …]
|
A D | ocb3_decrypt_last.c | 26 LTC_ARGCHK(ocb != NULL); in ocb3_decrypt_last() 37 full_blocks = ctlen/ocb->block_len; 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() 64 ocb->checksum[x] ^= 0x80; in ocb3_decrypt_last() 66 ocb->checksum[x] ^= 0x00; in ocb3_decrypt_last() 73 ocb->tag_part[x] = (ocb->checksum[x] ^ iOffset_star[x]) ^ ocb->L_dollar[x]; in ocb3_decrypt_last() 75 …if ((err = cipher_descriptor[ocb->cipher]->ecb_encrypt(ocb->tag_part, ocb->tag_part, &ocb->key)) !… in ocb3_decrypt_last() 83 ocb->tag_part[x] = (ocb->checksum[x] ^ ocb->Offset_current[x]) ^ ocb->L_dollar[x]; in ocb3_decrypt_last() [all …]
|
A D | ocb3_encrypt_last.c | 26 LTC_ARGCHK(ocb != NULL); in ocb3_encrypt_last() 37 full_blocks = ptlen/ocb->block_len; 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() 66 ocb->checksum[x] ^= 0x80; in ocb3_encrypt_last() 68 ocb->checksum[x] ^= 0x00; in ocb3_encrypt_last() 75 ocb->tag_part[x] = (ocb->checksum[x] ^ iOffset_star[x]) ^ ocb->L_dollar[x]; in ocb3_encrypt_last() 77 …if ((err = cipher_descriptor[ocb->cipher]->ecb_encrypt(ocb->tag_part, ocb->tag_part, &ocb->key)) !… in ocb3_encrypt_last() 84 ocb->tag_part[x] = (ocb->checksum[x] ^ ocb->Offset_current[x]) ^ ocb->L_dollar[x]; in ocb3_encrypt_last() [all …]
|
A D | ocb3_init.c | 32 iNonce[ocb->block_len-1] = iNonce[ocb->block_len-1] & 0xC0; in s_ocb3_int_calc_offset_zero() 34 zeromem(ocb->Offset_current, ocb->block_len); in s_ocb3_int_calc_offset_zero() 98 ocb->cipher = cipher; in ocb3_init() 115 ocb->tag_len = taglen; in ocb3_init() 138 zeromem(ocb->L_star, ocb->block_len); in ocb3_init() 139 …if ((err = cipher_descriptor[cipher]->ecb_encrypt(ocb->L_star, ocb->L_star, &ocb->key)) != CRYPT_O… in ocb3_init() 161 current[ocb->block_len-1] = (previous[ocb->block_len-1] << 1) & 255; in ocb3_init() 172 zeromem(ocb->checksum, ocb->block_len); in ocb3_init() 175 ocb->block_index = 1; in ocb3_init() 180 zeromem(ocb->aOffset_current, ocb->block_len); in ocb3_init() [all …]
|
A D | ocb3_decrypt.c | 26 LTC_ARGCHK(ocb != NULL); in ocb3_decrypt() 34 if (ocb->block_len != cipher_descriptor[ocb->cipher]->block_length) { 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() 54 if ((err = cipher_descriptor[ocb->cipher]->ecb_decrypt(tmp, tmp, &ocb->key)) != CRYPT_OK) { in ocb3_decrypt() 59 ocb3_int_xor_blocks(pt_b, tmp, ocb->Offset_current, ocb->block_len); in ocb3_decrypt() 62 ocb3_int_xor_blocks(ocb->checksum, ocb->checksum, pt_b, ocb->block_len); in ocb3_decrypt() [all …]
|
A D | ocb3_encrypt.c | 26 LTC_ARGCHK(ocb != NULL); in ocb3_encrypt() 34 if (ocb->block_len != cipher_descriptor[ocb->cipher]->block_length) { 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() 54 if ((err = cipher_descriptor[ocb->cipher]->ecb_encrypt(tmp, tmp, &ocb->key)) != CRYPT_OK) { in ocb3_encrypt() 59 ocb3_int_xor_blocks(ct_b, tmp, ocb->Offset_current, ocb->block_len); in ocb3_encrypt() 62 ocb3_int_xor_blocks(ocb->checksum, ocb->checksum, pt_b, ocb->block_len); in ocb3_encrypt() [all …]
|
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()
|
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 …]
|
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-3.20.0/core/lib/libtomcrypt/src/headers/ |
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); 380 int ocb3_add_aad(ocb3_state *ocb, const unsigned char *aad, unsigned long aadlen); [all …]
|