so im trying to add ecryptfs fnek and fekek signatures to the user keyring and im using openssl to generate a random payload for the keys but for some reason the signatures are the same each time i run my program even though RAND_priv_bytes doesn't fail and the value of random_bytes changes each time but the signature stays the same.
here is the code currently.
#include <openssl/rand.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include <keyutils.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
int main(){
key_serial_t fekek_sig;
key_serial_t fnek_sig;
const int BYTE_NUM = 496;
char random_bytes[BYTE_NUM];
const EVP_MD *md = NULL;
const EVP_MD *md2 = NULL;
EVP_MD_CTX *md_ctx = NULL;
EVP_MD_CTX *md2_ctx = NULL;
unsigned char md_res[EVP_MAX_MD_SIZE], md2_res[EVP_MAX_MD_SIZE];
unsigned int md_len, md2_len;
const char KEY_TYPE[] = "user";
const char FEKEK_DESC[] = "EcryptFS FEKEK Signature";
const char FNEK_DESC[] = "EcryptFS FNEK Signature";
md = EVP_get_digestbyname("SHA512");
md2 = EVP_get_digestbyname("BLAKE2B512");
md_ctx = EVP_MD_CTX_new();
md2_ctx = EVP_MD_CTX_new();
EVP_DigestInit_ex(md_ctx, md, NULL);
EVP_DigestInit_ex(md2_ctx, md2, NULL);
int rc;
rc = RAND_priv_bytes(random_bytes, BYTE_NUM);
if (rc == 1)
{
EVP_DigestUpdate(md_ctx, random_bytes, BYTE_NUM);
}
else if (rc == -1 || rc == 0)
{
fprintf(stderr, "%d\n", ERR_get_error());
}
rc = RAND_priv_bytes(random_bytes, BYTE_NUM);
if (rc == 1)
{
EVP_DigestUpdate(md2_ctx, random_bytes, BYTE_NUM);
}
else if (rc == -1 || rc == 0)
{
fprintf(stderr, "%d\n", ERR_get_error());
}
EVP_DigestFinal_ex(md_ctx, md_res, &md_len);
EVP_DigestFinal_ex(md2_ctx, md2_res, &md2_len);
fekek_sig = add_key(KEY_TYPE, FEKEK_DESC, md_res, md_len, KEY_SPEC_USER_KEYRING);
fnek_sig = add_key(KEY_TYPE, FNEK_DESC, md2_res, md2_len, KEY_SPEC_USER_KEYRING);
EVP_MD_CTX_free(md_ctx);
EVP_MD_CTX_free(md2_ctx);
printf("FEKEK=%d\nFNEK=%d\n", fekek_sig, fnek_sig);
return 0;
}
and this is what gets printed
$ gcc main.c -o test -lkeyutils -lssl -lcrypto
$ ./test
FEKEK=570453362
FNEK=791909717
$ ./test
FEKEK=570453362
FNEK=791909717
does anyone know why this is?