2N/A * Copyright (C) 1998, 1999, 2002, 2003, 2006, 2N/A * 2008 Free Software Foundation, Inc. 2N/A * This file is part of Libgcrypt. 2N/A * Libgcrypt is free software; you can redistribute it and/or modify 2N/A * it under the terms of the GNU Lesser general Public License as 2N/A * published by the Free Software Foundation; either version 2.1 of 2N/A * the License, or (at your option) any later version. 2N/A * Libgcrypt is distributed in the hope that it will be useful, 2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of 2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2N/A * GNU Lesser General Public License for more details. 2N/A * You should have received a copy of the GNU Lesser General Public 2N/A/* A dummy extraspec so that we do not need to tests the extraspec 2N/A field from the module specification against NULL and instead 2N/A directly test the respective fields of extraspecs. */ 2N/A/* This is the list of the digest implementations included in 2N/A /* We allow the CRC algorithms even in FIPS mode because they are 2N/A actually no cryptographic primitives. */ 2N/A/* List of registered digests. */ 2N/A/* This is the lock protecting DIGESTS_REGISTERED. */ 2N/A/* Flag to check wether the default ciphers have already been 2N/A/* this structure is put right after the gcry_md_hd_t buffer, so that 2N/A * only one memory block is needed. */ 2N/A/* Convenient macro for registering the default digests. */ 2N/A/* Internal function. Register all the ciphers included in 2N/A CIPHER_TABLE. Returns zero on success or an error code. */ 2N/A continue;
/* Do not register in enforced fips mode. */ 2N/A/* Internal callback function. */ 2N/A/* Internal callback function. Used via _gcry_module_lookup. */ 2N/A/* Internal function. Lookup a digest entry by it's name. */ 2N/A/* Internal function. Lookup a cipher entry by it's oid. */ 2N/A/* Register a new digest module whose specification can be found in 2N/A DIGEST. On success, a new algorithm ID is stored in ALGORITHM_ID 2N/A and a pointer representhing this module is stored in MODULE. */ 2N/A /* We do not support module loading in fips mode. */ 2N/A/* Unregister the digest identified by ID, which must have been 2N/A registered with gcry_digest_register. */ 2N/A * Map a string to the digest algo 2N/A /* If the string starts with a digit (optionally prefixed with 2N/A either "OID." or "oid."), we first look into our table of ASN.1 2N/A object identifiers to figure out the algorithm */ 2N/A /* Not found, search a matching digest name. */ 2N/A * Map a digest algo to a string 2N/A * This function simply returns the name of the algorithm or some constant 2N/A * string when there is no algo. It will never return NULL. 2N/A * Use the macro gcry_md_test_algo() to check whether the algorithm 2N/A * Open a message digest handle for use with algorithm ALGO. 2N/A * More algorithms may be added by md_enable(). The initial algorithm 2N/A /* Allocate a memory area to hold the caller visible buffer with it's 2N/A * control information and the data required by this module. Set the 2N/A * context pointer at the beginning to this area. 2N/A * We have to use this strange scheme because we want to hide the 2N/A * internal data but have a variable sized buffer. 2N/A * +---+------+---........------+-------------+ 2N/A * !ctx! bctl ! buffer ! private ! 2N/A * +---+------+---........------+-------------+ 2N/A * !---------------------------! 2N/A * We have to make sure that private is well aligned. 2N/A /* Allocate and set the Context pointer to the private data */ 2N/A /* Setup the globally visible data (bctl in the diagram).*/ 2N/A /* Initialize the private data. */ 2N/A /* Hmmm, should we really do that? - yes [-wk] */ 2N/A/* Create a message digest object for algorithm ALGO. FLAGS may be 2N/A given as an bitwise OR of the gcry_md_flags values. ALGO may be 2N/A given as 0 if the algorithms to be used are later set using 2N/A gcry_md_enable. H is guaranteed to be a valid handle or NULL on 2N/A return err;
/* already enabled */ 2N/A /* We should never get to here because we do not register 2N/A MD5 in enforced fips mode. But better throw an error. */ 2N/A /* And allocate a new list entry. */ 2N/A /* And init this instance. */ 2N/A /* No need to copy the buffer due to the write above. */ 2N/A /* Copy the complete list of algorithms. The copied list is 2N/A reversed, but that doesn't matter. */ 2N/A /* Add a reference to the module. */ 2N/A * Reset all contexts and discard any buffered stuff. This may be used 2N/A * instead of a md_close(); md_open(). 2N/A /* Note: We allow this even in fips non operational mode. */ 2N/A /* Note: We allow this even in fips non operational mode. */ 2N/A /* Finish the hmac. */ 2N/A /* Replace our digest with the mac (they have the same size). */ 2N/A/* The new debug interface. If SUFFIX is a string it creates an debug 2N/A file for the context HD. IF suffix is NULL, the file is closed and 2N/A debugging is stopped. */ 2N/A * if ALGO is null get the digest for the used algo (which should be only one) 2N/A /* return the first algorithm */ 2N/A * Read out the complete digest, this function implictly finalizes 2N/A /* This function is expected to always return a digest, thus we 2N/A can't return an error which we actually should do in 2N/A non-operational state. */ 2N/A * Read out an intermediate digest. Not yet functional. 2N/A * Shortcut function to hash a buffer with a given algo. The only 2N/A * guaranteed supported algorithms are RIPE-MD160 and SHA-1. The 2N/A * supplied digest buffer must be large enough to store the resulting 2N/A * hash. No error is returned, the function will abort on an invalid 2N/A * algo. DISABLED_ALGOS are ignored here. */ 2N/A /* For the others we do not have a fast function, so we use the 2N/A normal functions. */ 2N/A /* We should never get to here because we do not register 2N/A MD5 in enforced fips mode. */ 2N/A log_error (
"WARNING: more than one algorithm in md_get_algo()\n");
2N/A * Return the length of the digest 2N/A * Return the length of the digest in bytes. 2N/A * This function will return 0 in case of errors. 2N/A/* Hmmm: add a mode to enumerate the OIDs 2N/A * Return information about the given cipher algorithm 2N/A * WHAT select the kind of information returned: 2N/A * GCRYCTL_TEST_ALGO: 2N/A * Returns 0 when the specified algorithm is available for use. 2N/A * buffer and nbytes must be zero. 2N/A * GCRYCTL_GET_ASNOID: 2N/A * Return the ASNOID of the algorithm in buffer. if buffer is NULL, only 2N/A * the required length is returned. 2N/A * Note: Because this function is in most cases used to return an 2N/A * integer value, we can make it easier for the caller to just look at 2N/A * the return value. The caller will in all cases consult the value 2N/A * and thereby detecting whether a error occured or not (i.e. while checking 2N/A /* We need to check that the algo is available because 2N/A md_asn_oid would otherwise raise an assertion. */ 2N/A {
/* a kludge to pull in the __muldi3 for Solaris */ 2N/A * Return information about the digest handle. 2N/A * GCRYCTL_IS_SECURE: 2N/A * Returns 1 when the handle works on secured memory 2N/A * otherwise 0 is returned. There is no error return. 2N/A * GCRYCTL_IS_ALGO_ENABLED: 2N/A * Returns 1 if the algo is enabled for that handle. 2N/A * The algo must be passed as the address of an int. 2N/A/* Explicitly initialize this module. */ 2N/A value =
1;
/* It seems to be better to assume secure memory on 2N/A/* Get a list consisting of the IDs of the loaded message digest 2N/A modules. If LIST is zero, write the number of loaded message 2N/A digest modules to LIST_LENGTH and return. If LIST is non-zero, the 2N/A first *LIST_LENGTH algorithm IDs are stored in LIST, which must be 2N/A of according size. In case there are less message digest modules 2N/A than *LIST_LENGTH, *LIST_LENGTH is updated to the correct 2N/A/* Run the selftests for digest algorithm ALGO with optional reporting 2N/A "no selftest available" :
2N/A module?
"algorithm disabled" :
"algorithm not found");