[Cosm Logo]

Data Signing, Encryption, and Hash Functions


v3HashBegin

Syntax

#include "security.h"
s32 v3HashBegin( v3_HASH_TMP * work, u32 type );

Description

Initialize the work structure and setup the data needed to perform the type of hash needed.

Types

V3_HASH_SHA1
160-bits, preferred for signing hashes.
V3_HASH_MD5
128-bits, preferred for checksums.

Return Values

V3_PASS on success, or an error code on failure.

Errors

V3_HASH_ERROR_TYPE
Invalid hash type.
V3_HASH_ERROR_PARAM
The user passed a NULL pointer.
V3_HASH_ERROR_MEMORY
Memory problem.

Example

  v3_HASH_TMP * work;

  if ( ( work = v3MemAlloc( v3u64u32( sizeof( v3_HASH_TMP ) ),
    V3_MEM_NORMAL ) ) == NULL )
  {
    /* Error in memory allocation. */
    return( V3_FAIL );
  }

  if ( v3HashBegin( work, V3_HASH_MD5 ) != V3_PASS )
  {
    /* Failed */
    return( V3_FAIL );
  }


v3HashUpdate

Syntax

#include "security.h"
s32 v3HashUpdate( v3_HASH_TMP * work, const u8 * const data,
  u64 length );

Description

Feed length bytes of data into the work hash. Note: Make sure your data is in big endian format before using.

Return Values

V3_PASS on success, or an error code on failure.

Errors

V3_HASH_ERROR_STATE
Invalid state, wrong order.
V3_HASH_ERROR_PARAM
The user passed a NULL pointer.

Example

  ascii string[2388] = V3_TEST_TEXT_BLOCK;
  v3_HASH_TMP * work;

  /* v3HashBegin() ... */

  if ( v3HashUpdate( work, (ascii *) &string, v3u64u32( sizeof(
    string ) ) ) != V3_PASS )
  {
    /* Failed */
    return( V3_FAIL );
  }


v3HashEnd

Syntax

#include "security.h"
s32 v3HashEnd( v3_HASH * hash, v3_HASH_TMP * work );

Description

Take the work data and generate the final hash.

Return Values

V3_PASS on success, or an error code on failure.

Errors

V3_HASH_ERROR_STATE
Invalid state, wrong order.
V3_HASH_ERROR_MEMORY
Memory problem.

Example

  v3_HASH_TMP * work;
  v3_HASH hash;

  /* v3HashBegin() and v3HashUpdate() ... */

  if ( v3HashEnd( &hash, work ) != V3_PASS )
  {
    /* Failed */
    return( V3_FAIL );
  }

  /* Free the allocated memory */
  v3MemFree( work );


v3HashEq

Syntax

#include "security.h"
s32 v3HashEq( const v3_HASH * hashA, const v3_HASH * hashB );

Description

Check if the hashes are equal.

Return Values

1 if the hashes are equal, or 0 if they are not equal.

Errors

None.

Example

  v3_HASH hashA, hashB;

  /* Fill in the hashes ... */

  if( !v3HashEq( &hashA, &hashB ) )
  {
    /* Hashes are not equal */
  }


v3Random

Syntax

#include "security.h"
s32 v3Random( v3_RANDOM * random, u64 length, u8 * data,
  u64 salt_length, const u8 * salt );

Description

Initialization of the random number generator is done by feeding it salt_length bytes of salt with data == NULL. Any salt data fed to the random generator should be cumulative, so it can be called repeatedly with additional seed to provide more initial randomness.

Generate length bytes of deterministic random bits if we call with salt == NULL, and place them into data.

Generate a non-deterministic random sequence if we call with salt != NULL. The OS will also be asked for some random data if it supports that feature and salt != NULL.

Return Values

V3_PASS on success, or V3_FAIL on failure.

Errors

None.

Example





© Copyright Mithral Communications & Design, Inc. 1999. All rights reserved. Mithral(tm) and Cosm(tm) are trademarks of Mithral Communications & Design, Inc.
Document last modified: