Lines Matching +full:restore +full:- +full:keys
1 // SPDX-License-Identifier: BSD-2-Clause
36 /* Cryptographic Operations API - Generic Operation Functions */
102 /* Two 256-bit keys */ in TEE_AllocateOperation()
317 op->info.algorithm = algorithm; in TEE_AllocateOperation()
318 op->info.operationClass = TEE_ALG_GET_CLASS(algorithm); in TEE_AllocateOperation()
321 op->info.operationClass = TEE_OPERATION_ASYMMETRIC_SIGNATURE; in TEE_AllocateOperation()
323 op->info.mode = mode; in TEE_AllocateOperation()
324 op->info.digestLength = TEE_ALG_GET_DIGEST_SIZE(algorithm); in TEE_AllocateOperation()
325 op->info.maxKeySize = maxKeySize; in TEE_AllocateOperation()
326 op->info.requiredKeyUsage = req_key_usage; in TEE_AllocateOperation()
327 op->info.handleState = handle_state; in TEE_AllocateOperation()
333 if (op->info.operationClass == TEE_OPERATION_DIGEST) in TEE_AllocateOperation()
334 block_size = op->info.digestLength; in TEE_AllocateOperation()
342 op->buffer = TEE_Malloc(buffer_size, in TEE_AllocateOperation()
344 if (op->buffer == NULL) { in TEE_AllocateOperation()
349 op->block_size = block_size; in TEE_AllocateOperation()
350 op->buffer_two_blocks = buffer_two_blocks; in TEE_AllocateOperation()
358 * If two keys are expected the max key size is the sum of in TEE_AllocateOperation()
359 * the size of both keys. in TEE_AllocateOperation()
361 if (op->info.handleState & TEE_HANDLE_FLAG_EXPECT_TWO_KEYS) in TEE_AllocateOperation()
364 res = TEE_AllocateTransientObject(key_type, mks, &op->key1); in TEE_AllocateOperation()
368 if (op->info.handleState & TEE_HANDLE_FLAG_EXPECT_TWO_KEYS) { in TEE_AllocateOperation()
370 &op->key2); in TEE_AllocateOperation()
376 res = _utee_cryp_state_alloc(algorithm, mode, (unsigned long)op->key1, in TEE_AllocateOperation()
377 (unsigned long)op->key2, &op->state); in TEE_AllocateOperation()
383 * Other multi-stage operations initialized w/ TEE_xxxInit functions in TEE_AllocateOperation()
384 * Non-applicable on asymmetric operations in TEE_AllocateOperation()
387 res = _utee_hash_init(op->state, NULL, 0); in TEE_AllocateOperation()
391 op->info.handleState |= TEE_HANDLE_FLAG_INITIALIZED; in TEE_AllocateOperation()
394 op->operationState = TEE_OPERATION_STATE_INITIAL; in TEE_AllocateOperation()
404 if (op->state) { in TEE_AllocateOperation()
407 TEE_Free(op->buffer); in TEE_AllocateOperation()
408 TEE_FreeTransientObject(op->key1); in TEE_AllocateOperation()
409 TEE_FreeTransientObject(op->key2); in TEE_AllocateOperation()
426 * Note that keys should not be freed here, since they are in TEE_FreeOperation()
430 res = _utee_cryp_state_free(operation->state); in TEE_FreeOperation()
434 TEE_Free(operation->buffer); in TEE_FreeOperation()
453 *operationInfo = operation->info; in TEE_GetOperationInfo()
454 if (operationInfo->handleState & TEE_HANDLE_FLAG_EXPECT_TWO_KEYS) { in TEE_GetOperationInfo()
455 operationInfo->keySize = 0; in TEE_GetOperationInfo()
456 operationInfo->requiredKeyUsage = 0; in TEE_GetOperationInfo()
480 max_key_count = (*size - sizeof(*op_info)) / in TEE_GetOperationInfoMultiple()
485 /* Two keys flag (TEE_ALG_AES_XTS only) */ in TEE_GetOperationInfoMultiple()
486 two_keys = op->info.handleState & TEE_HANDLE_FLAG_EXPECT_TWO_KEYS; in TEE_GetOperationInfoMultiple()
488 if (op->info.mode == TEE_MODE_DIGEST) { in TEE_GetOperationInfoMultiple()
489 op_info->numberOfKeys = 0; in TEE_GetOperationInfoMultiple()
496 res = TEE_GetObjectInfo1(op->key1, &kinfo); in TEE_GetOperationInfoMultiple()
501 op_info->keyInformation[0].keySize = kinfo.objectSize; in TEE_GetOperationInfoMultiple()
502 op_info->keyInformation[0].requiredKeyUsage = in TEE_GetOperationInfoMultiple()
503 op->info.requiredKeyUsage; in TEE_GetOperationInfoMultiple()
504 op_info->numberOfKeys = 1; in TEE_GetOperationInfoMultiple()
511 res = TEE_GetObjectInfo1(op->key1, &kinfo); in TEE_GetOperationInfoMultiple()
516 op_info->keyInformation[0].keySize = kinfo.objectSize; in TEE_GetOperationInfoMultiple()
517 op_info->keyInformation[0].requiredKeyUsage = in TEE_GetOperationInfoMultiple()
518 op->info.requiredKeyUsage; in TEE_GetOperationInfoMultiple()
520 res = TEE_GetObjectInfo1(op->key2, &kinfo); in TEE_GetOperationInfoMultiple()
525 op_info->keyInformation[1].keySize = kinfo.objectSize; in TEE_GetOperationInfoMultiple()
526 op_info->keyInformation[1].requiredKeyUsage = in TEE_GetOperationInfoMultiple()
527 op->info.requiredKeyUsage; in TEE_GetOperationInfoMultiple()
529 op_info->numberOfKeys = 2; in TEE_GetOperationInfoMultiple()
532 op_info->algorithm = op->info.algorithm; in TEE_GetOperationInfoMultiple()
533 op_info->operationClass = op->info.operationClass; in TEE_GetOperationInfoMultiple()
534 op_info->mode = op->info.mode; in TEE_GetOperationInfoMultiple()
535 op_info->digestLength = op->info.digestLength; in TEE_GetOperationInfoMultiple()
536 op_info->maxKeySize = op->info.maxKeySize; in TEE_GetOperationInfoMultiple()
537 op_info->handleState = op->info.handleState; in TEE_GetOperationInfoMultiple()
538 op_info->operationState = op->operationState; in TEE_GetOperationInfoMultiple()
565 op->operationState = TEE_OPERATION_STATE_INITIAL; in reset_operation_state()
567 if (op->info.operationClass == TEE_OPERATION_DIGEST) { in reset_operation_state()
568 TEE_Result res = _utee_hash_init(op->state, NULL, 0); in reset_operation_state()
572 op->info.handleState |= TEE_HANDLE_FLAG_INITIALIZED; in reset_operation_state()
574 op->info.handleState &= ~TEE_HANDLE_FLAG_INITIALIZED; in reset_operation_state()
583 if (!(operation->info.handleState & TEE_HANDLE_FLAG_KEY_SET)) in TEE_ResetOperation()
603 TEE_ResetTransientObject(operation->key1); in TEE_SetOperationKey()
604 operation->info.handleState &= ~TEE_HANDLE_FLAG_KEY_SET; in TEE_SetOperationKey()
605 if (operation->operationState != TEE_OPERATION_STATE_INITIAL) in TEE_SetOperationKey()
611 if (operation->info.operationClass == TEE_OPERATION_DIGEST) { in TEE_SetOperationKey()
616 /* Two keys flag not expected (TEE_ALG_AES_XTS excluded) */ in TEE_SetOperationKey()
617 if ((operation->info.handleState & TEE_HANDLE_FLAG_EXPECT_TWO_KEYS) != in TEE_SetOperationKey()
629 if ((key_info.objectUsage & operation->info.requiredKeyUsage) != in TEE_SetOperationKey()
630 operation->info.requiredKeyUsage) { in TEE_SetOperationKey()
635 if (operation->info.maxKeySize < key_info.objectSize) { in TEE_SetOperationKey()
642 TEE_ResetTransientObject(operation->key1); in TEE_SetOperationKey()
643 operation->info.handleState &= ~TEE_HANDLE_FLAG_KEY_SET; in TEE_SetOperationKey()
645 res = TEE_CopyObjectAttributes1(operation->key1, key); in TEE_SetOperationKey()
649 operation->info.handleState |= TEE_HANDLE_FLAG_KEY_SET; in TEE_SetOperationKey()
651 operation->info.keySize = key_size; in TEE_SetOperationKey()
653 if (operation->operationState != TEE_OPERATION_STATE_INITIAL) in TEE_SetOperationKey()
669 operation->operationState != TEE_OPERATION_STATE_INITIAL) in __GP11_TEE_SetOperationKey()
691 * Either both keys are NULL or both are not NULL in set_operation_key2()
694 /* Clear the keys */ in set_operation_key2()
695 TEE_ResetTransientObject(operation->key1); in set_operation_key2()
696 TEE_ResetTransientObject(operation->key2); in set_operation_key2()
697 operation->info.handleState &= ~TEE_HANDLE_FLAG_KEY_SET; in set_operation_key2()
698 if (operation->operationState != TEE_OPERATION_STATE_INITIAL) in set_operation_key2()
702 /* Both keys are obviously not valid. */ in set_operation_key2()
708 if (operation->info.operationClass == TEE_OPERATION_DIGEST) { in set_operation_key2()
713 /* Two keys flag expected (TEE_ALG_AES_XTS and TEE_ALG_SM2_KEP only) */ in set_operation_key2()
714 if ((operation->info.handleState & TEE_HANDLE_FLAG_EXPECT_TWO_KEYS) == in set_operation_key2()
726 if ((key_info1.objectUsage & operation->info. in set_operation_key2()
727 requiredKeyUsage) != operation->info.requiredKeyUsage) { in set_operation_key2()
741 if ((key_info2.objectUsage & operation->info. in set_operation_key2()
742 requiredKeyUsage) != operation->info.requiredKeyUsage) { in set_operation_key2()
748 * All the multi key algorithm currently supported requires the keys to in set_operation_key2()
757 if (operation->info.maxKeySize < key_info1.objectSize) { in set_operation_key2()
768 TEE_ResetTransientObject(operation->key1); in set_operation_key2()
769 TEE_ResetTransientObject(operation->key2); in set_operation_key2()
770 operation->info.handleState &= ~TEE_HANDLE_FLAG_KEY_SET; in set_operation_key2()
772 res = TEE_CopyObjectAttributes1(operation->key1, key1); in set_operation_key2()
775 res = TEE_CopyObjectAttributes1(operation->key2, key2); in set_operation_key2()
782 operation->info.handleState |= TEE_HANDLE_FLAG_KEY_SET; in set_operation_key2()
784 operation->info.keySize = key_size; in set_operation_key2()
786 if (operation->operationState != TEE_OPERATION_STATE_INITIAL) in set_operation_key2()
813 operation->operationState != TEE_OPERATION_STATE_INITIAL) in __GP11_TEE_SetOperationKey2()
825 if (dst_op->info.algorithm != src_op->info.algorithm) in TEE_CopyOperation()
827 if (dst_op->info.mode != src_op->info.mode) in TEE_CopyOperation()
829 if (src_op->info.operationClass != TEE_OPERATION_DIGEST) { in TEE_CopyOperation()
833 if (src_op->info.handleState & TEE_HANDLE_FLAG_KEY_SET) { in TEE_CopyOperation()
834 key1 = src_op->key1; in TEE_CopyOperation()
835 key2 = src_op->key2; in TEE_CopyOperation()
838 if ((src_op->info.handleState & in TEE_CopyOperation()
845 dst_op->info.handleState = src_op->info.handleState; in TEE_CopyOperation()
846 dst_op->info.keySize = src_op->info.keySize; in TEE_CopyOperation()
847 dst_op->info.digestLength = src_op->info.digestLength; in TEE_CopyOperation()
848 dst_op->operationState = src_op->operationState; in TEE_CopyOperation()
850 if (dst_op->buffer_two_blocks != src_op->buffer_two_blocks || in TEE_CopyOperation()
851 dst_op->block_size != src_op->block_size) in TEE_CopyOperation()
854 if (dst_op->buffer != NULL) { in TEE_CopyOperation()
855 size_t sz = src_op->block_size; in TEE_CopyOperation()
857 if (src_op->buffer == NULL) in TEE_CopyOperation()
860 if (src_op->buffer_two_blocks) in TEE_CopyOperation()
862 memcpy(dst_op->buffer, src_op->buffer, sz); in TEE_CopyOperation()
863 dst_op->buffer_offs = src_op->buffer_offs; in TEE_CopyOperation()
864 } else if (src_op->buffer != NULL) { in TEE_CopyOperation()
868 res = _utee_cryp_state_copy(dst_op->state, src_op->state); in TEE_CopyOperation()
873 /* Cryptographic Operations API - Message Digest Functions */
884 res = _utee_hash_init(operation->state, IV, IVLen); in init_hash_operation()
887 operation->buffer_offs = 0; in init_hash_operation()
888 operation->info.handleState |= TEE_HANDLE_FLAG_INITIALIZED; in init_hash_operation()
897 operation->info.operationClass != TEE_OPERATION_DIGEST) in TEE_DigestUpdate()
900 operation->operationState = TEE_OPERATION_STATE_ACTIVE; in TEE_DigestUpdate()
902 res = _utee_hash_update(operation->state, chunk, chunkSize); in TEE_DigestUpdate()
922 (operation->info.operationClass != TEE_OPERATION_DIGEST)) { in TEE_DigestDoFinal()
926 if (operation->operationState == TEE_OPERATION_STATE_EXTRACTING && in TEE_DigestDoFinal()
933 if (operation->operationState == TEE_OPERATION_STATE_EXTRACTING && in TEE_DigestDoFinal()
934 operation->buffer) { in TEE_DigestDoFinal()
936 * This is not an Extendable-Output Function and we have in TEE_DigestDoFinal()
939 len = MIN(operation->block_size - operation->buffer_offs, in TEE_DigestDoFinal()
941 memcpy(hash, operation->buffer + operation->buffer_offs, len); in TEE_DigestDoFinal()
945 res = _utee_hash_final(operation->state, chunk, chunkLen, hash, in TEE_DigestDoFinal()
955 operation->operationState = TEE_OPERATION_STATE_INITIAL; in TEE_DigestDoFinal()
987 operation->info.operationClass != TEE_OPERATION_DIGEST) in TEE_DigestExtract()
991 if (!operation->buffer) { in TEE_DigestExtract()
992 /* This is an Extendable-Output Function */ in TEE_DigestExtract()
993 operation->info.handleState |= TEE_HANDLE_FLAG_EXTRACTING; in TEE_DigestExtract()
994 operation->operationState = TEE_OPERATION_STATE_EXTRACTING; in TEE_DigestExtract()
996 res = _utee_hash_final(operation->state, NULL, 0, hash, &hl); in TEE_DigestExtract()
1004 if (operation->operationState != TEE_OPERATION_STATE_EXTRACTING) { in TEE_DigestExtract()
1005 hl = operation->block_size; in TEE_DigestExtract()
1006 res = _utee_hash_final(operation->state, NULL, 0, in TEE_DigestExtract()
1007 operation->buffer, &hl); in TEE_DigestExtract()
1010 if (hl != operation->block_size) in TEE_DigestExtract()
1012 assert(!operation->buffer_offs); in TEE_DigestExtract()
1013 operation->info.handleState |= TEE_HANDLE_FLAG_EXTRACTING; in TEE_DigestExtract()
1014 operation->operationState = TEE_OPERATION_STATE_EXTRACTING; in TEE_DigestExtract()
1017 len = MIN(operation->block_size - operation->buffer_offs, *hashLen); in TEE_DigestExtract()
1018 memcpy(hash, operation->buffer + operation->buffer_offs, len); in TEE_DigestExtract()
1020 operation->buffer_offs += len; in TEE_DigestExtract()
1025 /* Cryptographic Operations API - Symmetric Cipher Functions */
1035 if (operation->info.operationClass != TEE_OPERATION_CIPHER) in TEE_CipherInit()
1038 if (!(operation->info.handleState & TEE_HANDLE_FLAG_KEY_SET) || in TEE_CipherInit()
1039 !(operation->key1)) in TEE_CipherInit()
1042 if (operation->operationState != TEE_OPERATION_STATE_INITIAL) in TEE_CipherInit()
1046 if (operation->info.algorithm == TEE_ALG_AES_ECB_NOPAD || in TEE_CipherInit()
1047 operation->info.algorithm == TEE_ALG_DES_ECB_NOPAD || in TEE_CipherInit()
1048 operation->info.algorithm == TEE_ALG_DES3_ECB_NOPAD || in TEE_CipherInit()
1049 operation->info.algorithm == TEE_ALG_SM4_ECB_NOPAD) in TEE_CipherInit()
1053 operation->operationState = TEE_OPERATION_STATE_ACTIVE; in TEE_CipherInit()
1055 res = _utee_cipher_init(operation->state, IV, IVLen); in TEE_CipherInit()
1059 operation->buffer_offs = 0; in TEE_CipherInit()
1060 operation->info.handleState |= TEE_HANDLE_FLAG_INITIALIZED; in TEE_CipherInit()
1093 if (op->buffer_two_blocks) { in tee_buffer_update()
1094 buffer_size = op->block_size * 2; in tee_buffer_update()
1097 buffer_size = op->block_size; in tee_buffer_update()
1101 if (op->buffer_offs > 0) { in tee_buffer_update()
1103 if (op->buffer_offs < op->block_size) in tee_buffer_update()
1104 l = MIN(slen, op->block_size - op->buffer_offs); in tee_buffer_update()
1106 l = MIN(slen, buffer_size - op->buffer_offs); in tee_buffer_update()
1107 memcpy(op->buffer + op->buffer_offs, src, l); in tee_buffer_update()
1108 op->buffer_offs += l; in tee_buffer_update()
1110 slen -= l; in tee_buffer_update()
1111 if ((op->buffer_offs % op->block_size) != 0) in tee_buffer_update()
1116 if ((op->buffer_offs > 0) && in tee_buffer_update()
1117 ((op->buffer_offs + slen) >= (buffer_size + buffer_left))) { in tee_buffer_update()
1118 l = ROUNDUP2(op->buffer_offs + slen - buffer_size, in tee_buffer_update()
1119 op->block_size); in tee_buffer_update()
1120 l = MIN(op->buffer_offs, l); in tee_buffer_update()
1125 if (!op->buffer_two_blocks) in tee_buffer_update()
1126 l = op->block_size; in tee_buffer_update()
1128 res = update_func(op->state, op->buffer, l, dst, &tmp_dlen); in tee_buffer_update()
1132 dlen -= tmp_dlen; in tee_buffer_update()
1134 op->buffer_offs -= l; in tee_buffer_update()
1135 if (op->buffer_offs > 0) { in tee_buffer_update()
1139 memcpy(op->buffer, op->buffer + l, buffer_size - l); in tee_buffer_update()
1140 memcpy(op->buffer + op->buffer_offs, src, slen); in tee_buffer_update()
1141 op->buffer_offs += slen; in tee_buffer_update()
1148 if (op->buffer_two_blocks) in tee_buffer_update()
1149 l = ROUNDUP2(slen - buffer_size, op->block_size); in tee_buffer_update()
1151 l = ROUNDUP2(slen - buffer_size + 1, op->block_size); in tee_buffer_update()
1154 res = update_func(op->state, src, l, dst, &tmp_dlen); in tee_buffer_update()
1158 slen -= l; in tee_buffer_update()
1160 dlen -= tmp_dlen; in tee_buffer_update()
1165 memcpy(op->buffer + op->buffer_offs, src, slen); in tee_buffer_update()
1166 op->buffer_offs += slen; in tee_buffer_update()
1186 if (operation->info.operationClass != TEE_OPERATION_CIPHER) { in TEE_CipherUpdate()
1191 if ((operation->info.handleState & TEE_HANDLE_FLAG_INITIALIZED) == 0) { in TEE_CipherUpdate()
1196 if (operation->operationState != TEE_OPERATION_STATE_ACTIVE) { in TEE_CipherUpdate()
1208 if (operation->block_size > 1) { in TEE_CipherUpdate()
1209 req_dlen = ((operation->buffer_offs + srcLen) / in TEE_CipherUpdate()
1210 operation->block_size) * operation->block_size; in TEE_CipherUpdate()
1214 if (operation->buffer_two_blocks) { in TEE_CipherUpdate()
1215 if (operation->buffer_offs + srcLen > in TEE_CipherUpdate()
1216 operation->block_size * 2) { in TEE_CipherUpdate()
1217 req_dlen = operation->buffer_offs + srcLen - in TEE_CipherUpdate()
1218 operation->block_size * 2; in TEE_CipherUpdate()
1219 req_dlen = ROUNDUP2(req_dlen, operation->block_size); in TEE_CipherUpdate()
1227 * can't restore sync with this API. in TEE_CipherUpdate()
1236 if (operation->block_size > 1) { in TEE_CipherUpdate()
1241 res = _utee_cipher_update(operation->state, srcData, in TEE_CipherUpdate()
1289 if (operation->info.operationClass != TEE_OPERATION_CIPHER) { in TEE_CipherDoFinal()
1294 if ((operation->info.handleState & TEE_HANDLE_FLAG_INITIALIZED) == 0) { in TEE_CipherDoFinal()
1299 if (operation->operationState != TEE_OPERATION_STATE_ACTIVE) { in TEE_CipherDoFinal()
1308 if (operation->info.algorithm == TEE_ALG_AES_ECB_NOPAD || in TEE_CipherDoFinal()
1309 operation->info.algorithm == TEE_ALG_AES_CBC_NOPAD || in TEE_CipherDoFinal()
1310 operation->info.algorithm == TEE_ALG_DES_ECB_NOPAD || in TEE_CipherDoFinal()
1311 operation->info.algorithm == TEE_ALG_DES_CBC_NOPAD || in TEE_CipherDoFinal()
1312 operation->info.algorithm == TEE_ALG_DES3_ECB_NOPAD || in TEE_CipherDoFinal()
1313 operation->info.algorithm == TEE_ALG_DES3_CBC_NOPAD || in TEE_CipherDoFinal()
1314 operation->info.algorithm == TEE_ALG_SM4_ECB_NOPAD || in TEE_CipherDoFinal()
1315 operation->info.algorithm == TEE_ALG_SM4_CBC_NOPAD) { in TEE_CipherDoFinal()
1316 if (((operation->buffer_offs + srcLen) % operation->block_size) in TEE_CipherDoFinal()
1326 * can't restore sync with this API. in TEE_CipherDoFinal()
1328 if (operation->block_size > 1) { in TEE_CipherDoFinal()
1329 req_dlen = operation->buffer_offs + srcLen; in TEE_CipherDoFinal()
1342 if (operation->block_size > 1) { in TEE_CipherDoFinal()
1353 tmp_dlen = *destLen - acc_dlen; in TEE_CipherDoFinal()
1355 res = _utee_cipher_final(operation->state, operation->buffer, in TEE_CipherDoFinal()
1356 operation->buffer_offs, dst, in TEE_CipherDoFinal()
1359 res = _utee_cipher_final(operation->state, srcData, srcLen, dst, in TEE_CipherDoFinal()
1369 operation->info.handleState &= ~TEE_HANDLE_FLAG_INITIALIZED; in TEE_CipherDoFinal()
1371 operation->operationState = TEE_OPERATION_STATE_INITIAL; in TEE_CipherDoFinal()
1398 /* Cryptographic Operations API - MAC Functions */
1405 if (operation->info.operationClass != TEE_OPERATION_MAC) in TEE_MACInit()
1408 if (!(operation->info.handleState & TEE_HANDLE_FLAG_KEY_SET) || in TEE_MACInit()
1409 !(operation->key1)) in TEE_MACInit()
1412 if (operation->operationState != TEE_OPERATION_STATE_INITIAL) in TEE_MACInit()
1415 operation->operationState = TEE_OPERATION_STATE_ACTIVE; in TEE_MACInit()
1434 if (operation->info.operationClass != TEE_OPERATION_MAC) in TEE_MACUpdate()
1437 if ((operation->info.handleState & TEE_HANDLE_FLAG_INITIALIZED) == 0) in TEE_MACUpdate()
1440 if (operation->operationState != TEE_OPERATION_STATE_ACTIVE) in TEE_MACUpdate()
1443 res = _utee_hash_update(operation->state, chunk, chunkSize); in TEE_MACUpdate()
1467 if (operation->info.operationClass != TEE_OPERATION_MAC) { in TEE_MACComputeFinal()
1472 if ((operation->info.handleState & TEE_HANDLE_FLAG_INITIALIZED) == 0) { in TEE_MACComputeFinal()
1477 if (operation->operationState != TEE_OPERATION_STATE_ACTIVE) { in TEE_MACComputeFinal()
1483 res = _utee_hash_final(operation->state, message, messageLen, mac, &ml); in TEE_MACComputeFinal()
1488 operation->info.handleState &= ~TEE_HANDLE_FLAG_INITIALIZED; in TEE_MACComputeFinal()
1490 operation->operationState = TEE_OPERATION_STATE_INITIAL; in TEE_MACComputeFinal()
1522 if (operation->info.operationClass != TEE_OPERATION_MAC) { in TEE_MACCompareFinal()
1527 if ((operation->info.handleState & TEE_HANDLE_FLAG_INITIALIZED) == 0) { in TEE_MACCompareFinal()
1532 if (operation->operationState != TEE_OPERATION_STATE_ACTIVE) { in TEE_MACCompareFinal()
1552 operation->operationState = TEE_OPERATION_STATE_INITIAL; in TEE_MACCompareFinal()
1569 /* Cryptographic Operations API - Authenticated Encryption Functions */
1582 if (operation->info.operationClass != TEE_OPERATION_AE) { in TEE_AEInit()
1587 if (operation->operationState != TEE_OPERATION_STATE_INITIAL) { in TEE_AEInit()
1593 * AES-CCM tag len is specified by AES-CCM spec and handled in TEE Core in TEE_AEInit()
1594 * in the implementation. But AES-GCM spec doesn't specify the tag len in TEE_AEInit()
1598 if (operation->info.algorithm == TEE_ALG_AES_GCM) { in TEE_AEInit()
1600 * From GP spec: For AES-GCM, can be 128, 120, 112, 104, or 96 in TEE_AEInit()
1608 res = _utee_authenc_init(operation->state, nonce, nonceLen, tagLen / 8, in TEE_AEInit()
1613 operation->info.digestLength = tagLen / 8; in TEE_AEInit()
1614 operation->buffer_offs = 0; in TEE_AEInit()
1615 operation->info.handleState |= TEE_HANDLE_FLAG_INITIALIZED; in TEE_AEInit()
1641 if (operation->info.operationClass != TEE_OPERATION_AE) in TEE_AEUpdateAAD()
1644 if (operation->operationState != TEE_OPERATION_STATE_INITIAL) in TEE_AEUpdateAAD()
1647 if ((operation->info.handleState & TEE_HANDLE_FLAG_INITIALIZED) == 0) in TEE_AEUpdateAAD()
1650 res = _utee_authenc_update_aad(operation->state, AADdata, AADdataLen); in TEE_AEUpdateAAD()
1664 if (operation->info.operationClass != TEE_OPERATION_AE) in __GP11_TEE_AEUpdateAAD()
1667 if ((operation->info.handleState & TEE_HANDLE_FLAG_INITIALIZED) == 0) in __GP11_TEE_AEUpdateAAD()
1670 res = _utee_authenc_update_aad(operation->state, AADdata, AADdataLen); in __GP11_TEE_AEUpdateAAD()
1672 operation->operationState = TEE_OPERATION_STATE_ACTIVE; in __GP11_TEE_AEUpdateAAD()
1694 * can't restore sync with this API. in ae_update_helper()
1696 if (operation->block_size > 1) { in ae_update_helper()
1697 req_dlen = ROUNDDOWN2(operation->buffer_offs + slen, in ae_update_helper()
1698 operation->block_size); in ae_update_helper()
1709 if (operation->block_size > 1) { in ae_update_helper()
1714 res = _utee_authenc_update_payload(operation->state, in ae_update_helper()
1739 if (operation->info.operationClass != TEE_OPERATION_AE) { in TEE_AEUpdate()
1744 if ((operation->info.handleState & TEE_HANDLE_FLAG_INITIALIZED) == 0) { in TEE_AEUpdate()
1751 operation->operationState = TEE_OPERATION_STATE_ACTIVE; in TEE_AEUpdate()
1774 if (operation->info.operationClass != TEE_OPERATION_AE) { in __GP11_TEE_AEUpdate()
1779 if ((operation->info.handleState & TEE_HANDLE_FLAG_INITIALIZED) == 0) { in __GP11_TEE_AEUpdate()
1791 operation->operationState = TEE_OPERATION_STATE_ACTIVE; in __GP11_TEE_AEUpdate()
1820 if (operation->info.operationClass != TEE_OPERATION_AE) { in TEE_AEEncryptFinal()
1825 if ((operation->info.handleState & TEE_HANDLE_FLAG_INITIALIZED) == 0) { in TEE_AEEncryptFinal()
1833 * can't restore sync with this API. in TEE_AEEncryptFinal()
1840 req_dlen = operation->buffer_offs + srcLen; in TEE_AEEncryptFinal()
1846 if (*tagLen < operation->info.digestLength) { in TEE_AEEncryptFinal()
1847 *tagLen = operation->info.digestLength; in TEE_AEEncryptFinal()
1855 tmp_dlen = *destLen - acc_dlen; in TEE_AEEncryptFinal()
1856 if (operation->block_size > 1) { in TEE_AEEncryptFinal()
1865 tmp_dlen = *destLen - acc_dlen; in TEE_AEEncryptFinal()
1866 res = _utee_authenc_enc_final(operation->state, in TEE_AEEncryptFinal()
1867 operation->buffer, in TEE_AEEncryptFinal()
1868 operation->buffer_offs, dst, in TEE_AEEncryptFinal()
1871 res = _utee_authenc_enc_final(operation->state, srcData, in TEE_AEEncryptFinal()
1882 operation->info.handleState &= ~TEE_HANDLE_FLAG_INITIALIZED; in TEE_AEEncryptFinal()
1884 operation->operationState = TEE_OPERATION_STATE_INITIAL; in TEE_AEEncryptFinal()
1931 if (operation->info.operationClass != TEE_OPERATION_AE) { in TEE_AEDecryptFinal()
1936 if ((operation->info.handleState & TEE_HANDLE_FLAG_INITIALIZED) == 0) { in TEE_AEDecryptFinal()
1944 * can't restore sync with this API. in TEE_AEDecryptFinal()
1946 req_dlen = operation->buffer_offs + srcLen; in TEE_AEDecryptFinal()
1953 tmp_dlen = *destLen - acc_dlen; in TEE_AEDecryptFinal()
1954 if (operation->block_size > 1) { in TEE_AEDecryptFinal()
1963 tmp_dlen = *destLen - acc_dlen; in TEE_AEDecryptFinal()
1964 res = _utee_authenc_dec_final(operation->state, in TEE_AEDecryptFinal()
1965 operation->buffer, in TEE_AEDecryptFinal()
1966 operation->buffer_offs, dst, in TEE_AEDecryptFinal()
1969 res = _utee_authenc_dec_final(operation->state, srcData, in TEE_AEDecryptFinal()
1977 if (tagLen != operation->info.digestLength) in TEE_AEDecryptFinal()
1983 operation->info.handleState &= ~TEE_HANDLE_FLAG_INITIALIZED; in TEE_AEDecryptFinal()
1985 operation->operationState = TEE_OPERATION_STATE_INITIAL; in TEE_AEDecryptFinal()
2012 /* Cryptographic Operations API - Asymmetric Functions */
2030 if (!operation->key1) in TEE_AsymmetricEncrypt()
2032 if (operation->info.operationClass != TEE_OPERATION_ASYMMETRIC_CIPHER) in TEE_AsymmetricEncrypt()
2034 if (operation->info.mode != TEE_MODE_ENCRYPT) in TEE_AsymmetricEncrypt()
2039 res = _utee_asymm_operate(operation->state, ua, paramCount, srcData, in TEE_AsymmetricEncrypt()
2069 if (!operation->key1) in __GP11_TEE_AsymmetricEncrypt()
2071 if (operation->info.operationClass != TEE_OPERATION_ASYMMETRIC_CIPHER) in __GP11_TEE_AsymmetricEncrypt()
2073 if (operation->info.mode != TEE_MODE_ENCRYPT) in __GP11_TEE_AsymmetricEncrypt()
2078 res = _utee_asymm_operate(operation->state, ua, paramCount, srcData, in __GP11_TEE_AsymmetricEncrypt()
2106 if (!operation->key1) in TEE_AsymmetricDecrypt()
2108 if (operation->info.operationClass != TEE_OPERATION_ASYMMETRIC_CIPHER) in TEE_AsymmetricDecrypt()
2110 if (operation->info.mode != TEE_MODE_DECRYPT) in TEE_AsymmetricDecrypt()
2115 res = _utee_asymm_operate(operation->state, ua, paramCount, srcData, in TEE_AsymmetricDecrypt()
2145 if (!operation->key1) in __GP11_TEE_AsymmetricDecrypt()
2147 if (operation->info.operationClass != TEE_OPERATION_ASYMMETRIC_CIPHER) in __GP11_TEE_AsymmetricDecrypt()
2149 if (operation->info.mode != TEE_MODE_DECRYPT) in __GP11_TEE_AsymmetricDecrypt()
2154 res = _utee_asymm_operate(operation->state, ua, paramCount, srcData, in __GP11_TEE_AsymmetricDecrypt()
2182 if (!operation->key1) in TEE_AsymmetricSignDigest()
2184 if (operation->info.operationClass != in TEE_AsymmetricSignDigest()
2187 if (operation->info.mode != TEE_MODE_SIGN) in TEE_AsymmetricSignDigest()
2192 res = _utee_asymm_operate(operation->state, ua, paramCount, digest, in TEE_AsymmetricSignDigest()
2219 if (!operation->key1) in __GP11_TEE_AsymmetricSignDigest()
2221 if (operation->info.operationClass != in __GP11_TEE_AsymmetricSignDigest()
2224 if (operation->info.mode != TEE_MODE_SIGN) in __GP11_TEE_AsymmetricSignDigest()
2229 res = _utee_asymm_operate(operation->state, ua, paramCount, digest, in __GP11_TEE_AsymmetricSignDigest()
2256 if (!operation->key1) in TEE_AsymmetricVerifyDigest()
2258 if (operation->info.operationClass != in TEE_AsymmetricVerifyDigest()
2261 if (operation->info.mode != TEE_MODE_VERIFY) in TEE_AsymmetricVerifyDigest()
2265 res = _utee_asymm_verify(operation->state, ua, paramCount, digest, in TEE_AsymmetricVerifyDigest()
2291 if (!operation->key1) in __GP11_TEE_AsymmetricVerifyDigest()
2293 if (operation->info.operationClass != in __GP11_TEE_AsymmetricVerifyDigest()
2296 if (operation->info.mode != TEE_MODE_VERIFY) in __GP11_TEE_AsymmetricVerifyDigest()
2300 res = _utee_asymm_verify(operation->state, ua, paramCount, digest, in __GP11_TEE_AsymmetricVerifyDigest()
2309 /* Cryptographic Operations API - Key Derivation Functions */
2324 if (TEE_ALG_GET_CLASS(operation->info.algorithm) != in TEE_DeriveKey()
2328 if (operation->info.operationClass != TEE_OPERATION_KEY_DERIVATION) in TEE_DeriveKey()
2330 if (!operation->key1) in TEE_DeriveKey()
2332 if (operation->info.mode != TEE_MODE_DERIVE) in TEE_DeriveKey()
2334 if ((operation->info.handleState & TEE_HANDLE_FLAG_KEY_SET) == 0) in TEE_DeriveKey()
2347 res = _utee_cryp_derive_key(operation->state, ua, paramCount, in TEE_DeriveKey()
2366 if (TEE_ALG_GET_CLASS(operation->info.algorithm) != in __GP11_TEE_DeriveKey()
2370 if (operation->info.operationClass != TEE_OPERATION_KEY_DERIVATION) in __GP11_TEE_DeriveKey()
2372 if (!operation->key1) in __GP11_TEE_DeriveKey()
2374 if (operation->info.mode != TEE_MODE_DERIVE) in __GP11_TEE_DeriveKey()
2376 if ((operation->info.handleState & TEE_HANDLE_FLAG_KEY_SET) == 0) in __GP11_TEE_DeriveKey()
2389 res = _utee_cryp_derive_key(operation->state, ua, paramCount, in __GP11_TEE_DeriveKey()
2395 /* Cryptographic Operations API - Random Number Generation Functions */