src/lib/crypto.c
DIGEST *crypto_digest_new(JCR *jcr, crypto_digest_t type)
{
   DIGEST *digest;
   const EVP_MD *md = NULL; /* Quell invalid uninitialized warnings */

   digest = (DIGEST *)malloc(sizeof(DIGEST));
   digest->type = type;
   digest->jcr = jcr;
   Dmsg1(150, "crypto_digest_new jcr=%p\n", jcr);

   /* Initialize the OpenSSL message digest context */
   digest->ctx = EVP_MD_CTX_new();
   if (!digest->ctx)
           goto err;
   EVP_MD_CTX_reset(digest->ctx);

   /* Determine the correct OpenSSL message digest type */
   switch (type) {
   case CRYPTO_DIGEST_MD5:
      md = EVP_md5();
      break;
   case CRYPTO_DIGEST_SHA1:
      md = EVP_sha1();
      break;
#ifdef HAVE_SHA2
   case CRYPTO_DIGEST_SHA256:
      md = EVP_sha256();
      break;
   case CRYPTO_DIGEST_SHA512:
      md = EVP_sha512();
      break;
#endif
   default:
      Jmsg1(jcr, M_ERROR, 0, _("Unsupported digest type: %d\n"), type);
      goto err;
   }

   /* Initialize the backing OpenSSL context */
   if (EVP_DigestInit_ex(digest->ctx, md, NULL) == 0) {
      goto err;
   }

   return digest;

err:
   /* This should not happen, but never say never ... */
   Dmsg0(150, "Digest init failed.\n");
   openssl_post_errors(jcr, M_ERROR, _("OpenSSL digest initialization failed"));
   crypto_digest_free(digest);
   return NULL;
}
/*
 * Create a new message digest context of the specified type
 *  Returns: A pointer to a DIGEST object on success.
 *           NULL on failure.
 */
Create a new message digest context of the specified type
Returns: A pointer to a DIGEST object on success.
NULL on failure.
Create a new message digest context of the specified type Returns : A pointer to a DIGEST object on success . NULL on failure .
DIGEST *crypto_digest_new(JCR *jcr, crypto_digest_t type)
{
   DIGEST *digest;
   const EVP_MD *md = NULL; 
   digest = (DIGEST *)malloc(sizeof(DIGEST));
   digest->type = type;
   digest->jcr = jcr;
   Dmsg1(150, "crypto_digest_new jcr=%p\n", jcr);
   digest->ctx = EVP_MD_CTX_new();
   if (!digest->ctx)
           goto err;
   EVP_MD_CTX_reset(digest->ctx);
   switch (type) {
   case CRYPTO_DIGEST_MD5:
      md = EVP_md5();
      break;
   case CRYPTO_DIGEST_SHA1:
      md = EVP_sha1();
      break;
#ifdef HAVE_SHA2
   case CRYPTO_DIGEST_SHA256:
      md = EVP_sha256();
      break;
   case CRYPTO_DIGEST_SHA512:
      md = EVP_sha512();
      break;
#endif
   default:
      Jmsg1(jcr, M_ERROR, 0, _("Unsupported digest type: %d\n"), type);
      goto err;
   }
   if (EVP_DigestInit_ex(digest->ctx, md, NULL) == 0) {
      goto err;
   }
   return digest;
err:
   Dmsg0(150, "Digest init failed.\n");
   openssl_post_errors(jcr, M_ERROR, _("OpenSSL digest initialization failed"));
   crypto_digest_free(digest);
   return NULL;
}
DIGEST * crypto_digest_new ( JCR * jcr , crypto_digest_t type ) { DIGEST * digest ; const EVP_MD * md = NULL ; digest = ( DIGEST * ) malloc ( sizeof ( DIGEST ) ) ; digest -> type = type ; digest -> jcr = jcr ; Dmsg1 ( 150 , " \n " , jcr ) ; digest -> ctx = EVP_MD_CTX_new ( ) ; if ( ! digest -> ctx ) goto err ; EVP_MD_CTX_reset ( digest -> ctx ) ; switch ( type ) { case CRYPTO_DIGEST_MD5 : md = EVP_md5 ( ) ; break ; case CRYPTO_DIGEST_SHA1 : md = EVP_sha1 ( ) ; break ; #ifdef HAVE_SHA2 case CRYPTO_DIGEST_SHA256 : md = EVP_sha256 ( ) ; break ; case CRYPTO_DIGEST_SHA512 : md = EVP_sha512 ( ) ; break ; #endif default : Jmsg1 ( jcr , M_ERROR , 0 , _ ( " \n " ) , type ) ; goto err ; } if ( EVP_DigestInit_ex ( digest -> ctx , md , NULL ) == 0 ) { goto err ; } return digest ; err : Dmsg0 ( 150 , " \n " ) ; openssl_post_errors ( jcr , M_ERROR , _ ( " " ) ) ; crypto_digest_free ( digest ) ; return NULL ; }
Create a new message digest context of the specified type
  Returns: A pointer to a DIGEST object on success.
Create a new message digest context of the specified type Returns : A pointer to a DIGEST object on success .
/* Quell invalid uninitialized warnings */ /* Initialize the OpenSSL message digest context */ /* Determine the correct OpenSSL message digest type */ /* Initialize the backing OpenSSL context */ /* This should not happen, but never say never ... */