Lines Matching refs:cipherKey
90 AesCipherKey *cipherKey, const AesInputData *inData, int32_t encMode, AesOutputData *outData)
95 if (cipherKey == NULL || cipherKey->ivLen != AES_IV_LENGTH || inData == NULL || inData->data == NULL ||
101 switch (cipherKey->keyLen) {
109 COMM_LOGE(COMM_ADAPTER, "cipherKey->keyLen unable to get encryption bits.");
112 if (AES_set_encrypt_key(cipherKey->key, bits, &aes) < 0) {
117 AES_cfb128_encrypt(inData->data, outData->data, inData->len, &aes, cipherKey->iv, &num, ENCRYPT_MODE);
119 AES_cfb128_encrypt(inData->data, outData->data, inData->len, &aes, cipherKey->iv, &num, DECRYPT_MODE);
126 static int32_t RootKeyGenerateIvAndSessionKey(const EncryptKey *randomKey, EncryptKey *rootKey, AesCipherKey *cipherKey)
133 if (memcpy_s(cipherKey->key, cipherKey->keyLen, result, AES_SESSION_KEY_LENGTH) != EOK) {
138 if (memcpy_s(cipherKey->iv, cipherKey->ivLen, result + AES_SESSION_KEY_LENGTH,
148 static int32_t GenerateIvAndSessionKey(const EncryptKey *randomKey, EncryptKey *rootKey, AesCipherKey *cipherKey)
150 if (cipherKey == NULL) {
154 cipherKey->keyLen = AES_SESSION_KEY_LENGTH;
155 cipherKey->ivLen = AES_IV_LENGTH;
156 cipherKey->key = (uint8_t *)SoftBusCalloc(cipherKey->keyLen);
157 if (cipherKey->key == NULL) {
160 cipherKey->iv = (uint8_t *)SoftBusCalloc(cipherKey->ivLen);
161 if (cipherKey->iv == NULL) {
162 SoftBusFree(cipherKey->key);
165 if (RootKeyGenerateIvAndSessionKey(randomKey, rootKey, cipherKey) != SOFTBUS_OK) {
167 (void)memset_s(cipherKey->key, cipherKey->keyLen, 0, cipherKey->keyLen);
168 (void)memset_s(cipherKey->iv, cipherKey->ivLen, 0, cipherKey->ivLen);
169 SoftBusFree(cipherKey->key);
170 SoftBusFree(cipherKey->iv);
184 AesCipherKey cipherKey = { 0 };
190 if (GenerateIvAndSessionKey(randomKey, rootKey, &cipherKey) != SOFTBUS_OK) {
195 if (OpensslAesCfbEncrypt(&cipherKey, inData, encMode, &encryptData) != SOFTBUS_OK) {
197 (void)memset_s(cipherKey.key, cipherKey.keyLen, 0, cipherKey.keyLen);
198 (void)memset_s(cipherKey.iv, cipherKey.ivLen, 0, cipherKey.ivLen);
199 SoftBusFree(cipherKey.key);
200 SoftBusFree(cipherKey.iv);
205 (void)memset_s(cipherKey.key, cipherKey.keyLen, 0, cipherKey.keyLen);
206 (void)memset_s(cipherKey.iv, cipherKey.ivLen, 0, cipherKey.ivLen);
207 SoftBusFree(cipherKey.key);
208 SoftBusFree(cipherKey.iv);
215 const AesInputData *inData, AesCipherKey *cipherKey, int32_t encMode, AesOutputData *outData)
220 if (inData == NULL || inData->data == NULL || cipherKey == NULL || cipherKey->ivLen < RANDOM_LENGTH ||
225 if (memcpy_s(random, sizeof(random), cipherKey->iv, sizeof(random)) != EOK) {
229 EncryptKey key = { cipherKey->key, cipherKey->keyLen };
235 (void)memset_s(cipherKey->key, cipherKey->keyLen, 0, cipherKey->keyLen);
236 if (memcpy_s(cipherKey->key, cipherKey->keyLen, result, SHA256_MAC_LEN) != EOK) {
237 COMM_LOGE(COMM_ADAPTER, "fill cipherKey->key failed!");
249 if (OpensslAesCfbEncrypt(cipherKey, inData, encMode, &encryptData) != SOFTBUS_OK) {
319 const uint8_t *srcData, uint32_t srcDataLen, AesCipherKey *cipherKey, uint8_t *outData, uint32_t *outDataLen)
321 if (srcData == NULL || srcDataLen == 0 || cipherKey == NULL || outData == NULL || outDataLen == NULL ||
327 int32_t ret = GcmOpensslEvpInit(&ctx, cipherKey->keyLen, ENCRYPT_MODE);
329 if (EVP_EncryptInit_ex(ctx, NULL, NULL, cipherKey->key, cipherKey->iv) != 1) {
372 const uint8_t *srcData, uint32_t srcDataLen, AesCipherKey *cipherKey, uint8_t *outData, uint32_t *outDataLen)
374 if (srcData == NULL || srcDataLen <= AES_GCM_TAG_LEN || cipherKey == NULL || outData == NULL ||
380 if (GcmOpensslEvpInit(&ctx, cipherKey->keyLen, DECRYPT_MODE) != SOFTBUS_OK) {
384 if (EVP_DecryptInit_ex(ctx, NULL, NULL, cipherKey->key, cipherKey->iv) != 1) {
424 const AesInputData *inData, AesCipherKey *cipherKey, int32_t encMode, AesOutputData *outData)
426 if (inData == NULL || inData->data == NULL || cipherKey == NULL || cipherKey->key == NULL ||
427 cipherKey->iv == NULL || outData == NULL || (encMode != ENCRYPT_MODE && encMode != DECRYPT_MODE)) {
438 if (OpensslAesGcmEncrypt(inData->data, inData->len, cipherKey, encryptData, &encryptDataLen) != SOFTBUS_OK) {
445 if (OpensslAesGcmDecrypt(inData->data, inData->len, cipherKey, encryptData, &encryptDataLen) != SOFTBUS_OK) {