~ubuntu-branches/ubuntu/wily/edk2/wily

« back to all changes in this revision

Viewing changes to CryptoPkg/Application/Cryptest/HmacVerify.c

  • Committer: Package Import Robot
  • Author(s): Steve Langasek
  • Date: 2013-02-10 13:11:25 UTC
  • Revision ID: package-import@ubuntu.com-20130210131125-0zwkb8f8m4ecia4m
Tags: upstream-0~20121205.edae8d2d
ImportĀ upstreamĀ versionĀ 0~20121205.edae8d2d

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file  
 
2
  Application for HMAC Primitives Validation.
 
3
 
 
4
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
 
5
This program and the accompanying materials
 
6
are licensed and made available under the terms and conditions of the BSD License
 
7
which accompanies this distribution.  The full text of the license may be found at
 
8
http://opensource.org/licenses/bsd-license.php
 
9
 
 
10
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 
11
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
12
 
 
13
**/
 
14
 
 
15
#include "Cryptest.h"
 
16
 
 
17
//
 
18
// Max Known Digest Size is SHA512 Output (64 bytes) by far
 
19
//
 
20
#define MAX_DIGEST_SIZE    64
 
21
 
 
22
//
 
23
// Data string for HMAC validation
 
24
//
 
25
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *HmacData = "Hi There";
 
26
 
 
27
//
 
28
// Key value for HMAC-MD5 validation. (From "2. Test Cases for HMAC-MD5" of IETF RFC2202)
 
29
//
 
30
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacMd5Key[16] = {
 
31
  0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b
 
32
  };
 
33
 
 
34
//
 
35
// Result for HMAC-MD5("Hi There"). (From "2. Test Cases for HMAC-MD5" of IETF RFC2202)
 
36
//
 
37
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacMd5Digest[] = {
 
38
  0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c, 0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d
 
39
  };
 
40
 
 
41
//
 
42
// Key value for HMAC-SHA-1 validation. (From "3. Test Cases for HMAC-SHA-1" of IETF RFC2202)
 
43
//
 
44
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacSha1Key[20] = {
 
45
  0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
 
46
  0x0b, 0x0b, 0x0b, 0x0b
 
47
  };
 
48
 
 
49
//
 
50
// Result for HMAC-SHA-1 ("Hi There"). (From "3. Test Cases for HMAC-SHA-1" of IETF RFC2202)
 
51
//
 
52
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacSha1Digest[] = {
 
53
  0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64, 0xe2, 0x8b, 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e,
 
54
  0xf1, 0x46, 0xbe, 0x00
 
55
  };
 
56
 
 
57
/**
 
58
  Validate UEFI-OpenSSL Message Authentication Codes Interfaces.
 
59
 
 
60
  @retval  EFI_SUCCESS  Validation succeeded.
 
61
  @retval  EFI_ABORTED  Validation failed.
 
62
 
 
63
**/
 
64
EFI_STATUS
 
65
ValidateCryptHmac (
 
66
  VOID
 
67
  )
 
68
{
 
69
  UINTN    CtxSize;
 
70
  VOID     *HmacCtx;
 
71
  UINT8    Digest[MAX_DIGEST_SIZE];
 
72
  BOOLEAN  Status;
 
73
 
 
74
  Print (L" \nUEFI-OpenSSL HMAC Engine Testing:\n");
 
75
 
 
76
  Print (L"- HMAC-MD5:  ");
 
77
 
 
78
  //
 
79
  // HMAC-MD5 Digest Validation
 
80
  //
 
81
  ZeroMem (Digest, MAX_DIGEST_SIZE);
 
82
  CtxSize = HmacMd5GetContextSize ();
 
83
  HmacCtx = AllocatePool (CtxSize);
 
84
 
 
85
  Print (L"Init... ");
 
86
  Status  = HmacMd5Init (HmacCtx, HmacMd5Key, sizeof (HmacMd5Key));
 
87
  if (!Status) {
 
88
    Print (L"[Fail]");
 
89
    return EFI_ABORTED;
 
90
  }
 
91
 
 
92
  Print (L"Update... ");
 
93
  Status  = HmacMd5Update (HmacCtx, HmacData, 8);
 
94
  if (!Status) {
 
95
    Print (L"[Fail]");
 
96
    return EFI_ABORTED;
 
97
  }
 
98
 
 
99
  Print (L"Finalize... ");
 
100
  Status  = HmacMd5Final (HmacCtx, Digest);
 
101
  if (!Status) {
 
102
    Print (L"[Fail]");
 
103
    return EFI_ABORTED;
 
104
  }
 
105
 
 
106
  FreePool (HmacCtx);
 
107
 
 
108
  Print (L"Check Value... ");
 
109
  if (CompareMem (Digest, HmacMd5Digest, MD5_DIGEST_SIZE) != 0) {
 
110
    Print (L"[Fail]");
 
111
    return EFI_ABORTED;
 
112
  }
 
113
 
 
114
  Print (L"[Pass]\n");
 
115
 
 
116
  Print (L"- HMAC-SHA1: ");
 
117
 
 
118
  //
 
119
  // HMAC-SHA1 Digest Validation
 
120
  //
 
121
  ZeroMem (Digest, MAX_DIGEST_SIZE);
 
122
  CtxSize = HmacSha1GetContextSize ();
 
123
  HmacCtx = AllocatePool (CtxSize);
 
124
 
 
125
  Print (L"Init... ");
 
126
  Status  = HmacSha1Init (HmacCtx, HmacSha1Key, sizeof (HmacSha1Key));
 
127
  if (!Status) {
 
128
    Print (L"[Fail]");
 
129
    return EFI_ABORTED;
 
130
  }
 
131
 
 
132
  Print (L"Update... ");
 
133
  Status  = HmacSha1Update (HmacCtx, HmacData, 8);
 
134
  if (!Status) {
 
135
    Print (L"[Fail]");
 
136
    return EFI_ABORTED;
 
137
  }
 
138
 
 
139
  Print (L"Finalize... ");
 
140
  Status  = HmacSha1Final (HmacCtx, Digest);
 
141
  if (!Status) {
 
142
    Print (L"[Fail]");
 
143
    return EFI_ABORTED;
 
144
  }
 
145
 
 
146
  FreePool (HmacCtx);
 
147
 
 
148
  Print (L"Check Value... ");
 
149
  if (CompareMem (Digest, HmacSha1Digest, SHA1_DIGEST_SIZE) != 0) {
 
150
    Print (L"[Fail]");
 
151
    return EFI_ABORTED;
 
152
  }
 
153
 
 
154
  Print (L"[Pass]\n");
 
155
 
 
156
  return EFI_SUCCESS;
 
157
}