Téma: [vyřešeno] AES-128-CTR šifrování
Dobrý den,
v rámci diplomové práce používám SDS-BIG a snažím se zprovoznit šifrování pomocí AES-128-CTR. Vytvořil jsem proto testovací program, který vychází z tohoto ukázkového kódu: http://wiki.merenienergie.cz/index.php/FULL-C_secure_httpget_example
#define HTTPGET_PLAINTEXT_FOR_B64_LIMIT (1056) // (which is 1063 rounded to closest multiply of 16)
#define ENCPROTOCOLhdrSIZE (23) // bytes
void HTTP_GET_SECURE_SEND_STRING_TO_WEB(char * PlaintextBuf) {
unsigned int b64len, clrLen, PlaintextLen;
unsigned int IV[2];
// setup IV = make sure it is a "number-used-once",
// we will use rand() here
IV[0] = rand() & 0x0FFFFFFF;
IV[1] = rand() & 0x0FFFFFFF;
PlaintextLen = strlen(PlaintextBuf);
if (PlaintextLen < 1) {
// failure
printf("Empty String Provided - failure\n");
return;
}
printf("PlaintextLen = %d\n", PlaintextLen);
printf("%x\n", (~0x0F));
PlaintextLen = (PlaintextLen +15) & (~0x0F);
printf("PlaintextLen = %d\n", PlaintextLen);
unsigned int LocalIV[2];
// copy IV to local-IV, as the local-IV will
// be modified in background by SDS_Crypto()
LocalIV[0] = IV[0];
LocalIV[1] = IV[1];
// encrypt
printf("Plain text: ");
for (int i = 0; i < PlaintextLen; i++) {
printf("%02x", PlaintextBuf[i]);
}
printf("\n");
if (SDS_crypto(0x10, (unsigned int *)LocalIV, (void *)PlaintextBuf, PlaintextLen) == 0) {
printf("SDS_crypto - failure\n");
return;
}
if (SDS_crypto(0x10, (unsigned int *)LocalIV, (void *)PlaintextBuf, PlaintextLen) == 1) {
printf("SDS_crypto - OK\n");
printf("Cipher text: ");
for (int i = 0; i < PlaintextLen; i++) {
printf("%02x", PlaintextBuf[i]);
}
printf("\n");
return;
}
// the encryption works over the very same single buffer,
// so at this moment the contents of 'PlaintextBuf' is encrypted
// and the 'PlaintextLen' is exactly the same (symmetrical-encryption)
}Pokud nechám šifrovací algoritmus XTEA (0x10), vše proběhne bez problému viz výpis z konzole:
EXAMPLE OF ENCRYPTED HTTP-GET FOR SECURE WEB-DELIVERY FROM SDS
PlaintextLen = 16
Plain text: 5344537c73333d610000000000000000
SDS_crypto - OK
Cipher text: 1e238633c4866ffc42bd29d1d8d98f70
Pokud ale (na starém firmware) změním algoritmus na AES, text se nezašifruje (funkce SDS_crypto vrátí nulu). Předpokládám, že musím nějak změnit Counter Block, který je u AES 128-bit a inkrementuje se pouze posledních 32 bitů. Mohli byste sem prosím dát nějaký příklad, kde je šifrování provedeno pomocí AES-128-CTR a kód pro sestavení Counter Blocku?
Díky