@@ -12,7 +12,6 @@ int test_simple()
1212 uint32_t ciphertext_ok = 0xe44f4cdf ;
1313 uint32_t temp ;
1414
15-
1615 printf ("------- Simple test -------\r\n" );
1716
1817 temp = plaintext_ok ;
@@ -53,14 +52,13 @@ int test_normal()
5352
5453 // KEELOQ Key LSB-first
5554 uint8_t mf_key []= {0xef ,0xcd ,0xab ,0x89 ,0x67 ,0x45 ,0x23 ,0x01 };
56- uint8_t key [8 ];
5755 uint32_t ser = 0x6C46ACA ;
56+ uint8_t key [8 ];
5857
5958 uint32_t plaintext_ok = 0x1eca04b4 ;
6059 uint32_t ciphertext_ok = 0xecf4c92d ;
6160 uint32_t temp ;
6261
63-
6462 printf ("------- Normal test -------\r\n" );
6563
6664 temp = plaintext_ok ;
@@ -98,11 +96,63 @@ int test_normal()
9896 return err ;
9997}
10098
99+ int test_secure ()
100+ {
101+ int err = 0 ;
102+
103+ // KEELOQ Key LSB-first
104+ uint8_t mf_key []= {0xef ,0xcd ,0xab ,0x89 ,0x67 ,0x45 ,0x23 ,0x01 };
105+ uint32_t ser = 0x0B6AF9A8 ;
106+ uint32_t seed = 0x4380FD94 ;
107+ uint8_t key [8 ];
108+
109+ uint32_t plaintext_ok = 0x95874b2c ;
110+ uint32_t ciphertext_ok = 0xc9ebe007 ;
111+ uint32_t temp ;
112+
113+ printf ("------- Secure test -------\r\n" );
114+
115+ temp = plaintext_ok ;
116+
117+ printf ("Text=0x%08x\r\n" ,temp );
118+ printf ("N=%d\r\n" ,KEELOQ_NROUNDS );
119+
120+ // Generate normal key
121+ keeloq_gen_secure_key (key ,mf_key ,seed ,ser );
122+
123+ // Encrypt plaintext to ciphertext
124+ keeloq_encrypt (key ,& temp ,KEELOQ_NROUNDS );
125+
126+ printf ("Encrypted to 0x%08x " ,temp );
127+ if (temp == ciphertext_ok ) printf ("[ OK ]" );
128+ else
129+ {
130+ printf ("[ ERROR! ]" );
131+ err ++ ;
132+ }
133+ printf ("\r\n" );
134+
135+ // Decrypt ciphertext to plaintext
136+ keeloq_decrypt (key ,& temp ,KEELOQ_NROUNDS );
137+
138+ printf ("Decrypted to 0x%08x " ,temp );
139+ if (temp == plaintext_ok ) printf ("[ OK ]" );
140+ else
141+ {
142+ printf ("[ ERROR! ]" );
143+ err ++ ;
144+ }
145+ printf ("\r\n---------------------------\r\n" );
146+
147+ return err ;
148+ }
149+
101150int main ()
102151{
103152 int err = 0 ;
104153 err = test_simple ();
105154 err += test_normal ();
155+ err += test_secure ();
106156
107157 printf ("Test Status : " );
108158 if (err )printf ("FAIL!" );
0 commit comments