WA-SDK  3.0.4.0
WA-SDK
issacapi/se/sample_se_gcm.c
#include <stdio.h>
#include "issacapi_bs.h"
#include "issacapi_se.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 char *authdata = "This is a authentication message";
static int authdataSize = 32; // strlen("This is a authentication message");
static const unsigned char symm_key[] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10
};
static const unsigned char iv[] = {
0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8
};
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_se_gcm() {
ISSAC_RETURN result;
unsigned char encrypted[32] = { 0, };
int encryptedSize = 0;
int tagSize = 4;
printf("sample_se_gcm() => ");
// encrypt
{
SECONTEXT encipher;
result = ISSAC_SECONTEXT_Set(&encipher, symm_key, sizeof(symm_key), NULL, 0, ISSACAPI_SE_GCM_MODE, ISSACAPI_SEED);
if (result == ISSAC_SUCCESS) {
result = ISSAC_SE_Encrypt_Auth(encrypted, &encryptedSize, sizeof(encrypted), (void *) plaintext, plaintextSize,
(void *) authdata, authdataSize, (void *) iv, sizeof(iv), tagSize, &encipher);
}
}
// decrypt
if (result == ISSAC_SUCCESS) {
SECONTEXT decipher;
unsigned char decrypted[32] = { 0, };
int decryptedSize = 0;
result = ISSAC_SECONTEXT_Set(&decipher, symm_key, sizeof(symm_key), NULL, 0, ISSACAPI_SE_GCM_MODE, ISSACAPI_SEED);
if (result == ISSAC_SUCCESS) {
result = ISSAC_SE_Decrypt_Auth(decrypted, &decryptedSize, sizeof(decrypted), (void *) encrypted, encryptedSize,
(void *) authdata, authdataSize, (void *) iv, sizeof(iv), tagSize, &decipher);
}
}
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_se_gcm();
}
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
@ ISSACAPI_SEED
(2) SEED
Definition: issacapi_bs_definitions.h:53
@ ISSAC_SUCCESS
(0) 성공
Definition: issacapi_bs_definitions.h:37
WA_SDK_API const char *FUNCCALL ISSAC_GetErrorMessage(ISSAC_RETURN errorCode)
ISSAC-API 의 에러코드에 대한 에러메시지를 가져온다.
WA_SDK_API ISSAC_RETURN FUNCCALL ISSAC_SE_Decrypt_Auth(void *plaintext, int *plaintext_len, int plaintext_alloc_len, void *ciphertext, int ciphertext_len, void *authdata, int authdata_len, void *iv, int iv_len, int tag_len, SECONTEXT *secontext)
입력한 암호문을 CCM/GCM 방식으로 복호화한다.
WA_SDK_API ISSAC_RETURN FUNCCALL ISSAC_SECONTEXT_Create(SECONTEXT *secontext)
SECONTEXT 구조체를 초기화한다.
WA_SDK_API ISSAC_RETURN FUNCCALL ISSAC_SECONTEXT_Delete(SECONTEXT *secontext)
SECONTEXT 에 할당된 메모리를 해제한다.
WA_SDK_API ISSAC_RETURN FUNCCALL ISSAC_SECONTEXT_Set(SECONTEXT *secontext, const void *key, int key_len, const void *iv, int iv_len, int mode, int cipher_id)
SECONTEXT 에 암호화를 위한 정보들을 입력한다.
WA_SDK_API ISSAC_RETURN FUNCCALL ISSAC_SE_Encrypt_Auth(void *ciphertext, int *ciphertext_len, int ciphertext_alloc_len, void *plaintext, int plaintext_len, void *authdata, int authdata_len, void *iv, int iv_len, int tag_len, SECONTEXT *secontext)
입력한 원문을 CCM/GCM 방식으로 암호화한다.
@ ISSACAPI_SE_GCM_MODE
Galois/Counter Mode of Operation
Definition: issacapi_se.h:40
WA_SDK_API const char *FUNCCALL wasdk_error_message(EErrorCode errorCode)
에러코드에 해당하는 에러 메시지를 가져온다.
WA_SDK_API EErrorCode FUNCCALL wasdk_init(void)
모듈 초기화를 실행한다.
대칭키 암호화 컨텍스트
Definition: issacapi_se.h:45