int main(int argc, char *argv[]) { int i, n, err = 0; RC5_32_KEY key; unsigned char buf[8], buf2[8], ivb[8]; for (n = 0; n < 5; n++) { RC5_32_set_key(&key, 16, &(RC5key[n][0]), 12); RC5_32_ecb_encrypt(&(RC5plain[n][0]), buf, &key, RC5_ENCRYPT); if (memcmp(&(RC5cipher[n][0]), buf, 8) != 0) { printf("ecb RC5 error encrypting (%d)\n", n + 1); printf("got :"); for (i = 0; i < 8; i++) printf("%02X ", buf[i]); printf("\n"); printf("expected:"); for (i = 0; i < 8; i++) printf("%02X ", RC5cipher[n][i]); err = 20; printf("\n"); } RC5_32_ecb_encrypt(buf, buf2, &key, RC5_DECRYPT); if (memcmp(&(RC5plain[n][0]), buf2, 8) != 0) { printf("ecb RC5 error decrypting (%d)\n", n + 1); printf("got :"); for (i = 0; i < 8; i++) printf("%02X ", buf2[i]); printf("\n"); printf("expected:"); for (i = 0; i < 8; i++) printf("%02X ", RC5plain[n][i]); printf("\n"); err = 3; } } if (err == 0) printf("ecb RC5 ok\n"); for (n = 0; n < RC5_CBC_NUM; n++) { i = rc5_cbc_rounds[n]; if (i < 8) continue; RC5_32_set_key(&key, rc5_cbc_key[n][0], &(rc5_cbc_key[n][1]), i); memcpy(ivb, &(rc5_cbc_iv[n][0]), 8); RC5_32_cbc_encrypt(&(rc5_cbc_plain[n][0]), buf, 8, &key, &(ivb[0]), RC5_ENCRYPT); if (memcmp(&(rc5_cbc_cipher[n][0]), buf, 8) != 0) { printf("cbc RC5 error encrypting (%d)\n", n + 1); printf("got :"); for (i = 0; i < 8; i++) printf("%02X ", buf[i]); printf("\n"); printf("expected:"); for (i = 0; i < 8; i++) printf("%02X ", rc5_cbc_cipher[n][i]); err = 30; printf("\n"); } memcpy(ivb, &(rc5_cbc_iv[n][0]), 8); RC5_32_cbc_encrypt(buf, buf2, 8, &key, &(ivb[0]), RC5_DECRYPT); if (memcmp(&(rc5_cbc_plain[n][0]), buf2, 8) != 0) { printf("cbc RC5 error decrypting (%d)\n", n + 1); printf("got :"); for (i = 0; i < 8; i++) printf("%02X ", buf2[i]); printf("\n"); printf("expected:"); for (i = 0; i < 8; i++) printf("%02X ", rc5_cbc_plain[n][i]); printf("\n"); err = 3; } } if (err == 0) printf("cbc RC5 ok\n"); EXIT(err); return (err); }
int ssl_test_rc5(int argc, char *argv[]) { int i,n,err=0; RC5_32_KEY key; unsigned char buf[8],buf2[8],ivb[8]; for (n=0; n<5; n++) { RC5_32_set_key(&key,16,&(RC5key[n][0]),12); RC5_32_ecb_encrypt(&(RC5plain[n][0]),buf,&key,RC5_ENCRYPT); if (TINYCLR_SSL_MEMCMP(&(RC5cipher[n][0]),buf,8) != 0) { TINYCLR_SSL_PRINTF("ecb RC5 error encrypting (%d)\n",n+1); TINYCLR_SSL_PRINTF("got :"); for (i=0; i<8; i++) TINYCLR_SSL_PRINTF("%02X ",buf[i]); TINYCLR_SSL_PRINTF("\n"); TINYCLR_SSL_PRINTF("expected:"); for (i=0; i<8; i++) TINYCLR_SSL_PRINTF("%02X ",RC5cipher[n][i]); err=20; TINYCLR_SSL_PRINTF("\n"); } RC5_32_ecb_encrypt(buf,buf2,&key,RC5_DECRYPT); if (TINYCLR_SSL_MEMCMP(&(RC5plain[n][0]),buf2,8) != 0) { TINYCLR_SSL_PRINTF("ecb RC5 error decrypting (%d)\n",n+1); TINYCLR_SSL_PRINTF("got :"); for (i=0; i<8; i++) TINYCLR_SSL_PRINTF("%02X ",buf2[i]); TINYCLR_SSL_PRINTF("\n"); TINYCLR_SSL_PRINTF("expected:"); for (i=0; i<8; i++) TINYCLR_SSL_PRINTF("%02X ",RC5plain[n][i]); TINYCLR_SSL_PRINTF("\n"); err=3; } } if (err == 0) TINYCLR_SSL_PRINTF("ecb RC5 ok\n"); for (n=0; n<RC5_CBC_NUM; n++) { i=rc5_cbc_rounds[n]; if (i < 8) continue; RC5_32_set_key(&key,rc5_cbc_key[n][0],&(rc5_cbc_key[n][1]),i); TINYCLR_SSL_MEMCPY(ivb,&(rc5_cbc_iv[n][0]),8); RC5_32_cbc_encrypt(&(rc5_cbc_plain[n][0]),buf,8, &key,&(ivb[0]),RC5_ENCRYPT); if (TINYCLR_SSL_MEMCMP(&(rc5_cbc_cipher[n][0]),buf,8) != 0) { TINYCLR_SSL_PRINTF("cbc RC5 error encrypting (%d)\n",n+1); TINYCLR_SSL_PRINTF("got :"); for (i=0; i<8; i++) TINYCLR_SSL_PRINTF("%02X ",buf[i]); TINYCLR_SSL_PRINTF("\n"); TINYCLR_SSL_PRINTF("expected:"); for (i=0; i<8; i++) TINYCLR_SSL_PRINTF("%02X ",rc5_cbc_cipher[n][i]); err=30; TINYCLR_SSL_PRINTF("\n"); } TINYCLR_SSL_MEMCPY(ivb,&(rc5_cbc_iv[n][0]),8); RC5_32_cbc_encrypt(buf,buf2,8, &key,&(ivb[0]),RC5_DECRYPT); if (TINYCLR_SSL_MEMCMP(&(rc5_cbc_plain[n][0]),buf2,8) != 0) { TINYCLR_SSL_PRINTF("cbc RC5 error decrypting (%d)\n",n+1); TINYCLR_SSL_PRINTF("got :"); for (i=0; i<8; i++) TINYCLR_SSL_PRINTF("%02X ",buf2[i]); TINYCLR_SSL_PRINTF("\n"); TINYCLR_SSL_PRINTF("expected:"); for (i=0; i<8; i++) TINYCLR_SSL_PRINTF("%02X ",rc5_cbc_plain[n][i]); TINYCLR_SSL_PRINTF("\n"); err=3; } } if (err == 0) TINYCLR_SSL_PRINTF("cbc RC5 ok\n"); return(err); }