ucryptolib/test.c
static int ossl_sign(EVP_PKEY* signing_key,
                     const EVP_MD* hash,
                     const void* msg,
                     size_t msglen,
                     unsigned char **sig,
                     size_t* siglen) {
  EVP_MD_CTX *ctx = NULL;
  int result = 0;
  unsigned int tmplen = EVP_PKEY_size(signing_key);

  *sig = NULL;
  *siglen = 0;

  ctx = EVP_MD_CTX_create();
  if (!ctx) goto error;

  EVP_MD_CTX_init(ctx);
  EVP_DigestInit(ctx, hash);
  EVP_DigestUpdate(ctx, msg, msglen);

  *sig = (unsigned char*)malloc(tmplen);
  result = EVP_SignFinal(ctx, *sig, &tmplen, signing_key);
  *siglen = tmplen;

error:
  if (result != 1) {
    free(*sig);
  }
  if (ctx) EVP_MD_CTX_destroy(ctx);
  return result;
}
// Sign a message with openssl using RSA private key and specified digest.
// Returns 1 if OK.
Sign a message with openssl using RSA private key and specified digest.
Returns 1 if OK.
Sign a message with openssl using RSA private key and specified digest . Returns 1 if OK .
static int ossl_sign(EVP_PKEY* signing_key,
                     const EVP_MD* hash,
                     const void* msg,
                     size_t msglen,
                     unsigned char **sig,
                     size_t* siglen) {
  EVP_MD_CTX *ctx = NULL;
  int result = 0;
  unsigned int tmplen = EVP_PKEY_size(signing_key);
  *sig = NULL;
  *siglen = 0;
  ctx = EVP_MD_CTX_create();
  if (!ctx) goto error;
  EVP_MD_CTX_init(ctx);
  EVP_DigestInit(ctx, hash);
  EVP_DigestUpdate(ctx, msg, msglen);
  *sig = (unsigned char*)malloc(tmplen);
  result = EVP_SignFinal(ctx, *sig, &tmplen, signing_key);
  *siglen = tmplen;
error:
  if (result != 1) {
    free(*sig);
  }
  if (ctx) EVP_MD_CTX_destroy(ctx);
  return result;
}
static int ossl_sign ( EVP_PKEY * signing_key , const EVP_MD * hash , const void * msg , size_t msglen , unsigned char * * sig , size_t * siglen ) { EVP_MD_CTX * ctx = NULL ; int result = 0 ; unsigned int tmplen = EVP_PKEY_size ( signing_key ) ; * sig = NULL ; * siglen = 0 ; ctx = EVP_MD_CTX_create ( ) ; if ( ! ctx ) goto error ; EVP_MD_CTX_init ( ctx ) ; EVP_DigestInit ( ctx , hash ) ; EVP_DigestUpdate ( ctx , msg , msglen ) ; * sig = ( unsigned char * ) malloc ( tmplen ) ; result = EVP_SignFinal ( ctx , * sig , & tmplen , signing_key ) ; * siglen = tmplen ; error : if ( result != 1 ) { free ( * sig ) ; } if ( ctx ) EVP_MD_CTX_destroy ( ctx ) ; return result ; }
Sign a message with openssl using RSA private key and specified digest.
Sign a message with openssl using RSA private key and specified digest .