sm: move SM common crypto procedures to the dedicated library

rename 'sm' source directory
This commit is contained in:
Viktor Tarasov 2013-01-04 21:08:42 +01:00
parent 250364c060
commit 3f30e14087
17 changed files with 91 additions and 27 deletions

View File

@ -613,13 +613,14 @@ AC_CONFIG_FILES([
src/common/Makefile
src/libopensc/Makefile
src/libopensc/libopensc.pc
src/libsm/Makefile
src/pkcs11/Makefile
src/pkcs15init/Makefile
src/scconf/Makefile
src/tests/Makefile
src/tests/regression/Makefile
src/tools/Makefile
src/sm/Makefile
src/smm/Makefile
src/minidriver/Makefile
src/minidriver/opensc-minidriver.inf
win32/Makefile

View File

@ -2,10 +2,10 @@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
EXTRA_DIST = Makefile.mak
# Order IS important
SUBDIRS = common scconf pkcs15init libopensc pkcs11 \
SUBDIRS = common scconf libsm pkcs15init libopensc pkcs11 \
tools tests minidriver
if ENABLE_SM
SUBDIRS += sm
SUBDIRS += smm
endif

View File

@ -2,14 +2,14 @@ TOPDIR = ..
!INCLUDE $(TOPDIR)\win32\Make.rules.mak
SUBDIRS = common scconf pkcs15init libopensc pkcs11 tools tests
SUBDIRS = common scconf libsm pkcs15init libopensc pkcs11 tools tests
!IF "$(MINIDRIVER_DEF)" == "/DENABLE_MINIDRIVER"
SUBDIRS = $(SUBDIRS) minidriver
!ENDIF
!IF "$(SM_DEF)" == "/DENABLE_SM"
SUBDIRS = $(SUBDIRS) sm
SUBDIRS = $(SUBDIRS) smm
!ENDIF
all::

12
src/libsm/Makefile.am Normal file
View File

@ -0,0 +1,12 @@
# Process this file with automake to create Makefile.in
MAINTAINERCLEANFILES = Makefile.in
EXTRA_DIST = Makefile.mak
noinst_LTLIBRARIES = libsm.la
noinst_HEADERS = sm-common.h
AM_CFLAGS = $(OPTIONAL_OPENSSL_CFLAGS) $(OPTIONAL_READLINE_CFLAGS)
AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src/include
libsm_la_SOURCES = sm-common.c sm-common.h

11
src/libsm/Makefile.mak Normal file
View File

@ -0,0 +1,11 @@
TOPDIR = ..\..
TARGET = libsm.lib
OBJECTS = sm-common.obj
all: $(TARGET)
$(TARGET): $(OBJECTS)
lib $(LIBFLAGS) /out:$(TARGET) $(OBJECTS)
!INCLUDE $(TOPDIR)\win32\Make.rules.mak

View File

@ -47,8 +47,7 @@
#include "libopensc/asn1.h"
#include "libopensc/log.h"
#include "sm-module.h"
#include "sm-common.h"
/*
* From crypto/des/des_locl.h of OpenSSL .
*/

51
src/libsm/sm-common.h Normal file
View File

@ -0,0 +1,51 @@
/*
* sm-commot.h: Common SM cryptographic procedures
*
* Copyright (C) 2013 Viktor Tarasov <viktor.tarasov@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _SM_COMMON_H
#define _SM_COMMON_H
#ifdef __cplusplus
extern "C" {
#endif
#include <openssl/des.h>
#include <openssl/sha.h>
#include "libopensc/sm.h"
DES_LONG DES_cbc_cksum_3des(const unsigned char *in, DES_cblock *output, long length,
DES_key_schedule *schedule, DES_key_schedule *schedule2, const_DES_cblock *ivec);
DES_LONG DES_cbc_cksum_3des_emv96(const unsigned char *in, DES_cblock *output,
long length, DES_key_schedule *schedule, DES_key_schedule *schedule2,
const_DES_cblock *ivec);
int sm_encrypt_des_ecb3(unsigned char *key, unsigned char *data, int data_len,
unsigned char **out, int *out_len);
int sm_encrypt_des_cbc3(struct sc_context *ctx, unsigned char *key,
const unsigned char *in, size_t in_len,
unsigned char **out, size_t *out_len, int
not_force_pad);
int sm_decrypt_des_cbc3(struct sc_context *ctx, unsigned char *key,
unsigned char *data, size_t data_len, unsigned char **out, size_t *out_len);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -6,11 +6,14 @@ EXTRA_DIST = Makefile.mak
AM_CFLAGS = $(OPTIONAL_OPENSSL_CFLAGS) $(OPTIONAL_READLINE_CFLAGS)
AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/common -I$(top_builddir)/src/include
LIBS = $(top_builddir)/src/libopensc/libopensc.la $(top_builddir)/src/common/libcompat.la
LIBS = $(top_builddir)/src/libsm/libsm.la \
$(top_builddir)/src/libopensc/libopensc.la \
$(top_builddir)/src/common/libcompat.la
lib_LTLIBRARIES = libsmm-local.la
libsmm_local_la_SOURCES = smm-local.c sm-module.h sm-common.c sm-global-platform.c sm-cwa14890.c \
libsmm_local_la_SOURCES = smm-local.c sm-module.h \
sm-global-platform.c sm-cwa14890.c \
sm-card-authentic.c sm-card-iasecc.c \
smm-local.exports
libsmm_local_la_LIBADD = $(OPTIONAL_OPENSSL_LIBS) ../libopensc/libopensc.la

View File

@ -2,17 +2,17 @@ TOPDIR = ..\..
TARGET = smm-local.dll
OBJECTS = smm-local.obj sm-common.obj sm-global-platform.obj sm-cwa14890.obj sm-card-iasecc.obj sm-card-authentic.obj
OBJECTS = smm-local.obj sm-global-platform.obj sm-cwa14890.obj sm-card-iasecc.obj sm-card-authentic.obj
all: $(TARGET)
!INCLUDE $(TOPDIR)\win32\Make.rules.mak
$(TARGET): $(OBJECTS) ..\libopensc\opensc.lib
$(TARGET): $(OBJECTS) ..\libsm\libsm.lib ..\libopensc\opensc.lib
echo LIBRARY $* > $*.def
echo EXPORTS >> $*.def
type $*.exports >> $*.def
link /dll $(LINKFLAGS) /def:$*.def /out:$(TARGET) $(OBJECTS) ..\libopensc\opensc_a.lib $(ZLIB_LIB) $(OPENSSL_LIB) ..\common\libscdl.lib ws2_32.lib gdi32.lib advapi32.lib Crypt32.lib User32.lib
link /dll $(LINKFLAGS) /def:$*.def /out:$(TARGET) $(OBJECTS) ..\libsm\libsm.lib ..\libopensc\opensc_a.lib $(ZLIB_LIB) $(OPENSSL_LIB) ..\common\libscdl.lib ws2_32.lib gdi32.lib advapi32.lib Crypt32.lib User32.lib
if EXIST $(TARGET).manifest mt -manifest $(TARGET).manifest -outputresource:$(TARGET);2
.c.obj:

View File

@ -31,20 +31,7 @@ extern "C" {
#include <openssl/sha.h>
#include "libopensc/sm.h"
DES_LONG DES_cbc_cksum_3des(const unsigned char *in, DES_cblock *output, long length,
DES_key_schedule *schedule, DES_key_schedule *schedule2, const_DES_cblock *ivec);
DES_LONG DES_cbc_cksum_3des_emv96(const unsigned char *in, DES_cblock *output,
long length, DES_key_schedule *schedule, DES_key_schedule *schedule2,
const_DES_cblock *ivec);
int sm_encrypt_des_ecb3(unsigned char *key, unsigned char *data, int data_len,
unsigned char **out, int *out_len);
int sm_encrypt_des_cbc3(struct sc_context *ctx, unsigned char *key,
const unsigned char *in, size_t in_len,
unsigned char **out, size_t *out_len, int
not_force_pad);
int sm_decrypt_des_cbc3(struct sc_context *ctx, unsigned char *key,
unsigned char *data, size_t data_len, unsigned char **out, size_t *out_len);
#include "libsm/sm-common.h"
/* Global Platform definitions */
int sm_gp_get_mac(unsigned char *key, DES_cblock *icv, unsigned char *in, int in_len,

View File

@ -83,7 +83,7 @@
<File Source="$(var.SOURCE_DIR)\src\libopensc\opensc.dll" Vital="yes"/>
</Component>
<Component Id="smm_local.dll" Guid="*" Win64="$(var.Win64YesNo)">
<File Source="$(var.SOURCE_DIR)\src\sm\smm-local.dll" Vital="yes"/>
<File Source="$(var.SOURCE_DIR)\src\smm\smm-local.dll" Vital="yes"/>
</Component>
<Component Id="opensc_explorer.exe" Guid="*" Win64="$(var.Win64YesNo)">
<File Source="$(var.SOURCE_DIR)\src\tools\opensc-explorer.exe" Vital="yes"/>