Logo Search packages:      
Sourcecode: libtomcrypt version File versions  Download package

int hash_memory_multi ( int  hash,
unsigned char *  out,
unsigned long *  outlen,
const unsigned char *  in,
unsigned long  inlen,

Hash multiple (non-adjacent) blocks of memory at once.

hashThe index of the hash you wish to use
out[out] Where to store the digest
outlen[in/out] Max size and resulting size of the digest
inThe data you wish to hash
inlenThe length of the data to hash (octets)
...tuples of (data,len) pairs to hash, terminated with a (NULL,x) (x=don't care)
CRYPT_OK if successful

Definition at line 28 of file hash_memory_multi.c.

References ltc_hash_descriptor::done, ltc_hash_descriptor::hashsize, and zeromem().

    hash_state          *md;
    int                  err;
    va_list              args;
    const unsigned char *curptr;
    unsigned long        curlen;

    LTC_ARGCHK(in     != NULL);
    LTC_ARGCHK(out    != NULL);
    LTC_ARGCHK(outlen != NULL);

    if ((err = hash_is_valid(hash)) != CRYPT_OK) {
        return err;

    if (*outlen < hash_descriptor[hash].hashsize) {
       *outlen = hash_descriptor[hash].hashsize;

    md = XMALLOC(sizeof(hash_state));
    if (md == NULL) {
       return CRYPT_MEM;

    if ((err = hash_descriptor[hash].init(md)) != CRYPT_OK) {
       goto LBL_ERR;

    va_start(args, inlen);
    curptr = in; 
    curlen = inlen;
    for (;;) {
       /* process buf */
       if ((err = hash_descriptor[hash].process(md, curptr, curlen)) != CRYPT_OK) {
          goto LBL_ERR;
       /* step to next */
       curptr = va_arg(args, const unsigned char*);
       if (curptr == NULL) {
       curlen = va_arg(args, unsigned long);
    err = hash_descriptor[hash].done(md, out);
    *outlen = hash_descriptor[hash].hashsize;
    zeromem(md, sizeof(hash_state));
    return err;

Here is the call graph for this function:

Generated by  Doxygen 1.6.0   Back to index