first step of v2 final release

This commit is contained in:
Zhi Guan
2017-11-05 21:00:36 +08:00
parent 480b9e8d88
commit 27bde477a5
395 changed files with 26341 additions and 31364 deletions

Binary file not shown.

View File

@@ -17,7 +17,7 @@ IF[{- !$disabled{tests} -}]
dtlsv1listentest ct_test threadstest afalgtest d2i_test \
ssl_test_ctx_test ssl_test x509aux cipherlist_test asynciotest \
bioprinttest sslapitest dtlstest sslcorrupttest bio_enc_test \
sm3test sms4test kdf2test eciestest ffxtest sm2test sm2evptest \
sm3test sms4test kdf2test eciestest ffxtest sm2test \
pailliertest cpktest otptest gmapitest ec2test \
bfibetest bb1ibetest sm9test \
saftest sdftest skftest softest zuctest \
@@ -312,10 +312,6 @@ IF[{- !$disabled{tests} -}]
INCLUDE[sm2test]=../include
DEPEND[sm2test]=../libcrypto
SOURCE[sm2evptest]=sm2evptest.c
INCLUDE[sm2evptest]=../include
DEPEND[sm2evptest]=../libcrypto
SOURCE[pailliertest]=pailliertest.c
INCLUDE[pailliertest]=../include
DEPEND[pailliertest]=../libcrypto

BIN
test/msb-f.msblob Normal file

Binary file not shown.

4
test/msb-f.p Normal file
View File

@@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKrbeqkuRk8VcRmWFmtP+LviMB3+6diz
WW3DwaffznyHGAFwUJ/ITv0XtbsCyl3QoyKGhrOAy3RvPK5M38iuXT0CAwEAAQ==
-----END PUBLIC KEY-----

BIN
test/msb-ff.dd Normal file

Binary file not shown.

BIN
test/msb-ff.dmsblob Normal file

Binary file not shown.

4
test/msb-ff.dp Normal file
View File

@@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKrbeqkuRk8VcRmWFmtP+LviMB3+6diz
WW3DwaffznyHGAFwUJ/ITv0XtbsCyl3QoyKGhrOAy3RvPK5M38iuXT0CAwEAAQ==
-----END PUBLIC KEY-----

BIN
test/msb-ff.msblobd Normal file

Binary file not shown.

BIN
test/msb-ff.msblobmsblob Normal file

Binary file not shown.

4
test/msb-ff.msblobp Normal file
View File

@@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKrbeqkuRk8VcRmWFmtP+LviMB3+6diz
WW3DwaffznyHGAFwUJ/ITv0XtbsCyl3QoyKGhrOAy3RvPK5M38iuXT0CAwEAAQ==
-----END PUBLIC KEY-----

BIN
test/msb-ff.pd Normal file

Binary file not shown.

4
test/msb-ff.pp Normal file
View File

@@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKrbeqkuRk8VcRmWFmtP+LviMB3+6diz
WW3DwaffznyHGAFwUJ/ITv0XtbsCyl3QoyKGhrOAy3RvPK5M38iuXT0CAwEAAQ==
-----END PUBLIC KEY-----

4
test/msb-fff.p Normal file
View File

@@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKrbeqkuRk8VcRmWFmtP+LviMB3+6diz
WW3DwaffznyHGAFwUJ/ITv0XtbsCyl3QoyKGhrOAy3RvPK5M38iuXT0CAwEAAQ==
-----END PUBLIC KEY-----

View File

@@ -10,4 +10,3 @@
use OpenSSL::Test::Simple;
simple_test("test_sm2", "sm2test", "sm2");
simple_test("test_sm2evp", "sm2evptest", "sm2");

View File

@@ -1,645 +0,0 @@
/* ====================================================================
* Copyright (c) 2016 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
/* Dummy SDF Library
*
* This is the **dummy** implementation of the SDF API, used by the SDF
* ENGINE for compiling and basic testing. For products this should be
* replaced by the library provided by hardware vendors.
*
* Design principles:
* 1. All the functions of this dummy library will return success, which
* is `SDR_OK`.
* 2. If there are return value pointers, such as handles, output length
* or generated key data types, the output will be filled with valid
* data. Such that the caller can parse these data without errors.
* 3. The implementation should not relay on any other libraries, source
* files or header files except the `sdf.h`.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sgd.h>
#include <openssl/sdf.h>
static char *deviceHandle = "SDF Device Handle";
static char *sessionHandle = "SDF Session Handle";
static char *keyHandle = "SDF Key Handle";
static char *agreementHandle = "SDF Agreement Handle";
static int hashAlgor;
/*
static unsigned char certificate[] = {
0x03, 0x04,
};
*/
static unsigned char rsaPublicKey[] = {
0x03, 0x04,
};
static unsigned char rsaPrivateKey[] = {
0x03, 0x04,
};
static unsigned char ecPublicKey[] = {
0x03, 0x04,
};
static unsigned char ecPrivateKey[] = {
0x03, 0x04,
};
static unsigned char ecCiphertext[] = {
0x03,
};
static unsigned char ecSignature[] = {
0x03,
};
/* 6.2.1 */
int SDF_OpenDevice(
void **phDeviceHandle)
{
*phDeviceHandle = deviceHandle;
return SDR_OK;
}
/* 6.2.2 */
int SDF_CloseDevice(
void *hDeviceHandle)
{
return SDR_OK;
}
/* 6.2.3 */
int SDF_OpenSession(
void *hDeviceHandle,
void **phSessionHandle)
{
*phSessionHandle = sessionHandle;
return SDR_OK;
}
/* 6.2.4 */
int SDF_CloseSession(
void *hSessionHandle)
{
return SDR_OK;
}
/* 6.2.5 */
int SDF_GetDeviceInfo(
void *hSessionHandle,
DEVICEINFO *pstDeviceInfo)
{
memset(pstDeviceInfo, 0, sizeof(*pstDeviceInfo));
strcpy((char *)pstDeviceInfo->IssuerName, "GmSSL");
strcpy((char *)pstDeviceInfo->DeviceName, "Dummy SDF");
strcpy((char *)pstDeviceInfo->DeviceSerial, "000001");
pstDeviceInfo->DeviceVersion = 2;
pstDeviceInfo->StandardVersion = 1;
pstDeviceInfo->AsymAlgAbility[0] = SGD_RSA|SGD_SM2_1;
pstDeviceInfo->AsymAlgAbility[1] = SGD_RSA|SGD_SM2_3;
pstDeviceInfo->SymAlgAbility = SGD_SM1|SGD_SSF33|SGD_SM4|SGD_ZUC;
pstDeviceInfo->HashAlgAbility = SGD_SM3|SGD_SHA1|SGD_SHA256;
pstDeviceInfo->BufferSize = 0;
return SDR_OK;
}
/* 6.2.6 */
int SDF_GenerateRandom(
void *hSessionHandle,
unsigned int uiLength,
unsigned char *pucRandom)
{
memset(pucRandom, 'R', uiLength);
return SDR_OK;
}
/* 6.2.7 */
int SDF_GetPrivateKeyAccessRight(
void *hSessionHandle,
unsigned int uiKeyIndex,
unsigned char *pucPassword,
unsigned int uiPwdLength)
{
return SDR_OK;
}
/* 6.2.8 */
int SDF_ReleasePrivateKeyAccessRight(
void *hSessionHandle,
unsigned int uiKeyIndex)
{
return SDR_OK;
}
/* 6.3.1 */
int SDF_ExportSignPublicKey_RSA(
void *hSessionHandle,
unsigned int uiKeyIndex,
RSArefPublicKey *pucPublicKey)
{
memcpy(pucPublicKey, rsaPublicKey, sizeof(*pucPublicKey));
return SDR_OK;
}
/* 6.3.2 */
int SDF_ExportEncPublicKey_RSA(
void *hSessionHandle,
unsigned int uiKeyIndex,
RSArefPublicKey *pucPublicKey)
{
memcpy(pucPublicKey, rsaPublicKey, sizeof(*pucPublicKey));
return SDR_OK;
}
/* 6.3.3 */
int SDF_GenerateKeyPair_RSA(
void *hSessionHandle,
unsigned int uiKeyBits,
RSArefPublicKey *pucPublicKey,
RSArefPrivateKey *pucPrivateKey)
{
memcpy(pucPublicKey, rsaPublicKey, sizeof(*pucPublicKey));
memcpy(pucPrivateKey, rsaPrivateKey, sizeof(*pucPrivateKey));
return SDR_OK;
}
/* 6.3.4 */
int SDF_GenerateKeyWithIPK_RSA(
void *hSessionHandle,
unsigned int uiIPKIndex,
unsigned int uiKeyBits,
unsigned char *pucKey,
unsigned int *puiKeyLength,
void **phKeyHandle)
{
*phKeyHandle = keyHandle;
return SDR_OK;
}
/* 6.3.5 */
int SDF_GenerateKeyWithEPK_RSA(
void *hSessionHandle,
unsigned int uiKeyBits,
RSArefPublicKey *pucPublicKey,
unsigned char *pucKey,
unsigned int *puiKeyLength,
void **phKeyHandle)
{
*phKeyHandle = keyHandle;
return SDR_OK;
}
/* 6.3.6 */
int SDF_ImportKeyWithISK_RSA(
void *hSessionHandle,
unsigned int uiISKIndex,
unsigned char *pucKey,
unsigned int uiKeyLength,
void **phKeyHandle)
{
*phKeyHandle = keyHandle;
return SDR_OK;
}
/* 6.3.7 */
int SDF_ExchangeDigitEnvelopeBaseOnRSA(
void *hSessionHandle,
unsigned int uiKeyIndex,
RSArefPublicKey *pucPublicKey,
unsigned char *pucDEInput,
unsigned int uiDELength,
unsigned char *pucDEOutput,
unsigned int *puiDELength)
{
*puiDELength = 256; // correct?
return SDR_OK;
}
/* 6.3.8 */
int SDF_ExportSignPublicKey_ECC(
void *hSessionHandle,
unsigned int uiKeyIndex,
ECCrefPublicKey *pucPublicKey)
{
memcpy(pucPublicKey, ecPublicKey, sizeof(*pucPublicKey));
return SDR_OK;
}
/* 6.3.9 */
int SDF_ExportEncPublicKey_ECC(
void *hSessionHandle,
unsigned int uiKeyIndex,
ECCrefPublicKey *pucPublicKey)
{
memcpy(pucPublicKey, ecPublicKey, sizeof(*pucPublicKey));
return SDR_OK;
}
/* 6.3.10 */
int SDF_GenerateKeyPair_ECC(
void *hSessionHandle,
unsigned int uiAlgID,
unsigned int uiKeyBits,
ECCrefPublicKey *pucPublicKey,
ECCrefPrivateKey *pucPrivateKey)
{
memcpy(pucPublicKey, ecPublicKey, sizeof(*pucPublicKey));
memcpy(pucPrivateKey, ecPrivateKey, sizeof(*pucPrivateKey));
return SDR_OK;
}
/* 6.3.11 */
int SDF_GenerateKeyWithIPK_ECC(
void *hSessionHandle,
unsigned int uiIPKIndex,
unsigned int uiKeyBits,
ECCCipher *pucKey,
void **phKeyHandle)
{
*phKeyHandle = keyHandle;
return SDR_OK;
}
/* 6.3.12 */
int SDF_GenerateKeyWithEPK_ECC(
void *hSessionHandle,
unsigned int uiKeyBits,
unsigned int uiAlgID,
ECCrefPublicKey *pucPublicKey,
ECCCipher *pucKey,
void **phKeyHandle)
{
*phKeyHandle = keyHandle;
return SDR_OK;
}
/* 6.3.13 */
int SDF_ImportKeyWithISK_ECC(
void *hSessionHandle,
unsigned int uiISKIndex,
ECCCipher *pucKey,
void **phKeyHandle)
{
*phKeyHandle = keyHandle;
return SDR_OK;
}
/* 6.3.14 */
int SDF_GenerateAgreementDataWithECC(
void *hSessionHandle,
unsigned int uiISKIndex,
unsigned int uiKeyBits,
unsigned char *pucSponsorID,
unsigned int uiSponsorIDLength,
ECCrefPublicKey *pucSponsorPublicKey,
ECCrefPublicKey *pucSponsorTmpPublicKey,
void **phAgreementHandle)
{
*phAgreementHandle = agreementHandle;
return SDR_OK;
}
/* 6.3.15 */
int SDF_GenerateKeyWithECC(
void *hSessionHandle,
unsigned char *pucResponseID,
unsigned int uiResponseIDLength,
ECCrefPublicKey *pucResponsePublicKey,
ECCrefPublicKey *pucResponseTmpPublicKey,
void *hAgreementHandle,
void **phKeyHandle)
{
*phKeyHandle = keyHandle;
return SDR_OK;
}
/* 6.3.16 */
int SDF_GenerateAgreementDataAndKeyWithECC(
void *hSessionHandle,
unsigned int uiISKIndex,
unsigned int uiKeyBits,
unsigned char *pucResponseID,
unsigned int uiResponseIDLength,
unsigned char *pucSponsorID,
unsigned int uiSponsorIDLength,
ECCrefPublicKey *pucSponsorPublicKey,
ECCrefPublicKey *pucSponsorTmpPublicKey,
ECCrefPublicKey *pucResponsePublicKey,
ECCrefPublicKey *pucResponseTmpPublicKey,
void **phKeyHandle)
{
*phKeyHandle = keyHandle;
return SDR_OK;
}
/* 6.3.17 */
int SDF_ExchangeDigitEnvelopeBaseOnECC(
void *hSessionHandle,
unsigned int uiKeyIndex,
unsigned int uiAlgID,
ECCrefPublicKey *pucPublicKey,
ECCCipher *pucEncDataIn,
ECCCipher *pucEncDataOut)
{
return SDR_OK;
}
/* 6.3.18 */
int SDF_GenerateKeyWithKEK(
void *hSessionHandle,
unsigned int uiKeyBits,
unsigned int uiAlgID,
unsigned int uiKEKIndex,
unsigned char *pucKey,
unsigned int *puiKeyLength,
void **phKeyHandle)
{
*phKeyHandle = keyHandle;
return SDR_OK;
}
/* 6.3.19 */
int SDF_ImportKeyWithKEK(
void *hSessionHandle,
unsigned int uiAlgID,
unsigned int uiKEKIndex,
unsigned char *pucKey,
unsigned int uiKeyLength,
void **phKeyHandle)
{
*phKeyHandle = keyHandle;
return SDR_OK;
}
/* 6.3.20 */
int SDF_DestroyKey(
void *hSessionHandle,
void *hKeyHandle)
{
return SDR_OK;
}
/* 6.4.1 */
int SDF_ExternalPublicKeyOperation_RSA(
void *hSessionHandle,
RSArefPublicKey *pucPublicKey,
unsigned char *pucDataInput,
unsigned int uiInputLength,
unsigned char *pucDataOutput,
unsigned int *puiOutputLength)
{
*puiOutputLength = 2048/8;
return SDR_OK;
}
/* 6.4.2 */
int SDF_ExternalPrivateKeyOperation_RSA(
void *hSessionHandle,
RSArefPrivateKey *pucPrivateKey,
unsigned char *pucDataInput,
unsigned int uiInputLength,
unsigned char *pucDataOutput,
unsigned int *puiOutputLength)
{
*puiOutputLength = 2048/8;
return SDR_OK;
}
/* 6.4.3 */
int SDF_InternalPrivateKeyOperation_RSA(
void *hSessionHandle,
unsigned int uiKeyIndex,
unsigned char *pucDataInput,
unsigned int uiInputLength,
unsigned char *pucDataOutput,
unsigned int *puiOutputLength)
{
*puiOutputLength = 2048/8;
return SDR_OK;
}
/* 6.4.4 */
int SDF_ExternalVerify_ECC(
void *hSessionHandle,
unsigned int uiAlgID,
ECCrefPublicKey *pucPublicKey,
unsigned char *pucDataInput,
unsigned int uiInputLength,
ECCSignature *pucSignature)
{
return SDR_OK;
}
/* 6.4.5 */
int SDF_InternalSign_ECC(
void *hSessionHandle,
unsigned int uiISKIndex,
unsigned char *pucData,
unsigned int uiDataLength,
ECCSignature *pucSignature)
{
memcpy(pucSignature, ecSignature, sizeof(*pucSignature));
return SDR_OK;
}
/* 6.4.6 */
int SDF_InternalVerify_ECC(
void *hSessionHandle,
unsigned int uiIPKIndex,
unsigned char *pucData,
unsigned int uiDataLength,
ECCSignature *pucSignature)
{
return SDR_OK;
}
/* 6.4.7 */
int SDF_ExternalEncrypt_ECC(
void *hSessionHandle,
unsigned int uiAlgID,
ECCrefPublicKey *pucPublicKey,
unsigned char *pucData,
unsigned int uiDataLength,
ECCCipher *pucEncData)
{
memcpy(pucEncData, ecCiphertext, sizeof(*pucEncData));
return SDR_OK;
}
/* 6.5.1 */
int SDF_Encrypt(
void *hSessionHandle,
void *hKeyHandle,
unsigned int uiAlgID,
unsigned char *pucIV,
unsigned char *pucData,
unsigned int uiDataLength,
unsigned char *pucEncData,
unsigned int *puiEncDataLength)
{
*puiEncDataLength = uiDataLength + 16;
return SDR_OK;
}
/* 6.5.2 */
int SDF_Decrypt(
void *hSessionHandle,
void *hKeyHandle,
unsigned int uiAlgID,
unsigned char *pucIV,
unsigned char *pucEncData,
unsigned int uiEncDataLength,
unsigned char *pucData,
unsigned int *puiDataLength)
{
*puiDataLength = uiEncDataLength;
return SDR_OK;
}
/* 6.5.3 */
int SDF_CalculateMAC(
void *hSessionHandle,
void *hKeyHandle,
unsigned int uiAlgID,
unsigned char *pucIV,
unsigned char *pucData,
unsigned int uiDataLength,
unsigned char *pucMAC,
unsigned int *puiMACLength)
{
*puiMACLength = 128/8;
return SDR_OK;
}
/* 6.6.1 */
int SDF_HashInit(
void *hSessionHandle,
unsigned int uiAlgID,
ECCrefPublicKey *pucPublicKey,
unsigned char *pucID,
unsigned int uiIDLength)
{
return SDR_OK;
}
/* 6.6.2 */
int SDF_HashUpdate(
void *hSessionHandle,
unsigned char *pucData,
unsigned int uiDataLength)
{
return SDR_OK;
}
/* 6.6.3 */
int SDF_HashFinal(void *hSessionHandle,
unsigned char *pucHash,
unsigned int *puiHashLength)
{
switch (hashAlgor) {
case SGD_SM3:
*puiHashLength = 256/8;
break;
case SGD_SHA1:
*puiHashLength = 160/8;
break;
case SGD_SHA256:
*puiHashLength = 256/8;
break;
}
return SDR_OK;
}
/* 6.7.1 */
int SDF_CreateFile(
void *hSessionHandle,
unsigned char *pucFileName,
unsigned int uiNameLen,
unsigned int uiFileSize)
{
return SDR_OK;
}
/* 6.7.2 */
int SDF_ReadFile(
void *hSessionHandle,
unsigned char *pucFileName,
unsigned int uiNameLen,
unsigned int uiOffset,
unsigned int *puiReadLength,
unsigned char *pucBuffer)
{
// return a certificate
return SDR_OK;
}
/* 6.7.3 */
int SDF_WriteFile(
void *hSessionHandle,
unsigned char *pucFileName,
unsigned int uiNameLen,
unsigned int uiOffset,
unsigned int uiWriteLength,
unsigned char *pucBuffer)
{
return SDR_OK;
}
/* 6.7.4 */
int SDF_DeleteFile(
void *hSessionHandle,
unsigned char *pucFileName,
unsigned int uiNameLen)
{
return SDR_OK;
}

File diff suppressed because it is too large Load Diff

3
test/serpenttest.c Normal file → Executable file
View File

@@ -57,9 +57,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include <openssl/e_os2.h>
#include "../e_os.h"

View File

@@ -1,255 +0,0 @@
/*====================================================================
* Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
// Simon Tests
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <openssl/simon.h>
int main(int argc, char** argv){
// Create reuseable cipher objects for each alogirthm type
simon_cipher my_simon_cipher = *(simon_cipher *)malloc(sizeof(simon_cipher));
// Create generic tmp variables
uint8_t ciphertext_buffer[16];
uint32_t result;
// Initialize IV and Counter Values for Use with Block Modes
uint8_t my_IV[] = {0x32,0x14,0x76,0x58};
uint8_t my_counter[] = {0x2F,0x3D,0x5C,0x7B};
int i, error_sum;
error_sum = 0;
// Simon 64/32 Test
// Key: 1918 1110 0908 0100 Plaintext: 6565 6877 Ciphertext: c69b e9bb
uint8_t simon64_32_key[] = {0x00, 0x01, 0x08, 0x09, 0x10, 0x11, 0x18, 0x19};
uint8_t simon64_32_plain[] = {0x77, 0x68, 0x65, 0x65};
uint8_t simon64_32_cipher[] = {0xBB,0xE9, 0x9B, 0xC6};
result = simon_init(&my_simon_cipher, simon_64_32, ECB, simon64_32_key, my_IV, my_counter);
simon_encrypt(my_simon_cipher, &simon64_32_plain, &ciphertext_buffer);
for(i = 0; i < 4; i++) {
if (ciphertext_buffer[i] != simon64_32_cipher[i])
error_sum++;
}
simon_decrypt(my_simon_cipher, &simon64_32_cipher, &ciphertext_buffer);
for(i = 0; i < 4; i++) {
if (ciphertext_buffer[i] != simon64_32_plain[i])
error_sum++;
}
// Simon 72/48 Test
// Key: 121110 0a0908 020100 Plaintext: 612067 6e696c Ciphertext: dae5ac 292cac
uint8_t simon72_48_key[] = {0x00, 0x01, 0x02, 0x08, 0x09, 0x0A, 0x10, 0x11, 0x12};
uint8_t simon72_48_plain[] = {0x6c, 0x69, 0x6E, 0x67, 0x20, 0x61};
uint8_t simon72_48_cipher[] = {0xAC, 0x2C, 0x29, 0xAC, 0xE5, 0xda};
result = simon_init(&my_simon_cipher, simon_72_48, ECB, simon72_48_key, my_IV, my_counter);
simon_encrypt(my_simon_cipher, &simon72_48_plain, &ciphertext_buffer);
for(i = 0; i < 6; i++) {
if (ciphertext_buffer[i] != simon72_48_cipher[i])
error_sum++;
}
simon_decrypt(my_simon_cipher, &simon72_48_cipher, &ciphertext_buffer);
for(i = 0; i < 6; i++) {
if (ciphertext_buffer[i] != simon72_48_plain[i])
error_sum++;
}
// Simon 96/48 Test
// Key: 1a1918 121110 0a0908 020100 Plaintext: 726963 20646e Ciphertext: 6e06a5 acf156
uint8_t simon96_48_key[] = {0x00, 0x01, 0x02, 0x08, 0x09, 0x0A, 0x10, 0x11, 0x12, 0x18, 0x19, 0x1a};
uint8_t simon96_48_plain[] = {0x6e, 0x64, 0x20, 0x63, 0x69, 0x72};
uint8_t simon96_48_cipher[] = {0x56, 0xf1, 0xac, 0xa5, 0x06, 0x6e};
result = simon_init(&my_simon_cipher, simon_96_48, ECB, simon96_48_key, my_IV, my_counter);
simon_encrypt(my_simon_cipher, &simon96_48_plain, &ciphertext_buffer);
for(i = 0; i < 6; i++) {
if (ciphertext_buffer[i] != simon96_48_cipher[i])
error_sum++;
}
simon_decrypt(my_simon_cipher, &simon96_48_cipher, &ciphertext_buffer);
for(i = 0; i < 6; i++) {
if (ciphertext_buffer[i] != simon96_48_plain[i])
error_sum++;
}
// Simon 96/64 Test
// Key: 13121110 0b0a0908 03020100 Plaintext: 6f722067 6e696c63 Ciphertext: 5ca2e27f 111a8fc8
uint8_t simon96_64_key[] = {0x00, 0x01, 0x02, 0x03, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x11, 0x12, 0x13};
uint8_t simon96_64_plain[] = {0x63, 0x6c, 0x69, 0x6e, 0x67, 0x20, 0x72, 0x6f};
uint8_t simon96_64_cipher[] = {0xc8, 0x8f, 0x1a, 0x11, 0x7f, 0xe2, 0xa2, 0x5c};
result = simon_init(&my_simon_cipher, simon_96_64, ECB, simon96_64_key, my_IV, my_counter);
simon_encrypt(my_simon_cipher, &simon96_64_plain, &ciphertext_buffer);
for(i = 0; i < 8; i++) {
if (ciphertext_buffer[i] != simon96_64_cipher[i])
error_sum++;
}
simon_decrypt(my_simon_cipher, &simon96_64_cipher, &ciphertext_buffer);
for(i = 0; i < 8; i++) {
if (ciphertext_buffer[i] != simon96_64_plain[i])
error_sum++;
}
// Simon 128/64 Test
// Key: 1b1a1918 13121110 0b0a0908 03020100 Plaintext: 656b696c 20646e75 Ciphertext: 44c8fc20 b9dfa07a
uint8_t simon128_64_key[] = {0x00, 0x01, 0x02, 0x03, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x11, 0x12, 0x13, 0x18, 0x19, 0x1A, 0x1B};
uint8_t simon128_64_plain[] = {0x75, 0x6e, 0x64, 0x20, 0x6c, 0x69, 0x6b, 0x65};
uint8_t simon128_64_cipher[] = {0x7a, 0xa0, 0xdf, 0xb9, 0x20, 0xfc, 0xc8, 0x44};
result = simon_init(&my_simon_cipher, simon_128_64, ECB, simon128_64_key, my_IV, my_counter);
simon_encrypt(my_simon_cipher, &simon128_64_plain, &ciphertext_buffer);
for(i = 0; i < 8; i++) {
if (ciphertext_buffer[i] != simon128_64_cipher[i])
error_sum++;
}
simon_decrypt(my_simon_cipher, &simon128_64_cipher, &ciphertext_buffer);
for(i = 0; i < 8; i++) {
if (ciphertext_buffer[i] != simon128_64_plain[i])
error_sum++;
}
// Simon 96/96 Test
// Key: 0d0c0b0a0908 050403020100 Plaintext: 2072616c6c69 702065687420 Ciphertext: 602807a462b4 69063d8ff082
uint8_t simon96_96_key[] = {0x00, 0x01, 0x02, 0x03,0x04,0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D};
uint8_t simon96_96_plain[] = {0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x20};
uint8_t simon96_96_cipher[] = {0x82, 0xf0, 0x8f, 0x3d, 0x06, 0x69, 0xb4, 0x62, 0xa4, 0x07, 0x28, 0x60};
result = simon_init(&my_simon_cipher, simon_96_96, ECB, simon96_96_key, my_IV, my_counter);
simon_encrypt(my_simon_cipher, &simon96_96_plain, &ciphertext_buffer);
for(i = 0; i < 12; i++) {
if (ciphertext_buffer[i] != simon96_96_cipher[i])
error_sum++;
}
simon_decrypt(my_simon_cipher, &simon96_96_cipher, &ciphertext_buffer);
for(i = 0; i < 12; i++) {
if (ciphertext_buffer[i] != simon96_96_plain[i])
error_sum++;
}
// Simon 144/96 Test
// Key: 151413121110 0d0c0b0a0908 050403020100 Plaintext: 746168742074 73756420666f Ciphertext: ecad1c6c451e 3f59c5db1ae9
uint8_t simon144_96_key[] = {0x00, 0x01, 0x02, 0x03,0x04,0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15};
uint8_t simon144_96_plain[] = {0x6f, 0x66, 0x20, 0x64, 0x75, 0x73, 0x74, 0x20, 0x74, 0x68, 0x61, 0x74};
uint8_t simon144_96_cipher[] = {0xe9, 0x1a, 0xdb, 0xc5, 0x59, 0x3f, 0x1e, 0x45, 0x6c, 0x1c, 0xad, 0xec};
result = simon_init(&my_simon_cipher, simon_144_96, ECB, simon144_96_key, my_IV, my_counter);
simon_encrypt(my_simon_cipher, &simon144_96_plain, &ciphertext_buffer);
for(i = 0; i < 12; i++) {
if (ciphertext_buffer[i] != simon144_96_cipher[i])
error_sum++;
}
simon_decrypt(my_simon_cipher, &simon144_96_cipher, &ciphertext_buffer);
for(i = 0; i < 12; i++) {
if (ciphertext_buffer[i] != simon144_96_plain[i])
error_sum++;
}
// Simon 128/128 Test
// Key: 0f0e0d0c0b0a0908 0706050403020100 Plaintext: 6373656420737265 6c6c657661727420 Ciphertext: 49681b1e1e54fe3f 65aa832af84e0bbc
uint8_t simon128_128_key[] = {0x00, 0x01, 0x02, 0x03,0x04, 0x05, 0x06,0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
uint8_t simon128_128_plain[] = {0x20, 0x74, 0x72, 0x61, 0x76, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x73, 0x20, 0x64, 0x65, 0x73, 0x63};
uint8_t simon128_128_cipher[] = {0xbc, 0x0b, 0x4e, 0xf8, 0x2a, 0x83, 0xaa, 0x65, 0x3f, 0xfe, 0x54, 0x1e, 0x1e, 0x1b, 0x68, 0x49};
result = simon_init(&my_simon_cipher, simon_128_128, ECB, simon128_128_key, my_IV, my_counter);
simon_encrypt(my_simon_cipher, &simon128_128_plain, &ciphertext_buffer);
for(i = 0; i < 16; i++) {
if (ciphertext_buffer[i] != simon128_128_cipher[i])
error_sum++;
}
simon_decrypt(my_simon_cipher, &simon128_128_cipher, &ciphertext_buffer);
for(i = 0; i < 16; i++) {
if (ciphertext_buffer[i] != simon128_128_plain[i])
error_sum++;
}
// Simon 192/128 Test
// Key: 1716151413121110 0f0e0d0c0b0a0908 0706050403020100 Plaintext: 206572656874206e 6568772065626972 Ciphertext: c4ac61effcdc0d4f 6c9c8d6e2597b85b
uint8_t simon192_128_key[] = {0x00, 0x01, 0x02, 0x03,0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17};
uint8_t simon192_128_plain[] = {0x72, 0x69, 0x62, 0x65, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x72, 0x65, 0x20};
uint8_t simon192_128_cipher[] = {0x5b, 0xb8, 0x97, 0x25, 0x6e, 0x8d, 0x9c, 0x6c, 0x4f, 0x0d, 0xdc, 0xfc, 0xef, 0x61, 0xac, 0xc4};
result = simon_init(&my_simon_cipher, simon_192_128, ECB, simon192_128_key, my_IV, my_counter);
simon_encrypt(my_simon_cipher, &simon192_128_plain, &ciphertext_buffer);
for(i = 0; i < 16; i++) {
if (ciphertext_buffer[i] != simon192_128_cipher[i])
error_sum++;
}
simon_decrypt(my_simon_cipher, &simon192_128_cipher, &ciphertext_buffer);
for(i = 0; i < 16; i++) {
if (ciphertext_buffer[i] != simon192_128_plain[i])
error_sum++;
}
// Simon 256/128 Test
// Key: 1f1e1d1c1b1a1918 1716151413121110 0f0e0d0c0b0a0908 0706050403020100 Plaintext: 74206e69206d6f6f 6d69732061207369 Ciphertext: 8d2b5579afc8a3a0 3bf72a87efe7b868
uint8_t simon256_128_key[] = {0x00, 0x01, 0x02, 0x03,0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1d, 0x1e, 0x1f};
uint8_t simon256_128_plain[] = {0x69, 0x73, 0x20, 0x61, 0x20, 0x73, 0x69, 0x6d, 0x6f, 0x6f, 0x6d, 0x20, 0x69, 0x6e, 0x20, 0x74};
uint8_t simon256_128_cipher[] = {0x68, 0xb8, 0xe7, 0xef, 0x87, 0x2a, 0xf7, 0x3b, 0xa0, 0xa3, 0xc8, 0xaf, 0x79, 0x55, 0x2b, 0x8d};
result = simon_init(&my_simon_cipher, simon_256_128, ECB, simon256_128_key, my_IV, my_counter);
simon_encrypt(my_simon_cipher, &simon256_128_plain, &ciphertext_buffer);
for(i = 0; i < 16; i++) {
if (ciphertext_buffer[i] != simon256_128_cipher[i])
error_sum++;
}
simon_decrypt(my_simon_cipher, &simon256_128_cipher, &ciphertext_buffer);
for(i = 0; i < 16; i++) {
if (ciphertext_buffer[i] != simon256_128_plain[i])
error_sum++;
}
return error_sum;
}

View File

@@ -60,6 +60,348 @@ int main(int argc, char **argv)
}
#else
# include <openssl/evp.h>
# include <openssl/gmskf.h>
#if 0
# define PRINT_ERRSTR(rv) \
fprintf(stderr, "error: %s %d: %s\n", __FILE__, __LINE__, \
SKF_GetErrorString(rv))
DEVHANDLE open_dev(LPSTR devName, int verbose)
{
DEVHANDLE hDev;
ULONG rv;
if ((rv = SKF_ConnectDev(devName, &hDev)) != SAR_OK) {
PRINT_ERRSTR(rv);
return NULL;
}
if (verbose > 1) {
DEVINFO devInfo;
if ((rv = SKF_GetDevInfo(hDev, &devInfo)) != SAR_OK) {
PRINT_ERRSTR(rv);
SKF_DisConnectDev(hDev);
return NULL;
}
SKF_PrintDeviceInfo(stdout, &devInfo);
}
return hDev;
}
int test_skf_mac(DEVHANDLE hDev, ULONG ulAlgID, int verbose)
{
int ret = 0;
HANDLE hKey = NULL;
HANDLE hMac = NULL;
BLOCKCIPHERPARAM param;
BYTE key[EVP_MAX_KEY_LENGTH];
BYTE data[128] = {0};
BYTE mac[EVP_MAX_MD_SIZE];
ULONG dataLen, macLen;
ULONG rv;
if ((rv = SKF_SetSymmKey(hDev, key, ulAlgID, &hKey)) != SAR_OK) {
PRINT_ERRSTR(rv);
goto end;
}
bzero(&param, sizeof(param));
param.IVLen = 0;
param.PaddingType = SKF_NO_PADDING;
if ((rv = SKF_MacInit(hKey, &param, &hMac)) != SAR_OK) {
PRINT_ERRSTR(rv);
goto end;
}
dataLen = (ULONG)sizeof(data);
macLen = (ULONG)sizeof(mac);
if ((rv = SKF_Mac(hMac, data, dataLen, mac, &macLen)) != SAR_OK) {
PRINT_ERRSTR(rv);
goto end;
}
if (macLen != 16) {
printf("macLen = %d\n", (int)macLen);
fprintf(stderr, "error: %s %d: %s\n", __FILE__, __LINE__, "mac
length != 16");
goto end;
}
ret = 1;
end:
if ((rv = SKF_CloseHandle(hMac)) != SAR_OK) {
PRINT_ERRSTR(rv);
ret = 0;
}
if ((rv = SKF_CloseHandle(hKey)) != SAR_OK) {
PRINT_ERRSTR(rv);
ret = 0;
}
if (ret && verbose) {
printf("%s(%s) passed\n", __FUNCTION__,
SKF_get_alg_name(ulAlgID));
}
return ret;
}
int test_skf_dgst(DEVHANDLE hDev, ULONG ulAlgID, int verbose)
{
int ret = 0;
HANDLE hHash = NULL;
BYTE data[200] = {0};
BYTE dgst[EVP_MAX_MD_SIZE];
ULONG dataLen, dgstLen;
ULONG rv;
if ((rv = SKF_DigestInit(hDev, ulAlgID, NULL, NULL, 0, &hHash)) !=
SAR_OK) {
PRINT_ERRSTR(rv);
return 0;
}
dataLen = (ULONG)sizeof(data);
dgstLen = (ULONG)sizeof(dgst);
if ((rv = SKF_Digest(hHash, data, dataLen, dgst, &dgstLen)) != SAR_OK)
{
PRINT_ERRSTR(rv);
goto end;
}
if (verbose > 1) {
ULONG i;
printf("%s (%u-Byte) = ", SKF_get_alg_name(ulAlgID), dgstLen);
for (i = 0; i < dgstLen; i++) {
printf("%02x", dgst[i]);
}
printf("\n");
}
ret = 1;
end:
if ((rv = SKF_CloseHandle(hHash)) != SAR_OK) {
PRINT_ERRSTR(rv);
ret = 0;
}
if (ret && verbose) {
printf("%s(%s) passed\n", __FUNCTION__,
SKF_get_alg_name(ulAlgID));
}
return ret;
}
int test_skf_enc(DEVHANDLE hDev, ULONG ulAlgID, BLOCKCIPHERPARAM param, int
verbose)
{
int ret = 0;
HANDLE hKey = NULL;
BYTE key[EVP_MAX_KEY_LENGTH];
BYTE data[] = "message to be encrypted";
BYTE cbuf[256];
BYTE mbuf[256];
ULONG mlen, clen;
ULONG rv;
if ((rv = SKF_SetSymmKey(hDev, key, ulAlgID, &hKey)) != SAR_OK) {
PRINT_ERRSTR(rv);
goto end;
}
if ((rv = SKF_EncryptInit(hKey, param)) != SAR_OK) {
PRINT_ERRSTR(rv);
goto end;
}
mlen = (ULONG)sizeof(data);
clen = (ULONG)sizeof(cbuf);
if ((rv = SKF_Encrypt(hKey, data, mlen, cbuf, &clen)) != SAR_OK) {
PRINT_ERRSTR(rv);
goto end;
}
if ((rv = SKF_DecryptInit(hKey, param)) != SAR_OK) {
PRINT_ERRSTR(rv);
goto end;
}
mlen = (ULONG)sizeof(mbuf);
if ((rv = SKF_Decrypt(hKey, cbuf, clen, mbuf, &mlen)) != SAR_OK) {
PRINT_ERRSTR(rv);
goto end;
}
//FIXME: compare data with mbuf
if (verbose > 1) {
//FIXME: print ciphertext
}
ret = 1;
end:
if ((rv = SKF_CloseHandle(hKey)) != SAR_OK) {
PRINT_ERRSTR(rv);
ret = 0;
}
if (ret && verbose) {
//FIXME: print success info
}
return ret;
}
int test_skf_rsa(DEVHANDLE hDev, ULONG ulBitsLen, int verbose)
{
int ret = 0;
RSAPRIVATEKEYBLOB rsa;
RSAPUBLICKEYBLOB rsaPubKey;
BYTE data[] = "message to be encrypted or signed";
BYTE cbuf[512];
BYTE mbuf[256];
BYTE sig[512];
ULONG len, clen, mlen, siglen;
ULONG rv;
if ((rv = SKF_GenExtRSAKey(hDev, 2048, &rsa)) != SAR_OK) {
PRINT_ERRSTR(rv);
goto end;
}
memcpy(&rsaPubKey, &rsa, sizeof(rsaPubKey));
len = (ULONG)sizeof(data);
clen = (ULONG)sizeof(cbuf);
if ((rv = SKF_ExtRSAPubKeyOperation(hDev, &rsaPubKey, data, len, cbuf,
&clen)) != SAR_OK) {
PRINT_ERRSTR(rv);
goto end;
}
mlen = (ULONG)sizeof(mbuf);
if ((rv = SKF_ExtRSAPriKeyOperation(hDev, &rsa, cbuf, clen, mbuf,
&mlen)) != SAR_OK) {
PRINT_ERRSTR(rv);
goto end;
}
ret = 1;
end:
return 0;
}
int test_skf_ec(DEVHANDLE hDev, int verbose)
{
ECCPRIVATEKEYBLOB priKey;
ECCPUBLICKEYBLOB pubKey;
ECCSIGNATUREBLOB sig;
BYTE cbuf[sizeof(ECCCIPHERBLOB) + 512];
BYTE msg[] = "message to be signed and encrypted";
BYTE mbuf[128];
ULONG mlen, clen;
ULONG rv;
bzero(&priKey, sizeof(priKey));
bzero(&pubKey, sizeof(pubKey));
if ((rv = SKF_GenExtECCKeyPair(hDev, &priKey, &pubKey)) != SAR_OK) {
PRINT_ERRSTR(rv);
return 0;
}
mlen = (ULONG)sizeof(msg);
bzero(&sig, sizeof(sig));
if ((rv = SKF_ExtECCSign(hDev, &priKey, msg, mlen, &sig)) != SAR_OK) {
PRINT_ERRSTR(rv);
return 0;
}
if ((rv = SKF_ExtECCVerify(hDev, &pubKey, msg, mlen, &sig)) != SAR_OK)
{
PRINT_ERRSTR(rv);
return 0;
}
mlen = (ULONG)sizeof(msg);
bzero(cbuf, sizeof(cbuf));
if ((rv = SKF_ExtECCEncrypt(hDev, &pubKey, msg, mlen, (ECCCIPHERBLOB
*)cbuf)) != SAR_OK) {
PRINT_ERRSTR(rv);
return 0;
}
mlen = (ULONG)sizeof(mbuf);
bzero(mbuf, sizeof(mbuf));
if ((rv = SKF_ExtECCDecrypt(hDev, &priKey, (ECCCIPHERBLOB *)cbuf, mbuf,
&mlen)) != SAR_OK) {
PRINT_ERRSTR(rv);
return 0;
}
return 1;
}
int main(int argc, char **argv)
{
int verbose = 2;
DEVHANDLE hDev = NULL;
ULONG digestAlgors[] = {
SGD_SM3,
SGD_SHA1,
SGD_SHA256
};
ULONG cipherAlgors[] = {
SGD_SM4_ECB,
SGD_SM4_CBC,
SGD_SM4_CFB,
SGD_SM4_CFB,
SGD_SM4_CFB,
SGD_SM4_OFB
};
BLOCKCIPHERPARAM cipherParams[] = {
{{0}, 0, SKF_NO_PADDING, 0},
{{0}, 16, SKF_PKCS5_PADDING, 0},
{{0}, 16, SKF_NO_PADDING, 1},
{{0}, 16, SKF_NO_PADDING, 8},
{{0}, 16, SKF_NO_PADDING, 128},
{{0}, 16, SKF_NO_PADDING, 0},
};
ULONG rsaBits[] = { 1024, 2048 };
int i;
hDev = open_dev((LPSTR)"name", verbose);
/*
if (!test_skf_mac(hDev, SGD_SM4_MAC, verbose)) {
goto end;
}
*/
for (i = 0; i < sizeof(digestAlgors)/sizeof(digestAlgors[0]); i++) {
if (!test_skf_dgst(hDev, digestAlgors[i], verbose)) {
goto end;
}
}
for (i = 0; i < sizeof(cipherAlgors)/sizeof(cipherAlgors[0]); i++) {
if (!test_skf_enc(hDev, cipherAlgors[i], cipherParams[i],
verbose)) {
goto end;
}
}
for (i = 0; i < sizeof(rsaBits)/sizeof(rsaBits[0]); i++) {
if (!test_skf_rsa(hDev, rsaBits[i], verbose)) {
goto end;
}
}
if (!test_skf_ec(hDev, verbose)) {
goto end;
}
end:
ERR_print_errors_fp(stderr);
SKF_DisConnectDev(hDev);
return -1;
}
#endif
int main(int argc, char **argv)
{

View File

@@ -1,611 +0,0 @@
/* ====================================================================
* Copyright (c) 2014 - 2016 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "../e_os.h"
#ifdef OPENSSL_NO_SM2
int main(int argc, char **argv)
{
printf("No SM2 support\n");
return 0;
}
#else
# include <openssl/ec.h>
# include <openssl/bn.h>
# include <openssl/evp.h>
# include <openssl/rand.h>
# include <openssl/engine.h>
# include <openssl/sm2.h>
static EVP_PKEY *genpkey(int curve_nid, BIO *out, int verbose)
{
int ok = 0;
EVP_PKEY *ret = NULL;
EVP_PKEY_CTX *pkctx = NULL;
if (!(pkctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL))) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!EVP_PKEY_keygen_init(pkctx)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pkctx, curve_nid)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!EVP_PKEY_keygen(pkctx, &ret)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (verbose > 1) {
EVP_PKEY_print_private(out, ret, 4, NULL);
BIO_printf(out, "\n");
}
ok = 1;
end:
if (!ok && ret) {
EVP_PKEY_free(ret);
ret = NULL;
}
EVP_PKEY_CTX_free(pkctx);
return ret;
}
static int test_evp_pkey_sign(EVP_PKEY *pkey, int do_sm2, int verbose)
{
int ret = 0;
EVP_PKEY_CTX *pkctx = NULL;
int type = do_sm2 ? NID_sm_scheme : NID_secg_scheme;
unsigned char dgst[EVP_MAX_MD_SIZE] = "hello world";
size_t dgstlen;
unsigned char sig[256];
size_t siglen;
if (!(pkctx = EVP_PKEY_CTX_new(pkey, NULL))) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
/* EVP_PKEY_sign() */
if (!EVP_PKEY_sign_init(pkctx)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!EVP_PKEY_CTX_set_ec_sign_type(pkctx, type)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
dgstlen = 32;
memset(sig, 0, sizeof(sig));
siglen = sizeof(sig);
if (!EVP_PKEY_sign(pkctx, sig, &siglen, dgst, dgstlen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (verbose > 1) {
size_t i;
printf("signature (%zu bytes) = ", siglen);
for (i = 0; i < siglen; i++) {
printf("%02X", sig[i]);
}
printf("\n");
}
if (!EVP_PKEY_verify_init(pkctx)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!EVP_PKEY_CTX_set_ec_sign_type(pkctx, type)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (1 != EVP_PKEY_verify(pkctx, sig, siglen, dgst, dgstlen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (verbose) {
printf("%s(%s) passed\n", __FUNCTION__, OBJ_nid2sn(type));
}
ret = 1;
end:
EVP_PKEY_CTX_free(pkctx);
return ret;
}
static int test_evp_pkey_encrypt(EVP_PKEY *pkey, int do_sm2, int verbose)
{
int ret = 0;
EVP_PKEY_CTX *pkctx = NULL;
int type = do_sm2 ? NID_sm_scheme : NID_secg_scheme;
unsigned char msg[] = "hello world this is the message";
size_t msglen = sizeof(msg);
unsigned char cbuf[512];
size_t cbuflen = sizeof(cbuf);
unsigned char mbuf[512];
size_t mbuflen = sizeof(mbuf);
if (!(pkctx = EVP_PKEY_CTX_new(pkey, NULL))) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
/* EVP_PKEY_encrypt() */
if (!EVP_PKEY_encrypt_init(pkctx)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!EVP_PKEY_CTX_set_ec_enc_type(pkctx, type)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
/* we need to set the sm2 encrypt params (hash = sm3) */
cbuflen = sizeof(cbuf);
if (!EVP_PKEY_encrypt(pkctx, cbuf, &cbuflen, msg, msglen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (verbose > 1) {
size_t i;
printf("ciphertext (%zu bytes) = ", cbuflen);
for (i = 0; i < cbuflen; i++) {
printf("%02X", cbuf[i]);
}
printf("\n");
}
if (!EVP_PKEY_decrypt_init(pkctx)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!EVP_PKEY_CTX_set_ec_enc_type(pkctx, type)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
memset(mbuf, 0, sizeof(mbuf));
mbuflen = sizeof(mbuf);
if (!EVP_PKEY_decrypt(pkctx, mbuf, &mbuflen, cbuf, cbuflen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (verbose > 1) {
printf("original message = %s\n", msg);
printf("decrypted message = %s\n", mbuf);
}
if (verbose) {
printf("%s(%s) passed\n", __FUNCTION__, OBJ_nid2sn(type));
}
ret = 1;
end:
ERR_print_errors_fp(stderr);
EVP_PKEY_CTX_free(pkctx);
return ret;
}
static int test_evp_pkey_encrypt_old(EVP_PKEY *pkey, int verbose)
{
int ret = 0;
unsigned char msg[] = "hello world this is the message";
size_t msglen = sizeof(msg);
unsigned char cbuf[512];
unsigned char mbuf[512];
int len;
if ((len = EVP_PKEY_encrypt_old(cbuf, msg, (int)msglen, pkey)) <= 0) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (verbose > 1) {
int i;
printf("ciphertext (%d bytes) = ", len);
for (i = 0; i < len; i++) {
printf("%02X", cbuf[i]);
}
printf("\n");
}
memset(mbuf, 0, sizeof(mbuf));
if ((len = EVP_PKEY_decrypt_old(mbuf, cbuf, len, pkey)) <= 0) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (verbose > 1) {
printf("original message = %s\n", msg);
printf("decrypted message = %s\n", mbuf);
}
if (verbose) {
printf("%s() passed!\n", __FUNCTION__);
}
ret = 1;
end:
return ret;
}
static int test_evp_sign(EVP_PKEY *pkey, const EVP_MD *md, int verbose)
{
int ret = 0;
EVP_MD_CTX *mdctx = NULL;
unsigned char msg[] = "hello world this is the message";
size_t msglen = sizeof(msg);
unsigned char sig[256];
unsigned int siglen = (unsigned int)sizeof(sig);
if (!(mdctx = EVP_MD_CTX_create())) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!EVP_SignInit_ex(mdctx, md, NULL)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!EVP_SignUpdate(mdctx, msg, msglen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!EVP_SignFinal(mdctx, sig, &siglen, pkey)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (verbose > 1) {
size_t i;
printf("signature (%u bytes) = ", siglen);
for (i = 0; i < siglen; i++) {
printf("%02X", sig[i]);
}
printf("\n");
}
if (!EVP_VerifyInit_ex(mdctx, md, NULL)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!EVP_VerifyUpdate(mdctx, msg, msglen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (1 != EVP_VerifyFinal(mdctx, sig, siglen, pkey)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (verbose) {
printf("%s() passed\n", __FUNCTION__);
}
ret = 1;
end:
EVP_MD_CTX_destroy(mdctx);
return ret;
}
static int test_evp_digestsign(EVP_PKEY *pkey, int do_sm2, const EVP_MD *md, int verbose)
{
int ret = 0;
EVP_MD_CTX *mdctx = NULL;
EVP_PKEY_CTX *pkctx;
int type = do_sm2 ? NID_sm_scheme : NID_secg_scheme;
unsigned char msg[] = "hello world this is the message";
size_t msglen = sizeof(msg);
unsigned char sig[256];
size_t siglen = (unsigned int)sizeof(sig);
unsigned char z[EVP_MAX_MD_SIZE];
if (!(mdctx = EVP_MD_CTX_create())) {
goto end;
}
pkctx = NULL;
if (!EVP_DigestSignInit(mdctx, &pkctx, md, NULL, pkey)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!EVP_PKEY_CTX_set_ec_sign_type(pkctx, type)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
/*
if (!EVP_PKEY_CTX_set_pre_update(pkctx, z, 32)) {
goto end;
}
*/
if (!EVP_DigestSignUpdate(mdctx, msg, msglen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
siglen = sizeof(sig);
if (!EVP_DigestSignFinal(mdctx, sig, &siglen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
pkctx = NULL;
if (!EVP_DigestVerifyInit(mdctx, &pkctx, md, NULL, pkey)) {
ERR_print_errors_fp(stderr);
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!EVP_PKEY_CTX_set_ec_sign_type(pkctx, type)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
/*
if (!EVP_PKEY_CTX_set_pre_update(pkctx, z, 32)) {
goto end;
}
*/
if (!EVP_DigestVerifyUpdate(mdctx, msg, msglen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!EVP_DigestVerifyFinal(mdctx, sig, siglen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (verbose) {
printf("%s() passed\n", __FUNCTION__);
}
ret = 1;
end:
EVP_MD_CTX_destroy(mdctx);
return ret;
}
#define NUM_PKEYS 3
#define MAX_PKEY_SIZE 1024
static int test_evp_seal(int curve_id, const EVP_CIPHER *cipher, BIO *out, int verbose)
{
int ret = 0;
EVP_PKEY *pkey[NUM_PKEYS] = {0};
EVP_CIPHER_CTX *cctx = NULL;
unsigned char iv[16];
unsigned char *ek[NUM_PKEYS] = {0};
int ekl[NUM_PKEYS];
unsigned char msg1[] = "Hello ";
unsigned char msg2[] = "World!";
unsigned char cbuf[256];
unsigned char mbuf[256];
unsigned char *p;
int len, clen, mlen, i;
for (i = 0; i < NUM_PKEYS; i++) {
if (!(pkey[i] = genpkey(curve_id, out, verbose))) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
ekl[i] = MAX_PKEY_SIZE;
ek[i] = OPENSSL_malloc(ekl[i]);
}
RAND_bytes(iv, sizeof(iv));
if (!(cctx = EVP_CIPHER_CTX_new())) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if ((i = EVP_SealInit(cctx, cipher, ek, ekl, iv, pkey, NUM_PKEYS)) != NUM_PKEYS) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (verbose > 1) {
for (i = 0; i < NUM_PKEYS; i++) {
int j;
BIO_printf(out, "ek[%d] (%d-byte) = ", i, ekl[i]);
for (j = 0; j < ekl[i]; j++) {
BIO_printf(out, "%02X", ek[i][j]);
}
BIO_printf(out, "\n");
}
}
p = cbuf;
len = sizeof(cbuf);
if (!EVP_SealUpdate(cctx, p, &len, msg1, sizeof(msg1)-1)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
p += len;
len = sizeof(cbuf) - (p - cbuf);
if (!EVP_SealUpdate(cctx, p, &len, msg2, sizeof(msg2)-1)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
p += len;
len = sizeof(cbuf) - (p - cbuf);
if (!EVP_SealFinal(cctx, p, &len)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
p += len;
clen = p - cbuf;
if (verbose > 1) {
BIO_printf(out, "ciphertext (%d-byte) = ", clen);
for (i = 0; i < clen; i++) {
BIO_printf(out, "%02X", cbuf[i]);
}
BIO_printf(out, "\n");
}
if (!EVP_OpenInit(cctx, cipher, ek[1], ekl[1], iv, pkey[1])) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
memset(mbuf, 0, sizeof(mbuf));
p = mbuf;
len = sizeof(mbuf);
if (!EVP_OpenUpdate(cctx, p, &len, cbuf, clen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
p += len;
len = sizeof(mbuf) - len;
if (!EVP_OpenFinal(cctx, p, &len)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
p += len;
mlen = p - mbuf;
if (verbose > 1) {
BIO_printf(out, "message = %s%s\n", (char *)msg1, (char *)msg2);
BIO_printf(out, "message = %s\n", (char *)mbuf);
}
if (verbose) {
BIO_printf(out, "%s() passed!\n", __FUNCTION__);
}
ret = 1;
end:
EVP_CIPHER_CTX_free(cctx);
for (i = 0; i < NUM_PKEYS; i++) {
EVP_PKEY_free(pkey[i]);
OPENSSL_free(ek[i]);
}
return ret;
}
int main(int argc, char **argv)
{
int err = 0;
int verbose = 2;
EVP_PKEY *pkey = NULL;
int curve_id = NID_sm2p256v1;
const EVP_MD *md = EVP_sm3();
const EVP_CIPHER *cipher = EVP_sms4_cbc();
BIO *out = NULL;
out = BIO_new_fp(stderr, BIO_NOCLOSE);
if (!(pkey = genpkey(curve_id, out, verbose))) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
//if (!test_evp_pkey_sign(pkey, 1, 0)) err++;
//if (!test_evp_pkey_sign(pkey, 0, 0)) err++;
if (!test_evp_pkey_encrypt(pkey, 1, verbose)) err++;
//if (!test_evp_pkey_encrypt(pkey, 0, verbose)) err++;
//if (!test_evp_pkey_encrypt_old(pkey, verbose)) err++;
//if (!test_evp_sign(pkey, md, 0)) err++;
//if (!test_evp_seal(curve_id, cipher, out, verbose)) err++;
//if (!test_evp_digestsign(pkey, 1, md, verbose)) err++;
end:
EVP_PKEY_free(pkey);
EXIT(err);
}
#endif

View File

@@ -177,7 +177,8 @@ static char *dgsthex[] = {
"26352AF82EC19F207BBC6F9474E11E90CE0F7DDACE03B27F801817E897A81FD5",
"E4D1D0C3CA4C7F11BC8FF8CB3F4C02A78F108FA098E51A668487240F75E20F31",
"6B4B6D0E276691BD4A11BF72F4FB501AE309FDACB72FA6CC336E6656119ABD67",
"ECF0080215977B2E5D6D61B98A99442F03E8803DC39E349F8DCA5621A9ACDF2B",
"329c2f6030cc7e0ca3af6c97b76243ca250338ad3d3dc3a8b322d1cfdf98c2b7",
/*"ECF0080215977B2E5D6D61B98A99442F03E8803DC39E349F8DCA5621A9ACDF2B",*/
"557BAD30E183559AEEC3B2256E1C7C11F870D22B165D015ACF9465B09B87B527",
"4D38D2958CA7FD2CFAE3AF04486959CF92C8EF48E8B83A05C112E739D5F181D0",
"C3B02E500A8B60B77DEDCF6F4C11BEF8D56E5CDE708C72065654FD7B2167915A",

View File

@@ -1,6 +1,56 @@
/* ====================================================================
* Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <openssl/e_os2.h>
#include <openssl/speck.h>
int main(int argc, char** argv)
@@ -10,19 +60,16 @@ int main(int argc, char** argv)
uint16_t plain16[2] = { 0x694c, 0x6574 };
uint16_t enc16[2] = { 0x42f2, 0xa868 };
uint32_t key32[4] = { 0x03020100, 0x0b0a0908, 0x13121110, 0x1b1a1918 };
uint32_t plain32[2] = { 0x7475432d, 0x3b726574 };
uint32_t enc32[2] = { 0x454e028b, 0x8c6fa548 };
uint64_t key64[4] = { 0x0706050403020100, 0x0f0e0d0c0b0a0908, 0x1716151413121110, 0x1f1e1d1c1b1a1918 };
uint64_t plain64[2] = { 0x202e72656e6f6f70, 0x65736f6874206e49 };
uint64_t enc64[2] = { 0x4eeeb48d9c188f43, 0x4109010405c0f53e };
SPECK_TYPE16 buffer[2] = { 0 };
SPECK_TYPE16 exp[SPECK_ROUNDS16];
uint16_t buffer[2] = { 0 };
uint16_t exp[SPECK_ROUNDS16];
speck_set_encrypt_key16(key16, exp);
speck_encrypt16(plain16, buffer, exp);
if (memcmp(buffer, enc16, sizeof(enc16)))
@@ -35,8 +82,8 @@ int main(int argc, char** argv)
sum++;
}
SPECK_TYPE32 exp32[SPECK_ROUNDS32];
SPECK_TYPE32 buffer32[2] = { 0 };
uint32_t exp32[SPECK_ROUNDS32];
uint32_t buffer32[2] = { 0 };
speck_set_encrypt_key32(key32, exp32);
speck_encrypt32(plain32, buffer32, exp32);
if (memcmp(buffer, enc32, sizeof(enc32)))
@@ -49,8 +96,8 @@ int main(int argc, char** argv)
sum++;
}
SPECK_TYPE64 exp64[SPECK_ROUNDS64];
SPECK_TYPE64 buffer64[2] = { 0 };
uint64_t exp64[SPECK_ROUNDS64];
uint64_t buffer64[2] = { 0 };
speck_set_encrypt_key64(key64, exp64);
speck_encrypt64(plain64, buffer64, exp64);
if (memcmp(buffer64, enc64, sizeof(enc64)))