Hash Object Functions
The generic Hash Object wraps hashing algorithms into a common interface. In this section, the following Hash Object functions are specified:
>Free
>Init
Free
HashObj destructor
The hash object Free function releases resources used by the object. The object itself will be freed.
Synopsis
#include "fmciphobj.h"
int (*Free)(struct HashObj * ctx);
Parameter | Description |
---|---|
ctx
|
pointer to object to destroy |
Return Value
See CiphObjStat in cipherr.h
Init
Configures the object to perform a hash operation or resets the current Hash operation.
Synopsis
#include "fmciphobj.h"
int (*Init)(struct HashObj * ctx);
Parameter | Description |
---|---|
ctx
|
IN/OUT object to modify |
Return Value
See CiphObjStat in cipherr.h
Update
Uses the object to perform a hash operation or to process more data with the algorithm.
The data passed in buf is passed through the hash algorithm
Synopsis
#include "fmciphobj.h"
int (*Update)(struct
HashObj * ctx,
const void * buf,
unsigned int length
);
Parameter | Description |
---|---|
ctx
|
IN/OUT object to modify |
buf
|
IN message to hash |
length
|
IN length of message |
Return Value
See CiphObjStat in cipherr.h
Final
Final uses the object to finish a hash operation.
If hashVal is NULL, no operation is performed, but the length that would be output is returned in plength.
Synopsis
#include "fmciphobj.h"
int (*Final)(struct
HashObj * ctx,
unsigned char * hashVal,
unsigned int length,
unsigned int * plength
);
Parameter | Description |
---|---|
ctx
|
IN/OUT object to modify |
hashVal
|
OUT where to place hash or NULL for length prediction |
length
|
IN length of message |
plength
|
OUT number of bytes (actually or potentially) returned in hashVal |
Return Value
See CiphObjStat in cipherr.h
GetInfo
HashObjGetInfo will return information about an initialized HashObj. No sensitive information is returned by this function.
Synopsis
#include "fmciphobj.h"
int (*GetInfo)(struct HashObj * ctx, struct HashInfo * hinfo);
Parameter | Description |
---|---|
ctx
|
IN object to query |
hinfo
|
OUT pointer to where to store the result (see the HashInfo description below) |
HashInfo Structure
Allows application to determine characteristics of the digest algorithm.
struct HashInfo {
char name[32];/**< null terminated ascii string e.g. "SHA-1" */
unsigned int blockLength;/**< optimal hash block size */
unsigned int hashLength;/**< size of hash value */
struct HashObj * hobj; /**< version 1 */
};
typedef struct HashInfo HashInfo;
Return Value
See CiphObjStat in cipherr.h
LoadParam
HashObjLoadParam directly modifies a Hash Object state.
Loads the internal parameters of the hash object from a byte array. If the internal data contains integers, the input byte array should contain big endian values for these integers.
See the particular Hash Class implementation description for details on valid parameter types and their values.
See UnloadParam.
Synopsis
#include "fmciphobj.h"
int (*LoadParam)(struct
HashObj * ctx,
const unsigned char * parameters,
unsigned int paramlen
);
Parameter | Description |
---|---|
ctx
|
IN object to query |
parameters
|
IN hash class specific information |
paramlen
|
IN length (in bytes) of parameters |
ctx: IN/OUT object to modify
Return Value
See CiphObjStat in cipherr.h
UnloadParam
HashObjUnloadParam queries a Hash Object state and returns certain information.
Writes the internal parameters of the hash object to a byte array. If the internal data contains integers, the output byte array will contain big endian values for these integers.
See the particular Hash Class implementation description for details on valid parameter types and their values.
See LoadParam.
Synopsis
#include "fmciphobj.h"
int (*UnloadParam)(struct
HashObj * ctx,
unsigned char * parameters,
unsigned int paramlen,
unsigned int * plen
);
Parameter | Description |
---|---|
ctx
|
IN object to query |
parameters
|
OUT hash class specific information (depends on pType) |
paramlen
|
IN length (in bytes) of parameters |
plen
|
OUT where to store the number of bytes returned in parameters (may be * NULL) |
Return Value
See CiphObjStat in cipherr.h