Home | History | Annotate | Download | only in tpm2
      1 // This file was extracted from the TCG Published
      2 // Trusted Platform Module Library
      3 // Part 3: Commands
      4 // Family "2.0"
      5 // Level 00 Revision 01.16
      6 // October 30, 2014
      7 
      8 #include "InternalRoutines.h"
      9 #include "HMAC_Start_fp.h"
     10 //
     11 //
     12 //     Error Returns                     Meaning
     13 //
     14 //     TPM_RC_ATTRIBUTES                 key referenced by handle is not a signing key or is restricted
     15 //     TPM_RC_OBJECT_MEMORY              no space to create an internal object
     16 //     TPM_RC_KEY                        key referenced by handle is not an HMAC key
     17 //     TPM_RC_VALUE                      hashAlg is not compatible with the hash algorithm of the scheme of
     18 //                                       the object referenced by handle
     19 //
     20 TPM_RC
     21 TPM2_HMAC_Start(
     22    HMAC_Start_In     *in,                 // IN: input parameter list
     23    HMAC_Start_Out    *out                 // OUT: output parameter list
     24    )
     25 {
     26    OBJECT                    *hmacObject;
     27    TPMT_PUBLIC               *publicArea;
     28    TPM_ALG_ID                 hashAlg;
     29 
     30 // Input Validation
     31 
     32    // Get HMAC key object and public area pointers
     33    hmacObject = ObjectGet(in->handle);
     34    publicArea = &hmacObject->publicArea;
     35 
     36    // Make sure that the key is an HMAC key
     37    if(publicArea->type != TPM_ALG_KEYEDHASH)
     38        return TPM_RC_TYPE + RC_HMAC_Start_handle;
     39 
     40    // and that it is unrestricted
     41    if(publicArea->objectAttributes.restricted == SET)
     42        return TPM_RC_ATTRIBUTES + RC_HMAC_Start_handle;
     43 
     44    // and that it is a signing key
     45    if(publicArea->objectAttributes.sign != SET)
     46        return TPM_RC_KEY + RC_HMAC_Start_handle;
     47 
     48    // See if the key has a default
     49    if(publicArea->parameters.keyedHashDetail.scheme.scheme == TPM_ALG_NULL)
     50        // it doesn't so use the input value
     51        hashAlg = in->hashAlg;
     52    else
     53    {
     54        // key has a default so use it
     55        hashAlg
     56            = publicArea->parameters.keyedHashDetail.scheme.details.hmac.hashAlg;
     57        // and verify that the input was either the TPM_ALG_NULL or the default
     58        if(in->hashAlg != TPM_ALG_NULL && in->hashAlg != hashAlg)
     59            hashAlg = TPM_ALG_NULL;
     60    }
     61    // if we ended up without a hash algorith then return an error
     62    if(hashAlg == TPM_ALG_NULL)
     63        return TPM_RC_VALUE + RC_HMAC_Start_hashAlg;
     64 
     65 // Internal Data Update
     66 
     67   // Create a HMAC sequence object. A TPM_RC_OBJECT_MEMORY error may be
     68   // returned at this point
     69   return ObjectCreateHMACSequence(hashAlg,
     70                                   in->handle,
     71                                   &in->auth,
     72                                   &out->sequenceHandle);
     73 }
     74