What is exact alternate API instead of AES_ctr128_encrypt from openssl 1.1.0?

Viewed 2297

I need to use 128 bit AES algrothm in CTR mode for encryption from the openssl library. But it seems that the corresponding function AES_ctr128_encrypt is removed from openssl 1.1.0g. because I get below error:-

Documentation or references from internet does not suggest the alternate function for AES CTR mode. What is the exact alternate for AES_ctr128_encrypt with openssl 1.1.0g?

2 Answers

To mnistic's answer, I would only add that you should not forget to include these headers:

  • openssl/aes.h
  • openssl/modes.h

So then this:

AES_ctr128_encrypt(
  cipher_in,
  plaintext_out,
  bytes_length,
  &cipher->aes_key->key,
  cipher->aes_key->IV,
  counter,
  &offset);

would become:

#include <openssl/aes.h>
#include <openssl/modes.h>
.
.
.
CRYPTO_ctr128_encrypt(
  cipher_in,
  plaintext_out,
  bytes_length,
  &cipher->aes_key->key,
  cipher->aes_key->IV,
  counter,
  &offset, 
  (block128_f)AES_encrypt);

You can use CRYPTO_ctr128_encrypt(), so instead of:

AES_ctr128_encrypt(
  in, 
  out, 
  len, 
  &cipher->aes_key->key, 
  cipher->aes_key->IV, 
  buffer, 
  &num);

You would do:

CRYPTO_ctr128_encrypt(
  in, 
  out, 
  len, 
  &cipher->aes_key->key, 
  cipher->aes_key->IV, 
  buffer, 
  &num, 
  (block128_f)AES_encrypt);
Related