+void testrun_aes128_cfb8(void){
+ uint8_t key[16];
+ uint8_t iv[16];
+ uint8_t plain[64];
+
+ bcal_cfb_B_ctx_t ctx;
+ uint8_t r;
+
+ memcpy_P(key, modes_key, 16);
+ memcpy_P(iv, modes_iv, 16);
+ memcpy_P(plain, modes_plain, 64);
+
+ cli_putstr_P(PSTR("\r\n** AES128-CFB8-TEST **"));
+ r = bcal_cfb_B_init(&aes128_desc, key, 128, 8, &ctx);
+ cli_putstr_P(PSTR("\r\n init = 0x"));
+ cli_hexdump(&r, 1);
+ cli_putstr_P(PSTR("\r\n key: "));
+ cli_hexdump(key, 128/8);
+ cli_putstr_P(PSTR("\r\n IV: "));
+ cli_hexdump(iv, 128/8);
+ cli_putstr_P(PSTR("\r\n plaintext:"));
+ cli_hexdump_block(plain, 4*128/8, 4, 16);
+ if(r)
+ return;
+ bcal_cfb_B_encMsg(iv, plain, 64, &ctx);
+ cli_putstr_P(PSTR("\r\n ciphertext: "));
+ cli_hexdump_block(plain, 64, 4, 16);
+
+ bcal_cfb_B_decMsg(iv, plain, 64, &ctx);
+ cli_putstr_P(PSTR("\r\n plaintext: "));
+ cli_hexdump_block(plain, 64, 4, 16);
+
+ bcal_cfb_B_free(&ctx);
+
+}
+
+void testrun_aes128_cfb1(void){
+ uint8_t key[16];
+ uint8_t iv[16];
+ uint8_t plain[64];
+
+ bcal_cfb_b_ctx_t ctx;
+ uint8_t r;
+
+ memcpy_P(key, modes_key, 16);
+ memcpy_P(iv, modes_iv, 16);
+ memcpy_P(plain, modes_plain, 64);
+
+ cli_putstr_P(PSTR("\r\n** AES128-CFB1-TEST **"));
+ r = bcal_cfb_b_init(&aes128_desc, key, 128, 1, &ctx);
+ cli_putstr_P(PSTR("\r\n init = 0x"));
+ cli_hexdump(&r, 1);
+ cli_putstr_P(PSTR("\r\n key: "));
+ cli_hexdump(key, 128/8);
+ cli_putstr_P(PSTR("\r\n IV: "));
+ cli_hexdump(iv, 128/8);
+ cli_putstr_P(PSTR("\r\n plaintext:"));
+ cli_hexdump_block(plain, 2, 4, 16);
+ if(r)
+ return;
+ uint8_t i, bit_offset, byte_offset;
+ bcal_cfb_b_loadIV(iv, &ctx);
+ for(i=0; i<16; ++i){
+ byte_offset = i/8;
+ bit_offset = i&7;
+ cli_putstr_P(PSTR("\r\n plain bit: "));
+ cli_putc((plain[byte_offset]&(1<<(7-bit_offset)))?'1':'0');
+ bcal_cfb_b_encNext(plain+byte_offset, bit_offset, &ctx);
+ cli_putstr_P(PSTR("\r\n cipher bit: "));
+ cli_putc((plain[byte_offset]&(1<<(7-bit_offset)))?'1':'0');
+ }
+ cli_putstr_P(PSTR("\r\n ciphertext: "));
+ cli_hexdump_block(plain, 2, 4, 16);
+
+ bcal_cfb_b_loadIV(iv, &ctx);
+ for(i=0; i<16; ++i){
+ byte_offset = i/8;
+ bit_offset = i&7;
+ cli_putstr_P(PSTR("\r\n plain bit: "));
+ cli_putc((plain[byte_offset]&(1<<(7-bit_offset)))?'1':'0');
+ bcal_cfb_b_decNext(plain+byte_offset, bit_offset, &ctx);
+ cli_putstr_P(PSTR("\r\n cipher bit: "));
+ cli_putc((plain[byte_offset]&(1<<(7-bit_offset)))?'1':'0');
+ }
+ cli_putstr_P(PSTR("\r\n plaintext: "));
+ cli_hexdump_block(plain, 2, 4, 16);
+
+
+ bcal_cfb_b_encMsg(iv, plain, 0, 64*8, &ctx);
+ cli_putstr_P(PSTR("\r\n ciphertext: "));
+ cli_hexdump_block(plain, 64, 4, 16);
+
+ bcal_cfb_b_decMsg(iv, plain, 0, 64*8, &ctx);
+ cli_putstr_P(PSTR("\r\n plaintext: "));
+ cli_hexdump_block(plain, 64, 4, 16);
+
+ bcal_cfb_b_free(&ctx);
+}
+
+void testrun_aes128_ofb(void){
+ uint8_t key[16];
+ uint8_t iv[16];
+ uint8_t plain[64];
+
+ bcal_ofb_ctx_t ctx;
+ uint8_t r;
+
+ memcpy_P(key, modes_key, 16);
+ memcpy_P(iv, modes_iv, 16);
+ memcpy_P(plain, modes_plain, 64);
+
+ cli_putstr_P(PSTR("\r\n** AES128-OFB-TEST **"));
+ r = bcal_ofb_init(&aes128_desc, key, 128, &ctx);
+ cli_putstr_P(PSTR("\r\n init = 0x"));
+ cli_hexdump(&r, 1);
+ cli_putstr_P(PSTR("\r\n key: "));
+ cli_hexdump(key, 128/8);
+ cli_putstr_P(PSTR("\r\n IV: "));
+ cli_hexdump(iv, 128/8);
+ cli_putstr_P(PSTR("\r\n plaintext:"));
+ cli_hexdump_block(plain, 4*128/8, 4, 16);
+ if(r)
+ return;
+ bcal_ofb_encMsg(iv, plain, 4*128, &ctx);
+ cli_putstr_P(PSTR("\r\n ciphertext: "));
+ cli_hexdump_block(plain, 4*128/8, 4, 16);
+ bcal_ofb_decMsg(iv, plain, 4*128, &ctx);
+ cli_putstr_P(PSTR("\r\n plaintext: "));
+ cli_hexdump_block(plain, 4*128/8, 4, 16);
+ bcal_ofb_free(&ctx);
+}
+
+void testrun_aes128_ctr(void){
+ uint8_t key[16];
+ uint8_t iv[16];
+ uint8_t plain[64];
+
+ bcal_ctr_ctx_t ctx;
+ uint8_t r;
+
+ memcpy_P(key, modes_key, 16);
+ memcpy_P(iv, modes_ctriv, 16);
+ memcpy_P(plain, modes_plain, 64);
+
+ cli_putstr_P(PSTR("\r\n** AES128-CTR-TEST **"));
+ r = bcal_ctr_init(&aes128_desc, key, 128, NULL, &ctx);
+ cli_putstr_P(PSTR("\r\n init = 0x"));
+ cli_hexdump(&r, 1);
+ cli_putstr_P(PSTR("\r\n key: "));
+ cli_hexdump(key, 128/8);
+ cli_putstr_P(PSTR("\r\n IV: "));
+ cli_hexdump(iv, 128/8);
+ cli_putstr_P(PSTR("\r\n plaintext:"));
+ cli_hexdump_block(plain, 4*128/8, 4, 16);
+ if(r)
+ return;
+ bcal_ctr_encMsg(iv, plain, 4*128, &ctx);
+ cli_putstr_P(PSTR("\r\n ciphertext: "));
+ cli_hexdump_block(plain, 4*128/8, 4, 16);
+ bcal_ctr_decMsg(iv, plain, 4*128, &ctx);
+ cli_putstr_P(PSTR("\r\n plaintext: "));
+ cli_hexdump_block(plain, 4*128/8, 4, 16);
+ bcal_ctr_free(&ctx);
+}