Commit e7a51184 authored by filatov's avatar filatov
Browse files

fix eol styles

parent 680a1960
......@@ -13,6 +13,7 @@ bins = asn1certgen
sources := asn1certgen.c ecc_openssl.c
sources-WIN32 := applink.c
packages += cshared openssl
includes += ../../../bin/asn1
libs += ../../../bin/asn1/libItsAsn.so
includes += asncodec
itsLib := asncodec/libSecItsAsn.a
libs += $(itsLib)
include ../common.mk
#define _CRT_SECURE_NO_WARNINGS
#define APPLINK_STDIN 1
#define APPLINK_STDOUT 2
#define APPLINK_STDERR 3
#define APPLINK_FPRINTF 4
#define APPLINK_FGETS 5
#define APPLINK_FREAD 6
#define APPLINK_FWRITE 7
#define APPLINK_FSETMOD 8
#define APPLINK_FEOF 9
#define APPLINK_FCLOSE 10 /* should not be used */
#define APPLINK_FOPEN 11 /* solely for completeness */
#define APPLINK_FSEEK 12
#define APPLINK_FTELL 13
#define APPLINK_FFLUSH 14
#define APPLINK_FERROR 15
#define APPLINK_CLEARERR 16
#define APPLINK_FILENO 17 /* to be used with below */
#define APPLINK_OPEN 18 /* formally can't be used, as flags can vary */
#define APPLINK_READ 19
#define APPLINK_WRITE 20
#define APPLINK_LSEEK 21
#define APPLINK_CLOSE 22
#define APPLINK_MAX 22 /* always same as last macro */
#ifndef APPMACROS_ONLY
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
static void *app_stdin(void) { return stdin; }
static void *app_stdout(void) { return stdout; }
static void *app_stderr(void) { return stderr; }
static int app_feof(FILE *fp) { return feof(fp); }
static int app_ferror(FILE *fp) { return ferror(fp); }
static void app_clearerr(FILE *fp) { clearerr(fp); }
static int app_fileno(FILE *fp) { return _fileno(fp); }
static int app_fsetmod(FILE *fp,char mod)
{ return _setmode (_fileno(fp),mod=='b'?_O_BINARY:_O_TEXT); }
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport)
void **
#if defined(__BORLANDC__)
__stdcall /* __stdcall appears to be the only way to get the name
* decoration right with Borland C. Otherwise it works
* purely incidentally, as we pass no parameters. */
#else
__cdecl
#endif
OPENSSL_Applink(void)
{ static int once=1;
static void *OPENSSL_ApplinkTable[APPLINK_MAX+1]={(void *)APPLINK_MAX};
if (once)
{ OPENSSL_ApplinkTable[APPLINK_STDIN] = app_stdin;
OPENSSL_ApplinkTable[APPLINK_STDOUT] = app_stdout;
OPENSSL_ApplinkTable[APPLINK_STDERR] = app_stderr;
OPENSSL_ApplinkTable[APPLINK_FPRINTF] = fprintf;
OPENSSL_ApplinkTable[APPLINK_FGETS] = fgets;
OPENSSL_ApplinkTable[APPLINK_FREAD] = fread;
OPENSSL_ApplinkTable[APPLINK_FWRITE] = fwrite;
OPENSSL_ApplinkTable[APPLINK_FSETMOD] = app_fsetmod;
OPENSSL_ApplinkTable[APPLINK_FEOF] = app_feof;
OPENSSL_ApplinkTable[APPLINK_FCLOSE] = fclose;
OPENSSL_ApplinkTable[APPLINK_FOPEN] = fopen;
OPENSSL_ApplinkTable[APPLINK_FSEEK] = fseek;
OPENSSL_ApplinkTable[APPLINK_FTELL] = ftell;
OPENSSL_ApplinkTable[APPLINK_FFLUSH] = fflush;
OPENSSL_ApplinkTable[APPLINK_FERROR] = app_ferror;
OPENSSL_ApplinkTable[APPLINK_CLEARERR] = app_clearerr;
OPENSSL_ApplinkTable[APPLINK_FILENO] = app_fileno;
OPENSSL_ApplinkTable[APPLINK_OPEN] = _open;
OPENSSL_ApplinkTable[APPLINK_READ] = _read;
OPENSSL_ApplinkTable[APPLINK_WRITE] = _write;
OPENSSL_ApplinkTable[APPLINK_LSEEK] = _lseek;
OPENSSL_ApplinkTable[APPLINK_CLOSE] = _close;
once = 0;
}
return OPENSSL_ApplinkTable;
}
#ifdef __cplusplus
}
#endif
#endif
#define _CRT_SECURE_NO_WARNINGS
#define APPLINK_STDIN 1
#define APPLINK_STDOUT 2
#define APPLINK_STDERR 3
#define APPLINK_FPRINTF 4
#define APPLINK_FGETS 5
#define APPLINK_FREAD 6
#define APPLINK_FWRITE 7
#define APPLINK_FSETMOD 8
#define APPLINK_FEOF 9
#define APPLINK_FCLOSE 10 /* should not be used */
#define APPLINK_FOPEN 11 /* solely for completeness */
#define APPLINK_FSEEK 12
#define APPLINK_FTELL 13
#define APPLINK_FFLUSH 14
#define APPLINK_FERROR 15
#define APPLINK_CLEARERR 16
#define APPLINK_FILENO 17 /* to be used with below */
#define APPLINK_OPEN 18 /* formally can't be used, as flags can vary */
#define APPLINK_READ 19
#define APPLINK_WRITE 20
#define APPLINK_LSEEK 21
#define APPLINK_CLOSE 22
#define APPLINK_MAX 22 /* always same as last macro */
#ifndef APPMACROS_ONLY
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
static void *app_stdin(void) { return stdin; }
static void *app_stdout(void) { return stdout; }
static void *app_stderr(void) { return stderr; }
static int app_feof(FILE *fp) { return feof(fp); }
static int app_ferror(FILE *fp) { return ferror(fp); }
static void app_clearerr(FILE *fp) { clearerr(fp); }
static int app_fileno(FILE *fp) { return _fileno(fp); }
static int app_fsetmod(FILE *fp,char mod)
{ return _setmode (_fileno(fp),mod=='b'?_O_BINARY:_O_TEXT); }
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport)
void **
#if defined(__BORLANDC__)
__stdcall /* __stdcall appears to be the only way to get the name
* decoration right with Borland C. Otherwise it works
* purely incidentally, as we pass no parameters. */
#else
__cdecl
#endif
OPENSSL_Applink(void)
{ static int once=1;
static void *OPENSSL_ApplinkTable[APPLINK_MAX+1]={(void *)APPLINK_MAX};
if (once)
{ OPENSSL_ApplinkTable[APPLINK_STDIN] = app_stdin;
OPENSSL_ApplinkTable[APPLINK_STDOUT] = app_stdout;
OPENSSL_ApplinkTable[APPLINK_STDERR] = app_stderr;
OPENSSL_ApplinkTable[APPLINK_FPRINTF] = fprintf;
OPENSSL_ApplinkTable[APPLINK_FGETS] = fgets;
OPENSSL_ApplinkTable[APPLINK_FREAD] = fread;
OPENSSL_ApplinkTable[APPLINK_FWRITE] = fwrite;
OPENSSL_ApplinkTable[APPLINK_FSETMOD] = app_fsetmod;
OPENSSL_ApplinkTable[APPLINK_FEOF] = app_feof;
OPENSSL_ApplinkTable[APPLINK_FCLOSE] = fclose;
OPENSSL_ApplinkTable[APPLINK_FOPEN] = fopen;
OPENSSL_ApplinkTable[APPLINK_FSEEK] = fseek;
OPENSSL_ApplinkTable[APPLINK_FTELL] = ftell;
OPENSSL_ApplinkTable[APPLINK_FFLUSH] = fflush;
OPENSSL_ApplinkTable[APPLINK_FERROR] = app_ferror;
OPENSSL_ApplinkTable[APPLINK_CLEARERR] = app_clearerr;
OPENSSL_ApplinkTable[APPLINK_FILENO] = app_fileno;
OPENSSL_ApplinkTable[APPLINK_OPEN] = _open;
OPENSSL_ApplinkTable[APPLINK_READ] = _read;
OPENSSL_ApplinkTable[APPLINK_WRITE] = _write;
OPENSSL_ApplinkTable[APPLINK_LSEEK] = _lseek;
OPENSSL_ApplinkTable[APPLINK_CLOSE] = _close;
once = 0;
}
return OPENSSL_ApplinkTable;
}
#ifdef __cplusplus
}
#endif
#endif
This diff is collapsed.
/*********************************************************************
######################################################################
##
## Created by: Denis Filatov
##
## Copyleft (c) 2015
## This code is provided under the CeCill-C license agreement.
######################################################################
*********************************************************************/
#ifndef ecc_api_h
#define ecc_api_h
#ifdef __cplusplus
extern "C" {
#endif
int ecc_api_init();
int ecc_api_done();
typedef enum {
ecies_nistp256,
ecies_brainpoolp256r,
ecies_brainpoolp384r,
}ecc_curve_id;
typedef enum {
sha_256,
sha_384
}ecc_hash_id;
typedef enum {
aes_128_ccm
}ecc_sym_algorithm;
typedef enum {
ecc_bin,
ecc_hex,
ecc_pem
}ecc_format;
typedef enum {
ecc_x_only = 0,
ecc_compressed_y0 = 2,
ecc_compressed_y1 = 3,
ecc_uncompressed = 4
}ecc_point_type;
void * ecc_key_gen(ecc_curve_id pk_alg);
void * ecc_key_init(ecc_curve_id pk_alg, const char* pkey);
void ecc_key_free(void*);
int ecc_key_private(void*, char* buf);
int ecc_key_public(void*, char* x, char* y, int * psign);
int ecc_key_private_save(void*, const char* path, ecc_format format);
void * ecc_key_private_load(const char* path, ecc_curve_id pk_alg);
int ecc_key_public_save(void*, const char* path, ecc_format format);
void * ecc_key_public_load(const char* path, ecc_curve_id pk_alg);
void * ecc_key_public_set(ecc_curve_id pk_alg, ecc_point_type ptype, const char * px, const char * py);
#define sha256_hash_size 32
#define sha384_hash_size 48
int sha256_calculate(char* hash, const char * ptr, int len);
int sha384_calculate(char* hash, const char * ptr, int len);
int ecc_sign(void * key, const char * hash, int hlength, char *r, char *s);
#ifdef __cplusplus
}
#endif
#endif
/*********************************************************************
######################################################################
##
## Created by: Denis Filatov
##
## Copyleft (c) 2015
## This code is provided under the CeCill-C license agreement.
######################################################################
*********************************************************************/
#ifndef ecc_api_h
#define ecc_api_h
#ifdef __cplusplus
extern "C" {
#endif
int ecc_api_init();
int ecc_api_done();
typedef enum {
ecies_nistp256,
ecies_brainpoolp256r,
ecies_brainpoolp384r,
}ecc_curve_id;
typedef enum {
sha_256,
sha_384
}ecc_hash_id;
typedef enum {
aes_128_ccm
}ecc_sym_algorithm;
typedef enum {
ecc_bin,
ecc_hex,
ecc_pem
}ecc_format;
typedef enum {
ecc_x_only = 0,
ecc_compressed_y0 = 2,
ecc_compressed_y1 = 3,
ecc_uncompressed = 4
}ecc_point_type;
void * ecc_key_gen(ecc_curve_id pk_alg);
void * ecc_key_init(ecc_curve_id pk_alg, const char* pkey);
void ecc_key_free(void*);
int ecc_key_private(void*, char* buf);
int ecc_key_public(void*, char* x, char* y, int * psign);
int ecc_key_private_save(void*, const char* path, ecc_format format);
void * ecc_key_private_load(const char* path, ecc_curve_id pk_alg);
int ecc_key_public_save(void*, const char* path, ecc_format format);
void * ecc_key_public_load(const char* path, ecc_curve_id pk_alg);
void * ecc_key_public_set(ecc_curve_id pk_alg, ecc_point_type ptype, const char * px, const char * py);
#define sha256_hash_size 32
#define sha384_hash_size 48
int sha256_calculate(char* hash, const char * ptr, int len);
int sha384_calculate(char* hash, const char * ptr, int len);
int ecc_sign(void * key, const char * hash, int hlength, char *r, char *s);
#ifdef __cplusplus
}
#endif
#endif
This diff is collapsed.
// Found in DeSmuME
// Alexis modified it a tad bit so it would compile as C (opposed to C++)
/* lib/mkgmtime.c
Copyright (C) 2010 DeSmuME team
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
//Taken from newlib 1.18.0 which is licensed under GPL 2 and modified for desmume
/*
* mktime.c
* Original Author: G. Haley
*
* Converts the broken-down time, expressed as local time, in the structure
* pointed to by tim_p into a calendar time value. The original values of the
* tm_wday and tm_yday fields of the structure are ignored, and the original
* values of the other fields have no restrictions. On successful completion
* the fields of the structure are set to represent the specified calendar
* time. Returns the specified calendar time. If the calendar time can not be
* represented, returns the value (time_t) -1.
*
* Modifications: Fixed tm_isdst usage - 27 August 2008 Craig Howland.
*/
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include "mkgmtime.h"
#define _SEC_IN_MINUTE 60L
#define _SEC_IN_HOUR 3600L
#define _SEC_IN_DAY 86400L
static const int DAYS_IN_MONTH[12] =
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
#define _DAYS_IN_MONTH(x) ((x == 1) ? days_in_feb : DAYS_IN_MONTH[x])
static const int _DAYS_BEFORE_MONTH[12] =
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
#define _ISLEAP(y) (((y) % 4) == 0 && (((y) % 100) != 0 || (((y)+1900) % 400) == 0))
#define _DAYS_IN_YEAR(year) (_ISLEAP(year) ? 366 : 365)
static void validate_structure(struct tm *tim_p)
{
div_t res;
int days_in_feb = 28;
/* calculate time & date to account for out of range values */
if (tim_p->tm_sec < 0 || tim_p->tm_sec > 59)
{
res = div (tim_p->tm_sec, 60);
tim_p->tm_min += res.quot;
if ((tim_p->tm_sec = res.rem) < 0)
{
tim_p->tm_sec += 60;
--tim_p->tm_min;
}
}
if (tim_p->tm_min < 0 || tim_p->tm_min > 59)
{
res = div (tim_p->tm_min, 60);
tim_p->tm_hour += res.quot;
if ((tim_p->tm_min = res.rem) < 0)
{
tim_p->tm_min += 60;
--tim_p->tm_hour;
}
}
if (tim_p->tm_hour < 0 || tim_p->tm_hour > 23)
{
res = div (tim_p->tm_hour, 24);
tim_p->tm_mday += res.quot;
if ((tim_p->tm_hour = res.rem) < 0)
{
tim_p->tm_hour += 24;
--tim_p->tm_mday;
}
}
if (tim_p->tm_mon > 11)
{
res = div (tim_p->tm_mon, 12);
tim_p->tm_year += res.quot;
if ((tim_p->tm_mon = res.rem) < 0)
{
tim_p->tm_mon += 12;
--tim_p->tm_year;
}
}
if (_DAYS_IN_YEAR (tim_p->tm_year) == 366)
days_in_feb = 29;
if (tim_p->tm_mday <= 0)
{
while (tim_p->tm_mday <= 0)
{
if (--tim_p->tm_mon == -1)
{
tim_p->tm_year--;
tim_p->tm_mon = 11;
days_in_feb =
((_DAYS_IN_YEAR (tim_p->tm_year) == 366) ?
29 : 28);
}
tim_p->tm_mday += _DAYS_IN_MONTH (tim_p->tm_mon);
}
}
else
{
while (tim_p->tm_mday > _DAYS_IN_MONTH (tim_p->tm_mon))
{
tim_p->tm_mday -= _DAYS_IN_MONTH (tim_p->tm_mon);
if (++tim_p->tm_mon == 12)
{
tim_p->tm_year++;
tim_p->tm_mon = 0;
days_in_feb =
((_DAYS_IN_YEAR (tim_p->tm_year) == 366) ?
29 : 28);
}
}
}
}
static const unsigned long _leap_moments[] = {
1136073600,
1230768000,
1341100800,
1435708800,
};
time_t addleapseconds(time_t t)
{
int i;
for (i = 0; i < sizeof(_leap_moments) / sizeof(_leap_moments[0]); i++){
if (t < _leap_moments[i]) break;
}
return t + i;
}
time_t removeleapseconds(time_t t)
{
int i;
for (i = 0; i < sizeof(_leap_moments) / sizeof(_leap_moments[0]); i++){
if (t < _leap_moments[i]) break;
t--;
}
return t;
}
#define ITS_UTC_EPOCH 1072915200
unsigned long mkitstime32(struct tm *tim_p)
{
time_t ret = mktaitime(tim_p);
if (ret > 0){
ret -= ITS_UTC_EPOCH;
}
return (unsigned long)ret;
}
unsigned long long mkitstime64(struct tm *tim_p)
{
unsigned long long ret = mktaitime64(tim_p);
if (ret > 0){
ret -= ((unsigned long long)ITS_UTC_EPOCH) * 1000;
}
return ret;
}
time_t mktaitime(struct tm *tim_p)
{
time_t t = mkgmtime(tim_p);
if (t >= 0){
t = addleapseconds(t);
}
return t;
}
unsigned long long mktaitime64(struct tm *tim_p)
{
time_t t = mkgmtime(tim_p);
if (t >= 0){
t = addleapseconds(t);
}
return ((unsigned long long)t)*1000;
}
unsigned long unix2itstime32(time_t t)
{
return ((unsigned long) addleapseconds(t)) - ITS_UTC_EPOCH;
}
unsigned long long unix2itstime64(time_t t)
{
return (((unsigned long long) addleapseconds(t)) - ITS_UTC_EPOCH) * 1000;
}
static char _datebuf[8][16];
static int _datebufidx = 0;
const char * strgmtdate(time_t t)
{
struct tm * tm;
char * b = _datebuf[_datebufidx];
_datebufidx = (_datebufidx + 1) & 7;
tm = gmtime(&t);
sprintf(b, "%u-%02u-%02u", 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday);
return b;
}
const char * strtaidate(time_t t)
{
return strgmtdate(removeleapseconds(t));
}
const char * stritsdate32(time_t t)
{
return strtaidate(t + ITS_UTC_EPOCH);
}
time_t mkgmtime(struct tm *tim_p)
{
time_t tim = 0;
long days = 0;
int year, isdst, tm_isdst;
/* validate structure */
validate_structure (tim_p);
/* compute hours, minutes, seconds */
tim += tim_p->tm_sec + (tim_p->tm_min * _SEC_IN_MINUTE) +