@@ -150,6 +150,42 @@ void BluetoothCryptoToolbox::testAh()
150150 printBytes (ourResult, 3 );
151151}
152152
153+ int BluetoothCryptoToolbox::g2 (uint8_t U[], uint8_t V[], uint8_t X[], uint8_t Y[], uint8_t out[4 ])
154+ {
155+ struct __attribute__ ((packed)) CmacInput {
156+ uint8_t U[32 ];
157+ uint8_t V[32 ];
158+ uint8_t Y[16 ];
159+ } cmacInput= {0 ,0 ,0 };
160+ memcpy (cmacInput.U ,U,32 );
161+ memcpy (cmacInput.V ,V,32 );
162+ memcpy (cmacInput.Y ,Y,16 );
163+ uint8_t intermediate[16 ];
164+ AES_CMAC (X,(uint8_t *)&cmacInput,sizeof (CmacInput),intermediate);
165+ memcpy (out,&intermediate[12 ],4 );
166+ return 1 ;
167+ }
168+ void BluetoothCryptoToolbox::testg2 (){
169+ uint8_t U[32 ] = {0x20 ,0xb0 ,0x03 ,0xd2 ,0xf2 ,0x97 ,0xbe ,0x2c ,0x5e ,0x2c ,0x83 ,0xa7 ,0xe9 ,0xf9 ,0xa5 ,0xb9 ,0xef ,0xf4 ,0x91 ,0x11 ,0xac ,0xf4 ,0xfd ,0xdb ,0xcc ,0x03 ,0x01 ,0x48 ,0x0e ,0x35 ,0x9d ,0xe6 };
170+ uint8_t V[32 ] = {0x55 ,0x18 ,0x8b ,0x3d ,0x32 ,0xf6 ,0xbb ,0x9a ,0x90 ,0x0a ,0xfc ,0xfb ,0xee ,0xd4 ,0xe7 ,0x2a ,0x59 ,0xcb ,0x9a ,0xc2 ,0xf1 ,0x9d ,0x7c ,0xfb ,0x6b ,0x4f ,0xdd ,0x49 ,0xf4 ,0x7f ,0xc5 ,0xfd };
171+ uint8_t X[16 ] = {0xd5 ,0xcb ,0x84 ,0x54 ,0xd1 ,0x77 ,0x73 ,0x3e ,0xff ,0xff ,0xb2 ,0xec ,0x71 ,0x2b ,0xae ,0xab };
172+ uint8_t Y[16 ] = {0xa6 ,0xe8 ,0xe7 ,0xcc ,0x25 ,0xa7 ,0x5f ,0x6e ,0x21 ,0x65 ,0x83 ,0xf7 ,0xff ,0x3d ,0xc4 ,0xcf };
173+ uint8_t AES[16 ] = {0x15 ,0x36 ,0xd1 ,0x8d ,0xe3 ,0xd2 ,0x0d ,0xf9 ,0x9b ,0x70 ,0x44 ,0xc1 ,0x2f ,0x9e ,0xd5 ,0xba };
174+ uint8_t out[4 ];
175+
176+
177+ uint32_t expected = 0 ;
178+ g2 (U,V,X,Y,out);
179+ uint32_t result = 0 ;
180+ for (int i=0 ; i<4 ; i++) result += out[i] << 8 *i;
181+
182+ Serial.print (" Expected : " );
183+ Serial.println (expected);
184+ Serial.print (" Result : " );
185+ Serial.println (result);
186+ Serial.println ();
187+
188+ }
153189
154190void BluetoothCryptoToolbox::AES_CMAC ( unsigned char *key, unsigned char *input, int length,
155191 unsigned char *mac )
0 commit comments