Skip to content

Instantly share code, notes, and snippets.

@agrare
Last active May 18, 2022 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agrare/90510235853901e8f0b494f861fd727c to your computer and use it in GitHub Desktop.
Save agrare/90510235853901e8f0b494f861fd727c to your computer and use it in GitHub Desktop.
#include <openssl/evp.h>
#include <openssl/err.h>
void print_ssl_error_stack(void)
{
int err;
while ((err = ERR_get_error()) != 0) {
fprintf(stderr, "ERR lib=%d reason=%d err=%s\n", ERR_GET_LIB(err), ERR_GET_REASON(err), ERR_reason_error_string(err));
}
}
int main(int argc, char *argv[])
{
unsigned char key[] = "0123456789abcdeF";
unsigned char iv[] = "1234567887654321";
unsigned char data[] = "this is a secret";
unsigned char *out;
int size, outlen, tmplen, err;
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
err = EVP_CipherInit_ex(ctx, EVP_chacha20_poly1305(), NULL, key, iv, 1);
if (err != 1) {
print_ssl_error_stack();
return 1;
}
size = sizeof(data);
out = malloc(size);
err = EVP_CipherUpdate(ctx, out, &outlen, data, size);
if (!err) {
print_ssl_error_stack();
return 1;
}
err = EVP_CipherFinal_ex(ctx, out, &outlen);
if (!err) {
print_ssl_error_stack();
return 1;
}
return 0;
}
@agrare
Copy link
Author

agrare commented May 18, 2022

[root@localhost ~]# gcc fips.c -o fips -lssl -lcrypto
[root@localhost ~]# ./fips 
ERR lib=6 reason=200 err=disabled for FIPS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment