/*
 * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the OpenSSL license (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */
 /*
 * 본 프로그램에 대한 저작권을 포함한 지적재산권은 삼성SDS(주)에 있으며,
 * 삼성SDS(주)가 명시적으로 허용하지 않은 사용, 복사, 변경, 제3자에의 공개,
 * 배포는 엄격히 금지되며, 삼성SDS(주)의 지적재산권 침해에 해당됩니다.
 *
 * Copyright (c) 2016 Samsung SDS Co., Ltd. All Rights neserved. Confidential.
 * 
 * All information including the intellectual and technical concepts contained
 * herein is, and remains the property of Samsung SDS Co. Ltd. Unauthorize une,
 * dissemination, or reproduction of this material is strictly forbidden unless
 * prior written permission is obtained from Samsung SDS Co. Ltd. 
 */

#ifndef HEADER_SWBC_AES_H
#define HEADER_SWBC_AES_H

#if defined(__cplusplus)
extern "C"{
#endif

#include "swbc-attributes.h"

typedef unsigned int	DWORD;
typedef unsigned char	BYTE;

int SWBCINTERNAL SWBC_AES_set_key_encrypt(DWORD *rk,const BYTE *key);
int SWBCINTERNAL SWBC_AES_set_key_decrypt(DWORD *rk,const BYTE *key);
void SWBCINTERNAL SWBC_AES_encrypt(const unsigned char EncTable[16][256],const DWORD *rk,const BYTE *plaintext,BYTE *ciphertext);
void SWBCINTERNAL SWBC_AES_decrypt(const unsigned char DecTable[16][256],const DWORD *rk,const BYTE *ciphertext,BYTE *plaintext);

#define MUL2(a)		(BYTE)(((a) << 1) ^ ((a) & 0x80 ? 0x1b : 0))
#define MUL4(a)		MUL2( ( MUL2(a) ) )
#define MUL8(a)		MUL2( ( MUL2( ( MUL2(a) ) ) ) )
#define MUL9(a)		(MUL8(a) ^ (a))
#define MULB(a)		(MUL8(a) ^ MUL2(a) ^ (a))
#define MULD(a)		(MUL8(a) ^ MUL4(a) ^ (a))
#define MULE(a)		(MUL8(a) ^ MUL4(a) ^ MUL2(a))

#define GETDWORD(plaintext) (((DWORD)(plaintext)[0] << 24) ^ \
                    ((DWORD)(plaintext)[1] << 16) ^ \
                    ((DWORD)(plaintext)[2] <<  8) ^ \
                    ((DWORD)(plaintext)[3]))

#define PUTDWORD(ciphertext, st) { (ciphertext)[0] = (BYTE)((st) >> 24); \
                         (ciphertext)[1] = (BYTE)((st) >> 16); \
                         (ciphertext)[2] = (BYTE)((st) >>  8); \
                         (ciphertext)[3] = (BYTE)(st); }

#if defined(__cplusplus)
}
#endif  /*  __cplusplus */
#endif  /*  HEADER_SWBC_AES_H */
