mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-08 23:13:38 +08:00
Update specktest.c
change some wrong codes
This commit is contained in:
@@ -64,25 +64,36 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
#include <openssl/speck.h>
|
#include <openssl/speck.h>
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
speck_key_t key;
|
int sum = 0;
|
||||||
unsigned char userkey[2] = { 0x01, 0x02, };
|
#ifdef SPECK_32_64
|
||||||
unsigned char msg[2] = { 0xab, 0xcd, };
|
uint16_t key[4] = { 0x0100, 0x0908, 0x1110, 0x1918 };
|
||||||
SPECK_TYPE S[SPECK_ROUNDS];
|
uint16_t plain[2] = { 0x694c, 0x6574 };
|
||||||
|
uint16_t enc[2] = { 0x42f2, 0xa868 };
|
||||||
|
#endif
|
||||||
|
|
||||||
unsigned char cbuf[2];
|
#ifdef SPECK_64_128
|
||||||
unsigned char mbuf[2];
|
uint32_t key[4] = { 0x03020100, 0x0b0a0908, 0x13121110, 0x1b1a1918 };
|
||||||
|
uint32_t plain[2] = { 0x7475432d, 0x3b726574 };
|
||||||
|
uint32_t enc[2] = { 0x454e028b, 0x8c6fa548 };
|
||||||
|
#endif
|
||||||
|
|
||||||
speck_set_encrypt_key(&key, userkey);
|
#ifdef SPECK_128_256
|
||||||
speck_expand(&key, S);
|
uint64_t key[4] = { 0x0706050403020100, 0x0f0e0d0c0b0a0908, 0x1716151413121110, 0x1f1e1d1c1b1a1918 };
|
||||||
speck_encrypt(msg, cbuf, S);
|
uint64_t plain[2] = { 0x202e72656e6f6f70, 0x65736f6874206e49 };
|
||||||
speck_decrypt(cbuf, mbuf, S);
|
uint64_t enc[2] = { 0x4eeeb48d9c188f43, 0x4109010405c0f53e };
|
||||||
|
#endif
|
||||||
if (memcmp(msg, mbuf, 2)) {
|
SPECK_TYPE buffer[2] = { 0 };
|
||||||
return -1;
|
SPECK_TYPE exp[SPECK_ROUNDS];
|
||||||
|
speck_set_encrypt_key(key, exp);
|
||||||
|
speck_encrypt(plain, buffer, exp);
|
||||||
|
speck_decrypt(enc, buffer, exp);
|
||||||
|
if (memcmp(buffer, plain, sizeof(enc)))
|
||||||
|
{
|
||||||
|
sum++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return sum;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user