Skip to content

Commit 51930a9

Browse files
committed
fix test
1 parent e020518 commit 51930a9

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

test.c

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <stdio.h>
22
#include "keeloq.h"
33

4-
int test_normal()
4+
int test_simple()
55
{
66
int err=0;
77

@@ -13,13 +13,64 @@ int test_normal()
1313
uint32_t temp;
1414

1515

16+
printf("------- Simple test -------\r\n");
17+
18+
temp=plaintext_ok;
19+
20+
printf("Text=0x%08x\r\n",temp);
21+
printf("N=%d\r\n",KEELOQ_NROUNDS);
22+
23+
// Encrypt plaintext to ciphertext
24+
keeloq_encrypt(key,&temp,KEELOQ_NROUNDS);
25+
26+
printf("Encrypted to 0x%08x ",temp);
27+
if(temp==ciphertext_ok) printf("[ OK ]");
28+
else
29+
{
30+
printf("[ ERROR! ]");
31+
err++;
32+
}
33+
printf("\r\n");
34+
35+
// Decrypt ciphertext to plaintext
36+
keeloq_decrypt(key,&temp,KEELOQ_NROUNDS);
37+
38+
printf("Decrypted to 0x%08x ",temp);
39+
if(temp==plaintext_ok) printf("[ OK ]");
40+
else
41+
{
42+
printf("[ ERROR! ]");
43+
err++;
44+
}
45+
printf("\r\n---------------------------\r\n");
46+
47+
return err;
48+
}
49+
50+
int test_normal()
51+
{
52+
int err=0;
53+
54+
// KEELOQ Key LSB-first
55+
uint8_t mf_key[]={0xef,0xcd,0xab,0x89,0x67,0x45,0x23,0x01};
56+
uint8_t key[8];
57+
uint32_t ser=0x6C46ACA;
58+
59+
uint32_t plaintext_ok= 0x1eca04b4;
60+
uint32_t ciphertext_ok= 0xecf4c92d;
61+
uint32_t temp;
62+
63+
1664
printf("------- Normal test -------\r\n");
1765

1866
temp=plaintext_ok;
1967

2068
printf("Text=0x%08x\r\n",temp);
2169
printf("N=%d\r\n",KEELOQ_NROUNDS);
2270

71+
// Generate normal key
72+
keeloq_gen_normal_key(key,mf_key,ser);
73+
2374
// Encrypt plaintext to ciphertext
2475
keeloq_encrypt(key,&temp,KEELOQ_NROUNDS);
2576

@@ -42,20 +93,21 @@ int test_normal()
4293
printf("[ ERROR! ]");
4394
err++;
4495
}
45-
printf("\r\n-------------------------\r\n");
96+
printf("\r\n---------------------------\r\n");
4697

4798
return err;
4899
}
49100

50101
int main()
51102
{
52103
int err=0;
53-
err=test_normal();
104+
err= test_simple();
105+
err+=test_normal();
54106

55107
printf("Test Status : ");
56108
if(err)printf("FAIL!");
57109
else printf("PASS");
58-
printf("\r\n-------------------------\r\n");
110+
printf("\r\n---------------------------\r\n");
59111

60112
return err;
61113
}

0 commit comments

Comments
 (0)