Update sdf and skf commands

This commit is contained in:
Zhi Guan
2019-01-10 21:06:07 +08:00
parent 80977d068c
commit 6f9620d24b
18 changed files with 6431 additions and 6143 deletions

View File

@@ -412,7 +412,7 @@ ECIES_CIPHERTEXT_VALUE *ECIES_do_encrypt(const ECIES_PARAMS *param,
OPENSSL_assert(pout - ret->ciphertext->data == ciphertextlen);
} else {
unsigned int i;
int i;
for (i = 0; i < ret->ciphertext->length; i++) {
ret->ciphertext->data[i] = in[i] ^ enckey[i];
}

View File

@@ -142,7 +142,7 @@ int FFX_encrypt(FFX_CTX *ctx, const char *in, char *out, size_t iolen,
unsigned char qblock[16];
char lbuf[FFX_MAX_DIGITS/2 + 2];
uint64_t yval;
int i;
size_t i;
if (!ctx || !in || !out || !tweak) {
FFXerr(FFX_F_FFX_ENCRYPT, ERR_R_PASSED_NULL_PARAMETER);
@@ -189,7 +189,7 @@ int FFX_encrypt(FFX_CTX *ctx, const char *in, char *out, size_t iolen,
for (i = 0; i < FFX_NUM_ROUNDS; i += 2) {
unsigned char rblock[16];
int j;
size_t j;
qblock[11] = i & 0xff;
memcpy(qblock + 12, &rval, sizeof(rval));
@@ -239,7 +239,7 @@ int FFX_decrypt(FFX_CTX *ctx, const char *in, char *out, size_t iolen,
unsigned char qblock[16];
char lbuf[FFX_MAX_DIGITS/2 + 2];
uint64_t yval;
int i;
size_t i;
if (!ctx || !in || !out || !tweak) {
FFXerr(FFX_F_FFX_DECRYPT, ERR_R_PASSED_NULL_PARAMETER);
@@ -287,7 +287,7 @@ int FFX_decrypt(FFX_CTX *ctx, const char *in, char *out, size_t iolen,
for (i = FFX_NUM_ROUNDS - 1; i > 0; i -= 2) {
unsigned char rblock[16];
int j;
size_t j;
qblock[11] = i & 0xff;
memcpy(qblock + 12, &rval, sizeof(rval));

View File

@@ -629,6 +629,7 @@ end:
return ret;
}
/*
ECCCipher *d2i_ECCCipher_bio(BIO *bp, ECCCipher **a)
{
return NULL;
@@ -638,6 +639,7 @@ ECCCipher *d2i_ECCCipher_fp(FILE *fp, ECCCipher **a)
{
return NULL;
}
*/
int i2d_ECCCipher(ECCCipher *a, unsigned char **pp)
{
@@ -654,6 +656,7 @@ int i2d_ECCCipher(ECCCipher *a, unsigned char **pp)
return ret;
}
/*
int i2d_ECCCipher_bio(BIO *bp, ECCCipher *a)
{
return 0;
@@ -663,6 +666,7 @@ int i2d_ECCCipher_fp(FILE *fp, ECCCipher *a)
{
return 0;
}
*/
ECCSignature *d2i_ECCSignature(ECCSignature **a, const unsigned char **pp, long length)
{
@@ -694,6 +698,7 @@ end:
return ret;
}
/*
ECCSignature *d2i_ECCSignature_bio(BIO *bp, ECCSignature **a)
{
return NULL;
@@ -703,6 +708,7 @@ ECCSignature *d2i_ECCSignature_fp(FILE *fp, ECCSignature **a)
{
return NULL;
}
*/
int i2d_ECCSignature(ECCSignature *a, unsigned char **pp)
{
@@ -719,6 +725,7 @@ int i2d_ECCSignature(ECCSignature *a, unsigned char **pp)
return ret;
}
/*
int i2d_ECCSignature_bio(BIO *bp, ECCSignature *a)
{
return 0;
@@ -728,6 +735,7 @@ int i2d_ECCSignature_fp(FILE *fp, ECCSignature *a)
{
return 0;
}
*/
# ifndef OPENSSL_NO_ECIES
ECIES_CIPHERTEXT_VALUE *ECIES_CIPHERTEXT_VALUE_new_from_ECCCipher(

View File

@@ -601,6 +601,7 @@ ECCCIPHERBLOB *d2i_ECCCIPHERBLOB(ECCCIPHERBLOB **a, const unsigned char **pp, lo
goto end;
}
ret = blob;
blob = NULL;
@@ -625,18 +626,6 @@ int i2d_ECCCIPHERBLOB(ECCCIPHERBLOB *a, unsigned char **pp)
return ret;
}
ECCCIPHERBLOB *d2i_ECCCIPHERBLOB_bio(BIO *bp, ECCCIPHERBLOB **a)
{
GMAPIerr(GMAPI_F_D2I_ECCCIPHERBLOB_BIO, GMAPI_R_NOT_IMPLEMENTED);
return NULL;
}
int i2d_ECCCIPHERBLOB_bio(BIO *bp, ECCCIPHERBLOB *a)
{
GMAPIerr(GMAPI_F_I2D_ECCCIPHERBLOB_BIO, GMAPI_R_NOT_IMPLEMENTED);
return 0;
}
ECCSIGNATUREBLOB *d2i_ECCSIGNATUREBLOB(ECCSIGNATUREBLOB **a, const unsigned char **pp, long length)
{
ECCSIGNATUREBLOB *ret = NULL;
@@ -658,6 +647,8 @@ ECCSIGNATUREBLOB *d2i_ECCSIGNATUREBLOB(ECCSIGNATUREBLOB **a, const unsigned char
goto end;
}
// a not used
ret = blob;
blob = NULL;
@@ -681,42 +672,4 @@ int i2d_ECCSIGNATUREBLOB(ECCSIGNATUREBLOB *a, unsigned char **pp)
ECDSA_SIG_free(sig);
return ret;
}
ECCSIGNATUREBLOB *d2i_ECCSIGNATUREBLOB_bio(BIO *bp, ECCSIGNATUREBLOB **a)
{
GMAPIerr(GMAPI_F_D2I_ECCSIGNATUREBLOB_BIO, GMAPI_R_NOT_IMPLEMENTED);
return NULL;
}
int i2d_ECCSIGNATUREBLOB_bio(BIO *fp, ECCSIGNATUREBLOB *a)
{
GMAPIerr(GMAPI_F_I2D_ECCSIGNATUREBLOB_BIO, GMAPI_R_NOT_IMPLEMENTED);
return 0;
}
# ifndef OPENSSL_NO_STDIO
ECCCIPHERBLOB *d2i_ECCCIPHERBLOB_fp(FILE *fp, ECCCIPHERBLOB **a)
{
GMAPIerr(GMAPI_F_D2I_ECCCIPHERBLOB_FP, GMAPI_R_NOT_IMPLEMENTED);
return NULL;
}
int i2d_ECCCIPHERBLOB_fp(FILE *fp, ECCCIPHERBLOB *a)
{
GMAPIerr(GMAPI_F_I2D_ECCCIPHERBLOB_FP, GMAPI_R_NOT_IMPLEMENTED);
return 0;
}
ECCSIGNATUREBLOB *d2i_ECCSIGNATUREBLOB_fp(FILE *fp, ECCSIGNATUREBLOB **a)
{
GMAPIerr(GMAPI_F_D2I_ECCSIGNATUREBLOB_FP, GMAPI_R_NOT_IMPLEMENTED);
return NULL;
}
int i2d_ECCSIGNATUREBLOB_fp(FILE *fp, ECCSIGNATUREBLOB *a)
{
GMAPIerr(GMAPI_F_I2D_ECCSIGNATUREBLOB_FP, GMAPI_R_NOT_IMPLEMENTED);
return 0;
}
# endif /* OPENSSL_NO_STDIO */
#endif

View File

@@ -55,28 +55,6 @@
#include "sdf_sansec.h"
static void print_str(const char *name, const void *value)
{
(void)printf("%-20s: %s\n", name, (char *)value);
}
static void print_int(const char *name, unsigned int value)
{
(void)printf("%-20s: %u\n", name, value);
}
/*
static void print_buf(const char *name, const unsigned char *buf, size_t buflen)
{
size_t i;
(void)printf("%-20s: ", name);
for (i = 0; i < buflen; i++) {
(void)printf("%02x", buf[i]);
}
(void)puts("\n");
}
*/
typedef struct {
ULONG id;
char *name;
@@ -116,9 +94,9 @@ static table_item_t sdf_pkey_caps[] = {
{ SGD_SM2_3, "sm2encrypt" }
};
int SDF_PrintDeviceInfo(DEVICEINFO *pstDeviceInfo)
int SDF_PrintDeviceInfo(BIO *out, DEVICEINFO *pstDeviceInfo)
{
int i, n;
size_t i, n;
DEVICEINFO buf;
DEVICEINFO *devInfo = &buf;
@@ -127,73 +105,59 @@ int SDF_PrintDeviceInfo(DEVICEINFO *pstDeviceInfo)
devInfo->DeviceName[15] = 0;
devInfo->DeviceSerial[15] = 0;
print_str(" Issuer", devInfo->IssuerName);
print_str(" Device Name", devInfo->DeviceName);
print_str(" Serial Number", devInfo->DeviceSerial);
print_int(" Hardware Version", devInfo->DeviceVersion);
print_int(" Standard Version", devInfo->StandardVersion);
printf("%-20s: ", " Public Key Algors");
BIO_printf(out, " %-18s : %s\n", "Device Name", devInfo->DeviceName);
BIO_printf(out, " %-18s : %s\n", "Serial Number", devInfo->DeviceSerial);
BIO_printf(out, " %-18s : %s\n", "Issuer", devInfo->IssuerName);
BIO_printf(out, " %-18s : %u\n", "Hardware Version", devInfo->DeviceVersion);
BIO_printf(out, " %-18s : %u\n", "Standard Version", devInfo->StandardVersion);
BIO_printf(out, " %-18s : ", "Public Key Algors");
for (i = n = 0; i < OSSL_NELEM(sdf_pkey_caps); i++) {
if ((devInfo->AsymAlgAbility[0] & sdf_pkey_caps[i].id) ==
sdf_pkey_caps[i].id) {
printf("%s%s", n ? ", " : "", sdf_pkey_caps[i].name);
BIO_printf(out, "%s%s", n ? "," : "", sdf_pkey_caps[i].name);
n++;
}
}
printf("\n");
BIO_puts(out, "\n");
printf("%-20s: ", " Ciphers");
BIO_printf(out, " %-18s : ", "Ciphers");
for (i = n = 0; i < OSSL_NELEM(sdf_cipher_caps); i++) {
if ((devInfo->SymAlgAbility & sdf_cipher_caps[i].id) ==
sdf_cipher_caps[i].id) {
printf("%s%s", n ? ", " : "", sdf_cipher_caps[i].name);
BIO_printf(out, "%s%s", n ? "," : "", sdf_cipher_caps[i].name);
n++;
}
}
printf("\n");
BIO_puts(out, "\n");
printf("%-20s: ", " Digests");
BIO_printf(out, " %-18s : ", "Digests");
for (i = n = 0; i < OSSL_NELEM(sdf_digest_caps); i++) {
if ((devInfo->HashAlgAbility & sdf_digest_caps[i].id) ==
sdf_digest_caps[i].id) {
printf("%s%s", n ? ", " : "", sdf_digest_caps[i].name);
BIO_printf(out, "%s%s", n ? "," : "", sdf_digest_caps[i].name);
n++;
}
}
printf("\n");
BIO_puts(out, "\n");
BIO_puts(out, "\n");
return SDR_OK;
}
int SDF_PrintRSAPublicKey(RSArefPublicKey *blob)
int SDF_PrintRSAPublicKey(BIO *out, RSArefPublicKey *blob)
{
BIO *bio = NULL;
if (!(bio = BIO_new_fp(stdout, BIO_NOCLOSE))) {
return SDR_UNKNOWERR;
}
(void)BIO_printf(bio, "bits: %d\n", blob->bits);
(void)BIO_printf(bio, "m:\n ");
(void)BIO_hex_string(bio, 4, 16, blob->m, sizeof(blob->m));
(void)BIO_printf(bio, "\n");
(void)BIO_printf(bio, "e:\n ");
(void)BIO_hex_string(bio, 4, 16, blob->e, sizeof(blob->e));
(void)BIO_printf(bio, "\n");
BIO_free(bio);
(void)BIO_printf(out, "bits: %d\n", blob->bits);
(void)BIO_printf(out, "m:\n ");
(void)BIO_hex_string(out, 4, 16, blob->m, sizeof(blob->m));
(void)BIO_printf(out, "\n");
(void)BIO_printf(out, "e:\n ");
(void)BIO_hex_string(out, 4, 16, blob->e, sizeof(blob->e));
(void)BIO_printf(out, "\n");
return SDR_OK;
}
int SDF_PrintRSAPrivateKey(RSArefPrivateKey *blob)
int SDF_PrintRSAPrivateKey(BIO *bio, RSArefPrivateKey *blob)
{
BIO *bio = NULL;
if (!(bio = BIO_new_fp(stdout, BIO_NOCLOSE))) {
return SDR_UNKNOWERR;
}
(void)BIO_printf(bio, "bits: %d", blob->bits);
(void)BIO_printf(bio, "\n%s:\n ", "m");
(void)BIO_hex_string(bio, 4, 16, blob->m, sizeof(blob->m));
@@ -213,18 +177,11 @@ int SDF_PrintRSAPrivateKey(RSArefPrivateKey *blob)
(void)BIO_hex_string(bio, 4, 16, blob->coef, sizeof(blob->coef));
(void)BIO_printf(bio, "\n");
BIO_free(bio);
return SDR_OK;
}
int SDF_PrintECCPublicKey(ECCrefPublicKey *blob)
int SDF_PrintECCPublicKey(BIO *bio, ECCrefPublicKey *blob)
{
BIO *bio = NULL;
if (!(bio = BIO_new_fp(stdout, BIO_NOCLOSE))) {
return SDR_UNKNOWERR;
}
(void)BIO_printf(bio, "bits: %d", blob->bits);
(void)BIO_printf(bio, "\n%s:\n ", "x");
(void)BIO_hex_string(bio, 4, 16, blob->x, sizeof(blob->x));
@@ -232,35 +189,21 @@ int SDF_PrintECCPublicKey(ECCrefPublicKey *blob)
(void)BIO_hex_string(bio, 4, 16, blob->y, sizeof(blob->y));
(void)BIO_printf(bio, "\n");
BIO_free(bio);
return SDR_OK;
}
int SDF_PrintECCPrivateKey(ECCrefPrivateKey *blob)
int SDF_PrintECCPrivateKey(BIO *bio, ECCrefPrivateKey *blob)
{
BIO *bio = NULL;
if (!(bio = BIO_new_fp(stdout, BIO_NOCLOSE))) {
return SDR_UNKNOWERR;
}
(void)BIO_printf(bio, "bits: %d", blob->bits);
(void)BIO_printf(bio, "\n%s:\n ", "K");
(void)BIO_hex_string(bio, 4, 16, blob->K, sizeof(blob->K));
(void)BIO_printf(bio, "\n");
BIO_free(bio);
return SDR_OK;
}
int SDF_PrintECCCipher(ECCCipher *blob)
int SDF_PrintECCCipher(BIO *bio, ECCCipher *blob)
{
BIO *bio = NULL;
if (!(bio = BIO_new_fp(stdout, BIO_NOCLOSE))) {
return SDR_UNKNOWERR;
}
(void)BIO_printf(bio, "%s:\n ", "x");
(void)BIO_hex_string(bio, 4, 16, blob->x, sizeof(blob->x));
(void)BIO_printf(bio, "\n%s:\n ", "y");
@@ -272,25 +215,17 @@ int SDF_PrintECCCipher(ECCCipher *blob)
(void)BIO_hex_string(bio, 4, 16, blob->C, sizeof(blob->C));
(void)BIO_printf(bio, "\n");
BIO_free(bio);
return SDR_OK;
}
int SDF_PrintECCSignature(ECCSignature *blob)
int SDF_PrintECCSignature(BIO *bio, ECCSignature *blob)
{
BIO *bio = NULL;
if (!(bio = BIO_new_fp(stdout, BIO_NOCLOSE))) {
return SDR_UNKNOWERR;
}
(void)BIO_printf(bio, "%s:\n ", "r");
(void)BIO_hex_string(bio, 4, 16, blob->r, sizeof(blob->r));
(void)BIO_printf(bio, "\n%s:\n ", "s");
(void)BIO_hex_string(bio, 4, 16, blob->s, sizeof(blob->s));
(void)BIO_printf(bio, "\n");
BIO_free(bio);
return SDR_OK;
}

View File

@@ -57,31 +57,6 @@
#include "../../e_os.h"
static void print_str(const char *name, const char *value)
{
(void)printf("%-17s: %s\n", name, value);
}
static void print_int(const char *name, ULONG value)
{
(void)printf("%-17s: ", name);
if (value == UINT_MAX) {
puts("(unlimited)");
} else {
printf("%u\n", value);
}
}
static void print_buf(const char *name, BYTE *value, size_t len)
{
size_t i;
(void)printf("%-17s : ", name);
for (i = 0; i < len; i++) {
(void)printf("%02X", value[i]);
}
putchar('\n');
}
static char *skf_algor_name(ULONG ulAlgID)
{
switch (ulAlgID) {
@@ -193,118 +168,189 @@ static table_item_t skf_pkey_caps[] = {
{ SGD_SM2_3, "sm2encrypt" }
};
ULONG SKF_PrintDevInfo(DEVINFO *devInfo)
ULONG SKF_PrintDevInfo(BIO *out, DEVINFO *devInfo)
{
int i, n;
size_t i, n;
char *serial = OPENSSL_buf2hexstr(devInfo->SerialNumber, strlen((char *)devInfo->SerialNumber));
printf(" Version : %d.%d\n", devInfo->Version.major,
devInfo->Version.minor);
printf(" Manufacturer : %s\n", devInfo->Manufacturer);
printf(" Issuer : %s\n", devInfo->Issuer);
printf(" Label : %s\n", devInfo->Label);
print_buf(" Serial Number ", devInfo->SerialNumber, strlen((char *)devInfo->SerialNumber));
printf(" Hardware Version : %d.%d\n", devInfo->HWVersion.major,
devInfo->HWVersion.minor);
printf(" Firmware Version : %d.%d\n", devInfo->FirmwareVersion.major,
devInfo->FirmwareVersion.minor);
printf(" Ciphers : ");
BIO_printf(out, " %-16s : %d.%d\n", "Version", devInfo->Version.major, devInfo->Version.minor);
BIO_printf(out, " %-16s : %s\n", "Manufacturer", devInfo->Manufacturer);
BIO_printf(out, " %-16s : %s\n", "Issuer", devInfo->Issuer);
BIO_printf(out, " %-16s : %s\n", "Label", devInfo->Label);
BIO_printf(out, " %-16s : %s\n", "Serial Number", serial);
BIO_printf(out, " %-16s : %d.%d\n", "Firmware Version", devInfo->HWVersion.major, devInfo->HWVersion.minor);
BIO_printf(out, " %-16s : ", "Ciphers");
for (i = n = 0; i < OSSL_NELEM(skf_cipher_caps); i++) {
if ((devInfo->AlgSymCap & skf_cipher_caps[i].id) ==
skf_cipher_caps[i].id) {
printf("%s%s", n ? ", " : "", skf_cipher_caps[i].name);
BIO_printf(out, "%s%s", n ? "," : "", skf_cipher_caps[i].name);
n++;
}
}
printf("\n");
printf(" Public Keys : ");
for (i = n = 0; i < OSSL_NELEM(skf_pkey_caps); i++) {
BIO_puts(out, "\n");
BIO_printf(out, " %-16s : ", "Public Keys");
for (size_t i = n = 0; i < OSSL_NELEM(skf_pkey_caps); i++) {
if ((devInfo->AlgAsymCap & skf_pkey_caps[i].id) ==
skf_pkey_caps[i].id) {
printf("%s%s", n ? ", " : "", skf_pkey_caps[i].name);
BIO_printf(out, "%s%s", n ? "," : "", skf_pkey_caps[i].name);
n++;
}
}
printf("\n");
printf(" Digests : ");
BIO_puts(out, "\n");
BIO_printf(out, " %-16s : ", "Digests");
for (i = n = 0; i < OSSL_NELEM(skf_digest_caps); i++) {
if ((devInfo->AlgHashCap & skf_digest_caps[i].id) ==
skf_digest_caps[i].id) {
printf("%s%s", n ? ", " : "", skf_digest_caps[i].name);
BIO_printf(out, "%s%s", n ? "," : "", skf_digest_caps[i].name);
n++;
}
}
printf("\n");
printf(" Auth Cipher : ");
BIO_puts(out, "\n");
BIO_printf(out, " %-16s : ", "Auth Cipher");
for (i = 0; i < OSSL_NELEM(skf_cipher_caps); i++) {
if (devInfo->DevAuthAlgId == skf_cipher_caps[i].id) {
printf("%s\n", skf_cipher_caps[i].name);
BIO_printf(out, "%s\n", skf_cipher_caps[i].name);
break;
}
}
if (i == OSSL_NELEM(skf_cipher_caps)) {
printf("(unknown)\n");
BIO_puts(out, "(unknown)\n");
}
print_int(" Total Sapce ", devInfo->TotalSpace);
print_int(" Free Space ", devInfo->FreeSpace);
print_int(" MAX ECC Input ", devInfo->MaxECCBufferSize);
print_int(" MAX Cipher Input ", devInfo->MaxBufferSize);
if (devInfo->TotalSpace == UINT_MAX)
BIO_printf(out, " %-16s : %s\n", "Total Sapce", "(unlimited)");
else BIO_printf(out, " %-16s : %u\n", "Total Sapce", devInfo->TotalSpace);
if (devInfo->FreeSpace == UINT_MAX)
BIO_printf(out, " %-16s : %s\n", "Free Space", "(unlimited)");
else BIO_printf(out, " %-16s : %u\n", "Free Space", devInfo->FreeSpace);
if (devInfo->MaxECCBufferSize == UINT_MAX)
BIO_printf(out, " %-16s : %s\n", "MAX ECC Input", "(unlimited)");
else BIO_printf(out, " %-16s : %u\n", "MAX ECC Input", devInfo->MaxECCBufferSize);
if (devInfo->MaxBufferSize == UINT_MAX)
BIO_printf(out, " %-16s : %s\n", "MAX Cipher Input", "(unlimited)");
else BIO_printf(out, " %-16s : %u\n", "MAX Cipher Input", devInfo->MaxBufferSize);
OPENSSL_free(serial);
return SAR_OK;
}
ULONG SKF_PrintRSAPublicKey(RSAPUBLICKEYBLOB *blob)
ULONG SKF_PrintRSAPublicKey(BIO *out, RSAPUBLICKEYBLOB *blob)
{
print_str("AlgID", skf_algor_name(blob->AlgID));
print_int("BitLen", blob->BitLen);
print_buf("Modulus", blob->Modulus, MAX_RSA_MODULUS_LEN);
print_buf("PublicExponent", blob->PublicExponent, MAX_RSA_EXPONENT_LEN);
BIO_printf(out, "AlgID : %s\n", skf_algor_name(blob->AlgID));
BIO_printf(out, "BitLen : %u\n", blob->BitLen);
BIO_puts(out, "Modulus:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->Modulus, MAX_RSA_MODULUS_LEN);
BIO_puts(out, "\n");
BIO_puts(out, "PublicExponent:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->PublicExponent, MAX_RSA_EXPONENT_LEN);
BIO_puts(out, "\n");
return SAR_OK;
}
ULONG SKF_PrintRSAPrivateKey(RSAPRIVATEKEYBLOB *blob)
ULONG SKF_PrintRSAPrivateKey(BIO *out, RSAPRIVATEKEYBLOB *blob)
{
print_str("AlgID", skf_algor_name(blob->AlgID));
print_int("BitLen", blob->BitLen);
print_buf("Modulus", blob->Modulus, MAX_RSA_MODULUS_LEN);
print_buf("PublicExponent", blob->PublicExponent, MAX_RSA_EXPONENT_LEN);
print_buf("PrivateExponent", blob->PrivateExponent, MAX_RSA_MODULUS_LEN);
print_buf("Prime1", blob->Prime1, MAX_RSA_MODULUS_LEN/2);
print_buf("Prime2", blob->Prime2, MAX_RSA_MODULUS_LEN/2);
print_buf("Prime1Exponent", blob->Prime1Exponent, MAX_RSA_MODULUS_LEN/2);
print_buf("Prime2Exponent", blob->Prime2Exponent, MAX_RSA_MODULUS_LEN/2);
print_buf("Coefficient", blob->Coefficient, MAX_RSA_MODULUS_LEN/2);
BIO_printf(out, "AlgID : %s\n", skf_algor_name(blob->AlgID));
BIO_printf(out, "BitLen : %u\n", blob->BitLen);
BIO_puts(out, "Modulus:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->Modulus, MAX_RSA_MODULUS_LEN);
BIO_puts(out, "\n");
BIO_puts(out, "PublicExponent:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->PublicExponent, MAX_RSA_EXPONENT_LEN);
BIO_puts(out, "\n");
BIO_puts(out, "PrivateExponent:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->PrivateExponent, MAX_RSA_MODULUS_LEN);
BIO_puts(out, "\n");
BIO_puts(out, "Prime1:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->Prime1, MAX_RSA_MODULUS_LEN/2);
BIO_puts(out, "\n");
BIO_puts(out, "Prime2:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->Prime2, MAX_RSA_MODULUS_LEN/2);
BIO_puts(out, "\n");
BIO_puts(out, "Prime1Exponent:\n");
BIO_hex_string(out, 4, 16, blob->Prime1Exponent, MAX_RSA_MODULUS_LEN/2);
BIO_puts(out, "\n");
BIO_puts(out, " ");
BIO_puts(out, "Prime2Exponent:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->Prime2Exponent, MAX_RSA_MODULUS_LEN/2);
BIO_puts(out, "\n");
BIO_puts(out, "Coefficient:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->Coefficient, MAX_RSA_MODULUS_LEN/2);
BIO_puts(out, "\n");
return SAR_OK;
}
ULONG SKF_PrintECCPublicKey(ECCPUBLICKEYBLOB *blob)
ULONG SKF_PrintECCPublicKey(BIO *out, ECCPUBLICKEYBLOB *blob)
{
print_int("BitLen", blob->BitLen);
print_buf("XCoordinate", blob->XCoordinate, ECC_MAX_XCOORDINATE_BITS_LEN/8);
print_buf("YCoordinate", blob->YCoordinate, ECC_MAX_XCOORDINATE_BITS_LEN/8);
BIO_printf(out, "BitLen : %u\n", blob->BitLen);
BIO_puts(out, "XCoordinate:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->XCoordinate, ECC_MAX_XCOORDINATE_BITS_LEN/8);
BIO_puts(out, "\n");
BIO_puts(out, "YCoordinate:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->YCoordinate, ECC_MAX_XCOORDINATE_BITS_LEN/8);
BIO_puts(out, "\n");
return SAR_OK;
}
ULONG SKF_PrintECCPrivateKey(ECCPRIVATEKEYBLOB *blob)
ULONG SKF_PrintECCPrivateKey(BIO *out, ECCPRIVATEKEYBLOB *blob)
{
print_int("BitLen", blob->BitLen);
print_buf("PrivateKey", blob->PrivateKey, ECC_MAX_MODULUS_BITS_LEN/8);
BIO_printf(out, "BitLen : %u\n", blob->BitLen);
BIO_puts(out, "PrivateKey:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->PrivateKey, ECC_MAX_MODULUS_BITS_LEN/8);
BIO_puts(out, "\n");
return SAR_OK;
}
ULONG SKF_PrintECCCipher(ECCCIPHERBLOB *blob)
ULONG SKF_PrintECCCipher(BIO *out, ECCCIPHERBLOB *blob)
{
print_buf("XCoordinate", blob->XCoordinate, ECC_MAX_XCOORDINATE_BITS_LEN/8);
print_buf("YCoordinate", blob->YCoordinate, ECC_MAX_XCOORDINATE_BITS_LEN/8);
print_buf("HASH", blob->HASH, 32);
print_int("CipherLen", blob->CipherLen);
print_buf("Cipher", blob->Cipher, blob->CipherLen);
BIO_puts(out, "XCoordinate:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->XCoordinate, ECC_MAX_XCOORDINATE_BITS_LEN/8);
BIO_puts(out, "\n");
BIO_puts(out, "YCoordinate:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->YCoordinate, ECC_MAX_XCOORDINATE_BITS_LEN/8);
BIO_puts(out, "\n");
BIO_puts(out, "HASH:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->HASH, 32);
BIO_puts(out, "\n");
BIO_printf(out, "CipherLen: %u\n", blob->CipherLen);
BIO_puts(out, "Cipher:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->Cipher, blob->CipherLen);
BIO_puts(out, "\n");
return SAR_OK;
}
ULONG SKF_PrintECCSignature(ECCSIGNATUREBLOB *blob)
ULONG SKF_PrintECCSignature(BIO *out, ECCSIGNATUREBLOB *blob)
{
print_buf("r", blob->r, ECC_MAX_XCOORDINATE_BITS_LEN/8);
print_buf("s", blob->s, ECC_MAX_XCOORDINATE_BITS_LEN/8);
BIO_puts(out, "r:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->r, ECC_MAX_XCOORDINATE_BITS_LEN/8);
BIO_puts(out, "\n");
BIO_puts(out, "s:\n");
BIO_puts(out, " ");
BIO_hex_string(out, 4, 16, blob->s, ECC_MAX_XCOORDINATE_BITS_LEN/8);
BIO_puts(out, "\n");
return SAR_OK;
}
@@ -336,11 +382,11 @@ ULONG DEVAPI SKF_NewEnvelopedKey(ULONG ulCipherLen, ENVELOPEDKEYBLOB **enveloped
return SAR_OK;
}
ULONG DEVAPI SKF_PrintErrorString(ULONG ulError)
ULONG DEVAPI SKF_PrintErrorString(BIO *out, ULONG ulError)
{
LPSTR str = NULL;
SKF_GetErrorString(ulError, &str);
printf("SKF Error: %s\n", (char *)str);
BIO_printf(out, "SKF Error: %s\n", (char *)str);
return SAR_OK;
}

View File

@@ -59,8 +59,7 @@
SKF_METHOD *skf_method = NULL;
SKF_VENDOR *skf_vendor = NULL;
extern SKF_VENDOR *skf_wisec;
extern SKF_VENDOR skf_wisec;
ULONG SKF_LoadLibrary(LPSTR so_path, LPSTR vendor)
{
@@ -75,8 +74,8 @@ ULONG SKF_LoadLibrary(LPSTR so_path, LPSTR vendor)
}
if (vendor) {
if (strcmp((char *)vendor, skf_wisec->name) == 0) {
skf_vendor = skf_wisec;
if (strcmp((char *)vendor, skf_wisec.name) == 0) {
skf_vendor = &skf_wisec;
} else {
SKFerr(SKF_F_SKF_LOADLIBRARY, SKF_R_UNKNOWN_VENDOR);
return SAR_FAIL;