Skip to content

Commit

Permalink
More minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
aggarw13 committed Aug 19, 2021
1 parent 6cc5dce commit aeabd54
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions source/include/sigv4_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

#define HMAC_INNER_PAD_BYTE ( 0x36U ) /**< The "ipad" byte used for generating the inner key in the HMAC calculation process. */
#define HMAC_OUTER_PAD_BYTE ( 0x5CU ) /**< The "opad" byte used for generating the outer key in the HMAC calculation process. */
#define HMAX_IPAD_XOR_OPAD_BYTE ( 0x6AU ) /**< The XOR of the "ipad" and "opad" bytes to extract outer key from inner key. */

/**
* @brief A helper macro to print insufficient memory errors.
Expand Down
3 changes: 1 addition & 2 deletions source/sigv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -2494,8 +2494,7 @@ static int32_t hmacFinal( HmacContext_t * pHmacContext,
* this is by performing XOR on each byte of the inner-padded key (ipad ^ opad). */
for( i = 0U; i < pCryptoInterface->hashBlockLen; i++ )
{
static const uint8_t padByteForOuterKey = HMAC_INNER_PAD_BYTE ^ HMAC_OUTER_PAD_BYTE;
pHmacContext->key[ i ] ^= padByteForOuterKey;
pHmacContext->key[ i ] ^= HMAX_IPAD_XOR_OPAD_BYTE;
}

returnStatus = pCryptoInterface->hashInit( pCryptoInterface->pHashContext );
Expand Down
12 changes: 6 additions & 6 deletions test/unit-test/sigv4_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
#define QUERY_WITH_SPECIAL_CHARS "param=/"

#define QUERY_STRING_NO_PARAM_VALUE "param=&param2="
#define QUERY_STRING_WITH_TRAILING_N_LEADING_AMPERSANT "&&param2=&&"
#define QUERY_STRING_WITH_REPEATED_AMPERSANT "param1=val&&param2=val"
#define QUERY_STRING_WITH_TRAILING_N_LEADING_AMPERSAND "&&param2=&&"
#define QUERY_STRING_WITH_REPEATED_AMPERSAND "param1=val&&param2=val"

#define QUERY "Action=ListUsers&Version=2010-05-08"
#define QUERY_LENGTH ( sizeof( QUERY ) - 1U )
Expand Down Expand Up @@ -769,8 +769,8 @@ void test_SigV4_GenerateAuthorization_Query_Strings_Special_Cases()
printf( "%.*s\n", authBufLen, authBuf );
TEST_ASSERT_EQUAL_MEMORY( pExpectedSignature, signature, signatureLen );

params.pHttpParameters->pQuery = QUERY_STRING_WITH_TRAILING_N_LEADING_AMPERSANT;
params.pHttpParameters->queryLen = strlen( QUERY_STRING_WITH_TRAILING_N_LEADING_AMPERSANT );
params.pHttpParameters->pQuery = QUERY_STRING_WITH_TRAILING_N_LEADING_AMPERSAND;
params.pHttpParameters->queryLen = strlen( QUERY_STRING_WITH_TRAILING_N_LEADING_AMPERSAND );

pExpectedSignature = "576a0348d54591e15bed920586936f9263656470197adf7ce79c5fc8ef44d825";

Expand All @@ -779,8 +779,8 @@ void test_SigV4_GenerateAuthorization_Query_Strings_Special_Cases()
TEST_ASSERT_EQUAL( SIGV4_HASH_MAX_DIGEST_LENGTH * 2U, signatureLen );
TEST_ASSERT_EQUAL_MEMORY( pExpectedSignature, signature, signatureLen );

params.pHttpParameters->pQuery = QUERY_STRING_WITH_REPEATED_AMPERSANT;
params.pHttpParameters->queryLen = strlen( QUERY_STRING_WITH_REPEATED_AMPERSANT );
params.pHttpParameters->pQuery = QUERY_STRING_WITH_REPEATED_AMPERSAND;
params.pHttpParameters->queryLen = strlen( QUERY_STRING_WITH_REPEATED_AMPERSAND );

pExpectedSignature = "4fcf6c89d5ddb944c0e386817d52835f578769e100d7e92d433bf4a946b7e6c3";
TEST_ASSERT_EQUAL( SigV4Success, SigV4_GenerateHTTPAuthorization(
Expand Down

0 comments on commit aeabd54

Please sign in to comment.