#include <time.h>
#include "aes128.h"
#include "driver.h"
#include "md5.h"
#include "aes_cmac.h"
void drv_reset(int mask)
{
// dummy
}
static int BCD(int d)
{
return d+(int)(d/10)*6;
}
void convert(int year, int month, int date, int dow, int hour, int minutes, int sec, uint8 *p)
{
*p++ = BCD(year/100);
*p++ = BCD(year%100);
*p++ = BCD(month);
*p++ = BCD(date);
*p++ = BCD(dow);
*p++ = BCD(hour);
*p++ = BCD(minutes);
*p = BCD(sec);
}
uint8 *drv_rtc_get_bin()
{
struct tm *tm;
time_t t;
static uint8 buf[8];
// for software use POSIX stdlib
time(&t);
tm = localtime(&t);
convert(tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday,
tm->tm_hour, tm->tm_min, tm->tm_sec, buf);
return buf;
}
void drv_AES_crypt(uint *msg, uint8 *key)
{
AES128_crypt(msg, key);
}
void drv_AES_decrypt(uint *msg, uint8 *key)
{
AES128_decrypt(msg, key);
}
static md5_context ctx;
static unsigned char md5sum[16];
uint8 *drv_MD5(int n, uint8 *msg, uint8 *key)
{
md5_starts(&ctx);
md5_update(&ctx, msg, n);
md5_finish(&ctx, md5sum);
return md5sum;
}
ODAT *drv_AES_cmac(KEY128 *K, u128 *M, int n)
{
return (ODAT*)AES_cmac((uint8 *)K, (uint *)M, n);
}
/* vi:expandtab:foldmethod=syntax:sw=2:ts=2 */