SKF Wrapper

This commit is contained in:
Zhi Guan
2016-05-29 00:22:33 +02:00
parent 0cf9126a7d
commit ee4384daeb
142 changed files with 9469 additions and 6750 deletions

81
crypto/sm1/Makefile Normal file
View File

@@ -0,0 +1,81 @@
#
# OpenSSL/crypto/sm1/Makefile
#
DIR= sm1
TOP= ../..
CC= cc
CPP= $(CC) -E
INCLUDES=-I.. -I$(TOP) -I../../include
CFLAG=-g
MAKEFILE= Makefile
AR= ar r
SM3_ASM_OBJ=
CFLAGS= $(INCLUDES) $(CFLAG)
ASFLAGS= $(INCLUDES) $(ASFLAG)
AFLAGS= $(ASFLAGS)
GENERAL=Makefile
TEST=
APPS=
LIB=$(TOP)/libcrypto.a
LIBSRC=
LIBOBJ=
SRC= $(LIBSRC)
EXHEADER= sm1.h
HEADER= $(EXHEADER)
ALL= $(GENERAL) $(SRC) $(HEADER)
top:
(cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
all: lib
lib: $(LIBOBJ)
$(AR) $(LIB) $(LIBOBJ)
$(RANLIB) $(LIB) || echo Never mind.
@touch lib
files:
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
links:
@$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
@$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
@$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
install:
@[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
@headerlist="$(EXHEADER)"; for i in $$headerlist ; \
do \
(cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
done;
tags:
ctags $(SRC)
tests:
lint:
lint -DLINT $(INCLUDES) $(SRC)>fluff
depend:
@[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
dclean:
$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
mv -f Makefile.new $(MAKEFILE)
clean:
rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
# DO NOT DELETE THIS LINE -- make depend depends on it.

View File

@@ -54,6 +54,7 @@
#define SM1_KEY_LENGTH 16
#define SM1_BLOCK_SIZE 16
#define SM1_IV_LENGTH (SM1_BLOCK_SIZE)
#ifdef __cplusplus
extern "C" {

View File

@@ -1,54 +0,0 @@
#include <stdio.h>
#include <openssl/evp.h>
#include <openssl/engine.h>
#include <openssl/assert.h>
int main(int argc, char **argv)
{
const char *engine_id = "SKF";
ENGINE *engine = NULL;
const EVP_CIPHER *cipher;
EVP_CIPHER_CTX ctx;
unsigned char key[16];
unsigned char iv[16];
const char *msg1 = "hello world";
const char *msg2 = "12345678";
unsigned char buf[128];
int len;
ENGINE_load_builtin_engines();
engine = ENGINE_by_id(engine_id);
OPENSSL_assert(engine != NULL);
rv = ENGINE_init(engine);
OPENSSL_assert(rv == 1);
cipher = ENGINE_get_cipher(engine, NID_sm1_cbc);
EVP_CIPHER_CTX_init(&ctx);
rv = RAND_bytes(key, (int)sizeof(key));
rv = RAND_bytes(iv, (int)sizeof(iv));
rv = EVP_EncryptInit_ex(&ctx, cipher, engine, key, iv);
p = buf;
rv = EVP_EncryptUpdate(&ctx, p, &len, (unsigned char *)msg1, (int)strlen(msg1));
p += len;
rv = EVP_EncryptUpdate(&ctx, p, &len, (unsigned char *)msg2, (int)strlen(msg2));
p += len;
rv = EVP_EncryptFinal_ex(&ctx, p, &len);
p += len;
EVP_CIPHER_CTX_cleanup(&ctx);
ENGINE_finish(engine);
ENGINE_free(engine);
return 0;
}