Struct:ttAhAlgorithm

Jump to: navigation, search
 
typedef struct tsAhAlgorithm {
    ttUser16Bit     aalgName;
    ttUser16Bit     aalgKeyMin;    /* in bits */
    ttUser16Bit     aalgKeyMax;    /* in bits */
    ttUser16Bit     aalgKeyDefault;
    ttUser16Bit     aalgDigestOutBits; /*in bits*/
    ttUser16Bit     aalgDigestTruncateBits; /*in bits*/
#ifdef TM_AALG_VAR_BLOCK_SIZE
    ttUser16Bit     aalgBlockSize; /* in bytes */
#endif /* TM_AALG_VAR_BLOCK_SIZE */
    void            (TM_CODE_FAR *aalgInitFuncPtr) (ttUserVoidPtr contextPtr);
    void            (TM_CODE_FAR *aalgUpdateFuncPtr) (
                                        ttUserVoidPtr  contextPtr, 
                                        ttUser8BitPtr  moreDataPtr, 
                                        ttPktLen       size, 
                                        ttPktLen       offset);
    void            (TM_CODE_FAR *aalgFinalFuncPtr)(
                                      ttUser8BitPtr outDigest, 
                                      ttUserVoidPtr contextPtr);
    int             (TM_CODE_FAR *aalgContextLenFuncPtr) (void);
} ttAhAlgorithm;
typedef ttAhAlgorithm TM_FAR * ttAhAlgorithmPtr;
 


Structure Description

Any authentication algorithm must follow the format of ttAhAlgorithm. The user may use this format to add more authentication algorithms.


Members

  • aalgName
    Algorithm name (i.e. SADB_AALG_MD5HMAC).
  • aalgKeyMin
    The minimum key size (in bits).
  • aalgKeyMax
    The maximum key size (in bits).
  • aalgKeyDefault
    The default key size (in bits).
  • aalgDigestOutBits
    The output digest size (in bits).
  • 160 bits for SHA1_HMAC
  • 128 bits for MD5_HMAC
  • 256 bits for SHA256_HMAC
  • 384 bits for SHA384_HMAC
  • 512 bits for SHA512_HMAC
  • aalgDigestTruncateBits
    The truncated output digest size (in bits) for the authentication header. It is always 96 bits except when TM_USE_SHAHMAC_96 is defined, which makes all SHA2 versions use half their digest in bits. Define TM_USE_SHAHMAC_96 in <trsystem.h> to use a value of 96 for all SHA2 HMACs as well.
  • aalgBlockSize
    Specifies the block size of the authentication algorithm. Only valid when TM_AALG_VAR_BLOCK_SIZE is defined.
  • aalgInitFuncPtr
    The initialization function pointer. The function prototype for the 'aalgInitFuncPtr' is below.
  • aalgUpdateFuncPtr
    The update function pointer. The function prototype for the 'aalgUpdateFuncPtr' is below.
The 'offset' parameter is used for 16-bit or 32-bit DSPs. When using a 16-bit DSP, 'offset' is 0, 1. When using a 32-bit DSP, 'offset' is 0, 1, 2, 3.
  • aalgFinalFuncPtr
    The finalization function pointer. The function prototype for the 'aalgFinalFuncPtr' is below.
  • aalgContextLenFuncPtr
    A pointer to the function which calculates the size of the corresponding context (i.e. ttMd5Cxt or ttSha1Cxt) and returns the length.


Function Prototypes

aalgInitFuncPtr

 
void TM_CODE_FAR * aalgInitFuncPtr(ttUserVoidPtr contextPtr);
 


aalgUpdateFuncPtr

 
void TM_CODE_FAR * aalgUpdateFuncPtr(ttUserVoidPtr contextPtr,
                                     ttUser8BitPtr moreDataPtr,
                                     ttPktLen size,
                                     ttPktLen offset);
 

aalgFinalFuncPtr

 
void TM_CODE_FAR * aalgFinalFuncPtr(ttUser8BitPtr outDigest,
                                    ttUserVoidPtr contextPtr);
 

Example

This example attempts to add another authentication algorithm foobar_HMAC_96. foobar_HMAC_96 accepts key size of 240 bits only. It originally outputs a digest size of 240 bits. We have the context structure for the foobar_HMAC_96 algorithm ttFoobarContext and we wish to use 4 to indicate this authentication algorithm. Now we make foobar_HMAC_96 available in the AH algorithm list. The list is in <trahcore.c>. Before doing that, user should make tfFoobarInit(), tfFoobarUpdate(), tfFoobarFinal(), and tfFoobarContextLen() ready.

 
static ttAhAlgorithm ahAlgorithms[] = {
  {
    SADB_AALG_NONE, 0, 0, 0, 0, 0, 
    0, 0, 0, 0
  }, 
  {
    SADB_AALG_MD5HMAC, 128, 128, 128, 128, 96, 
    tfMd5Init, tfMd5Update, tfMd5Final, tfMd5ContextLen
  },
  {
    SADB_AALG_SHA1HMAC, 160, 160, 160, 160, 96, 
    tfSha1Init, tfSha1Update, tfSha1Final, tfSha1ContextLen
  },
  {
    SADB_AALG_foobarHMAC, 240, 240, 240, 240, 96, 
    tfFoobarInit, tfFoobarUpdate, tfFoobarFinal, tfFoobarContextLen
  }
};
 

Now the user may use algorithm SADB_AALG_FOOBARHMAC (4) the same way as SADB_AALG_MD5HMAC or SADB_AALG_SHA1HMAC.

Hashing Algorithm Key Length Table

Keylength (in bits) Min Max Default
MD5: 128 128 128
SHA1: 160 160 160
SHA256: 256 256 256
SHA384: 384 384 384
SHA512: 512 512 512
Ripemd: 160 160 160