OiO.lk Blog C++ What replaces AES_set_decrypt_key and AES_unwrap_key in OpenSSL 3?
C++

What replaces AES_set_decrypt_key and AES_unwrap_key in OpenSSL 3?


The AES_set_decrypt_key and AES_unwrap_key functions are deprecated in OpenSSL 3. I’m maintaining a function which uses them that I’d like to update to use non-deprecated functions:

std::unique_ptr<uint8_t[]> rfc3394_key_unwrap(const uint8_t* key, size_t key_len,
    const void *input, size_t input_len, const void *iv) noexcept 
{
  AES_KEY aes_key;
  AES_set_decrypt_key(key, key_len * 8, &aes_key);

  const int output_len = input_len - 8;

  auto out = std::make_unique<uint8_t[]>(output_len);

  const auto ret = AES_unwrap_key(&aes_key, (const uint8_t*)iv, out.get(),
                                  (const uint8_t*)input, input_len);

  if (ret != output_len) {
    return nullptr;
  }

  return out;
}

Or, in C if you prefer:

uint8_t* rfc3394_key_unwrap(const uint8_t *key, size_t key_len, const void *input,
    size_t input_len, const void *iv)
{
  AES_KEY aes_key;
  AES_set_decrypt_key(key, key_len * 8, &aes_key);

  const int output_len = input_len - 8;

  uint8_t* out = (uint8_t*) malloc(output_len);

  const intret = AES_unwrap_key(&aes_key, (const uint8_t*)iv, out,
                                (const uint8_t*)input, input_len);

  if (ret != output_len) {
    free(out);
    return NULL;
  }

  return out;
}

I haven’t been able to determine what the replacements are (possibly amongst the EVP_CIPHER functions?). What should I be looking for?



You need to sign in to view this answers

Exit mobile version