WA-SDK  3.0.4.0
WA-SDK
issacapi/hmac/sample_hmac_basic.c
#include <stdio.h>
#include "issacapi_hmac.h"
static const unsigned char *plaintext = (const unsigned char *) "This is a test text";
static int plaintextSize = 19; // strlen("This is a test text");
static const unsigned char secretKey[] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30
};
static int sample_setup() {
EErrorCode result = wasdk_init();
if (result != EEC_Success) {
printf("[ERROR] %s\n", wasdk_error_message(result));
return 1;
}
return 0;
}
int sample_hmac_basic() {
ISSAC_RETURN result;
HMAC_CONTEXT context;
unsigned char hmac[MAX_HASH_SIZE] = { 0, };
int hmacLen = 0;
printf("sample_hmac_basic() => ");
// 비밀키와 해시 알고리즘 설정
// - sizeof(secretKey)가 입력한 해시 알고리즘의 출력크기보다 커야한다. (API 문서 참고)
result = ISSAC_HMAC_Initialize(&context, secretKey, sizeof(secretKey), ISSACAPI_SHA256);
// 원문 메시지 추가
if (result == ISSAC_SUCCESS) {
result = ISSAC_HMAC_Update(&context, plaintext, plaintextSize);
}
// HMAC 출력값 가져오기
if (result == ISSAC_SUCCESS) {
result = ISSAC_HMAC_Finalize(hmac, &hmacLen, sizeof(hmac), &context);
}
if (result == ISSAC_SUCCESS) {
printf("[OK]\n");
return 0;
} else {
printf("[ERROR] %s\n", ISSAC_GetErrorMessage(result));
return 1;
}
}
int main() {
int result;
result = sample_setup();
if (result != 0) {
return result;
}
return sample_hmac_basic();
}
EErrorCode
새롭게 구현된 내부 API 에서 사용되는 에러코드들
Definition: wasdk_errorcode.h:13
@ EEC_Success
성공
Definition: wasdk_errorcode.h:14
unsigned int ISSAC_RETURN
ISSAC-API 실행 결과 [ ISSACAPI_BASIC_RETURN, ISSACAPI_ERRORS, ISSAC_LICENSE_ERR ]
Definition: issacapi_bs_definitions.h:32
@ ISSAC_SUCCESS
(0) 성공
Definition: issacapi_bs_definitions.h:37
@ ISSACAPI_SHA256
(6) SHA256
Definition: issacapi_bs_definitions.h:89
WA_SDK_API const char *FUNCCALL ISSAC_GetErrorMessage(ISSAC_RETURN errorCode)
ISSAC-API 의 에러코드에 대한 에러메시지를 가져온다.
WA_SDK_API ISSAC_RETURN FUNCCALL ISSAC_HMAC_CONTEXT_Delete(HMAC_CONTEXT *context)
HMAC_CONTEXT 에 할당된 메모리를 해제한다.
WA_SDK_API ISSAC_RETURN FUNCCALL ISSAC_HMAC_Finalize(void *hmac, int *hmacLen, int hmacAllocLen, HMAC_CONTEXT *context)
HMAC 을 생성한다.
WA_SDK_API ISSAC_RETURN FUNCCALL ISSAC_HMAC_Initialize(HMAC_CONTEXT *context, const void *key, int keyLen, int hashAlg)
HMAC 생성에 사용할 비밀키와 해시 알고리즘을 설정한다.
WA_SDK_API ISSAC_RETURN FUNCCALL ISSAC_HMAC_CONTEXT_Create(HMAC_CONTEXT *context)
HMAC_CONTEXT 구조체를 초기화한다.
WA_SDK_API ISSAC_RETURN FUNCCALL ISSAC_HMAC_Update(HMAC_CONTEXT *context, const void *message, int messageLen)
HMAC 생성에 사용할 원문 메시지를 업데이트한다.
WA_SDK_API const char *FUNCCALL wasdk_error_message(EErrorCode errorCode)
에러코드에 해당하는 에러 메시지를 가져온다.
WA_SDK_API EErrorCode FUNCCALL wasdk_init(void)
모듈 초기화를 실행한다.
#define MAX_HASH_SIZE
512 bit (SHA 512)
Definition: wasdk_public.h:40
HMAC (Hashed MAC) 컨텍스트
Definition: issacapi_hmac.h:25