Newsgroup: it.comp.sicurezza.crittografia
Titolo: [forse OT] calcolo digest

sto facendo una valutazione di alcune funzioni hash e vorrei sapere, se non 
sono OT, più o meno quante sono le operazioni in virgola mobile che un 
processore deve effettuare per il calcolo di un digest (diciamo con lo 
SHA-1); o, in altri termini, potrebbe essermi utile anche il numero di 
istruzioni.
    grazie 


Non sei OT.
Tutte le operazioni sono fatte tra numeri interi (quindi nessuna operazione
in virgola mobile) e il numero di istruzioni dipende dalla lunghezza del
file del quale devi calcolare il digest (più è lungo, più sono le istruzioni
da eseguire).
Cristiano

 da eseguire).
Ok... ragionevole, allora qual è il numero di istruzioni da eseguire per un 
singolo blocco? (credo 512 bit nel caso di md5) 

 singolo blocco? (credo 512 bit nel caso di md5) 
Questo è un singolo blocco di SHA-1, MD5 non ce l'ho sotto mano ma so
che è più rapido, quindi consideralo un "limite superiore"...
245 +
320 -
320 <<
320 >>>
360 ^
60 &
360 |
Se non ho sbalgiato a contare, giudica tu stesso:
protected final void update_buffers() {
    for (int j = 16; j < 80; j++) {
        W[j] = W[j - 3] ^ W[j - 8] ^ W[j - 14] ^ W[j - 16];
        W[j] = (W[j] << 1) | (W[j] >>> 31);
    }
    int A = H[0], B = H[1], C = H[2], D = H[3], E = H[4];
    E += W[ 0] + ((A << 5) | (A >>> 27)) + (D ^ (B & (C ^ D))) +
    0x5A827999; B = (B << 30) | (B >>> 2);
    D += W[ 1] + ((E << 5) | (E >>> 27)) + (C ^ (A & (B ^ C))) +
    0x5A827999; A = (A << 30) | (A >>> 2);
    C += W[ 2] + ((D << 5) | (D >>> 27)) + (B ^ (E & (A ^ B))) +
    0x5A827999; E = (E << 30) | (E >>> 2);
    B += W[ 3] + ((C << 5) | (C >>> 27)) + (A ^ (D & (E ^ A))) +
    0x5A827999; D = (D << 30) | (D >>> 2);
    A += W[ 4] + ((B << 5) | (B >>> 27)) + (E ^ (C & (D ^ E))) +
    0x5A827999; C = (C << 30) | (C >>> 2);
    E += W[ 5] + ((A << 5) | (A >>> 27)) + (D ^ (B & (C ^ D))) +
    0x5A827999; B = (B << 30) | (B >>> 2);
    D += W[ 6] + ((E << 5) | (E >>> 27)) + (C ^ (A & (B ^ C))) +
    0x5A827999; A = (A << 30) | (A >>> 2);
    C += W[ 7] + ((D << 5) | (D >>> 27)) + (B ^ (E & (A ^ B))) +
    0x5A827999; E = (E << 30) | (E >>> 2);
    B += W[ 8] + ((C << 5) | (C >>> 27)) + (A ^ (D & (E ^ A))) +
    0x5A827999; D = (D << 30) | (D >>> 2);
    A += W[ 9] + ((B << 5) | (B >>> 27)) + (E ^ (C & (D ^ E))) +
    0x5A827999; C = (C << 30) | (C >>> 2);
    E += W[10] + ((A << 5) | (A >>> 27)) + (D ^ (B & (C ^ D))) +
    0x5A827999; B = (B << 30) | (B >>> 2);
    D += W[11] + ((E << 5) | (E >>> 27)) + (C ^ (A & (B ^ C))) +
    0x5A827999; A = (A << 30) | (A >>> 2);
    C += W[12] + ((D << 5) | (D >>> 27)) + (B ^ (E & (A ^ B))) +
    0x5A827999; E = (E << 30) | (E >>> 2);
    B += W[13] + ((C << 5) | (C >>> 27)) + (A ^ (D & (E ^ A))) +
    0x5A827999; D = (D << 30) | (D >>> 2);
    A += W[14] + ((B << 5) | (B >>> 27)) + (E ^ (C & (D ^ E))) +
    0x5A827999; C = (C << 30) | (C >>> 2);
    E += W[15] + ((A << 5) | (A >>> 27)) + (D ^ (B & (C ^ D))) +
    0x5A827999; B = (B << 30) | (B >>> 2);
    D += W[16] + ((E << 5) | (E >>> 27)) + (C ^ (A & (B ^ C))) +
    0x5A827999; A = (A << 30) | (A >>> 2);
    C += W[17] + ((D << 5) | (D >>> 27)) + (B ^ (E & (A ^ B))) +
    0x5A827999; E = (E << 30) | (E >>> 2);
    B += W[18] + ((C << 5) | (C >>> 27)) + (A ^ (D & (E ^ A))) +
    0x5A827999; D = (D << 30) | (D >>> 2);
    A += W[19] + ((B << 5) | (B >>> 27)) + (E ^ (C & (D ^ E))) +
    0x5A827999; C = (C << 30) | (C >>> 2);
    E += W[20] + ((A << 5) | (A >>> 27)) + (B ^ C ^ D) +
    0x6ED9EBA1; B = (B << 30) | (B >>> 2);
    D += W[21] + ((E << 5) | (E >>> 27)) + (A ^ B ^ C) +
    0x6ED9EBA1; A = (A << 30) | (A >>> 2);
    C += W[22] + ((D << 5) | (D >>> 27)) + (E ^ A ^ B) +
    0x6ED9EBA1; E = (E << 30) | (E >>> 2);
    B += W[23] + ((C << 5) | (C >>> 27)) + (D ^ E ^ A) +
    0x6ED9EBA1; D = (D << 30) | (D >>> 2);
    A += W[24] + ((B << 5) | (B >>> 27)) + (C ^ D ^ E) +
    0x6ED9EBA1; C = (C << 30) | (C >>> 2);
    E += W[25] + ((A << 5) | (A >>> 27)) + (B ^ C ^ D) +
    0x6ED9EBA1; B = (B << 30) | (B >>> 2);
    D += W[26] + ((E << 5) | (E >>> 27)) + (A ^ B ^ C) +
    0x6ED9EBA1; A = (A << 30) | (A >>> 2);
    C += W[27] + ((D << 5) | (D >>> 27)) + (E ^ A ^ B) +
    0x6ED9EBA1; E = (E << 30) | (E >>> 2);
    B += W[28] + ((C << 5) | (C >>> 27)) + (D ^ E ^ A) +
    0x6ED9EBA1; D = (D << 30) | (D >>> 2);
    A += W[29] + ((B << 5) | (B >>> 27)) + (C ^ D ^ E) +
    0x6ED9EBA1; C = (C << 30) | (C >>> 2);
    E += W[30] + ((A << 5) | (A >>> 27)) + (B ^ C ^ D) +
    0x6ED9EBA1; B = (B << 30) | (B >>> 2);
    D += W[31] + ((E << 5) | (E >>> 27)) + (A ^ B ^ C) +
    0x6ED9EBA1; A = (A << 30) | (A >>> 2);
    C += W[32] + ((D << 5) | (D >>> 27)) + (E ^ A ^ B) +
    0x6ED9EBA1; E = (E << 30) | (E >>> 2);
    B += W[33] + ((C << 5) | (C >>> 27)) + (D ^ E ^ A) +
    0x6ED9EBA1; D = (D << 30) | (D >>> 2);
    A += W[34] + ((B << 5) | (B >>> 27)) + (C ^ D ^ E) +
    0x6ED9EBA1; C = (C << 30) | (C >>> 2);
    E += W[35] + ((A << 5) | (A >>> 27)) + (B ^ C ^ D) +
    0x6ED9EBA1; B = (B << 30) | (B >>> 2);
    D += W[36] + ((E << 5) | (E >>> 27)) + (A ^ B ^ C) +
    0x6ED9EBA1; A = (A << 30) | (A >>> 2);
    C += W[37] + ((D << 5) | (D >>> 27)) + (E ^ A ^ B) +
    0x6ED9EBA1; E = (E << 30) | (E >>> 2);
    B += W[38] + ((C << 5) | (C >>> 27)) + (D ^ E ^ A) +
    0x6ED9EBA1; D = (D << 30) | (D >>> 2);
    A += W[39] + ((B << 5) | (B >>> 27)) + (C ^ D ^ E) +
    0x6ED9EBA1; C = (C << 30) | (C >>> 2);
    E += W[40] + ((A << 5) | (A >>> 27)) + ((B & (C | D)) | (C & D)) +
    0x8F1BBCDC; B = (B << 30) | (B >>> 2);
    D += W[41] + ((E << 5) | (E >>> 27)) + ((A & (B | C)) | (B & C)) +
    0x8F1BBCDC; A = (A << 30) | (A >>> 2);
    C += W[42] + ((D << 5) | (D >>> 27)) + ((E & (A | B)) | (A & B)) +
    0x8F1BBCDC; E = (E << 30) | (E >>> 2);
    B += W[43] + ((C << 5) | (C >>> 27)) + ((D & (E | A)) | (E & A)) +
    0x8F1BBCDC; D = (D << 30) | (D >>> 2);
    A += W[44] + ((B << 5) | (B >>> 27)) + ((C & (D | E)) | (D & E)) +
    0x8F1BBCDC; C = (C << 30) | (C >>> 2);
    E += W[45] + ((A << 5) | (A >>> 27)) + ((B & (C | D)) | (C & D)) +
    0x8F1BBCDC; B = (B << 30) | (B >>> 2);
    D += W[46] + ((E << 5) | (E >>> 27)) + ((A & (B | C)) | (B & C)) +
    0x8F1BBCDC; A = (A << 30) | (A >>> 2);
    C += W[47] + ((D << 5) | (D >>> 27)) + ((E & (A | B)) | (A & B)) +
    0x8F1BBCDC; E = (E << 30) | (E >>> 2);
    B += W[48] + ((C << 5) | (C >>> 27)) + ((D & (E | A)) | (E & A)) +
    0x8F1BBCDC; D = (D << 30) | (D >>> 2);
    A += W[49] + ((B << 5) | (B >>> 27)) + ((C & (D | E)) | (D & E)) +
    0x8F1BBCDC; C = (C << 30) | (C >>> 2);
    E += W[50] + ((A << 5) | (A >>> 27)) + ((B & (C | D)) | (C & D)) +
    0x8F1BBCDC; B = (B << 30) | (B >>> 2);
    D += W[51] + ((E << 5) | (E >>> 27)) + ((A & (B | C)) | (B & C)) +
    0x8F1BBCDC; A = (A << 30) | (A >>> 2);
    C += W[52] + ((D << 5) | (D >>> 27)) + ((E & (A | B)) | (A & B)) +
    0x8F1BBCDC; E = (E << 30) | (E >>> 2);
    B += W[53] + ((C << 5) | (C >>> 27)) + ((D & (E | A)) | (E & A)) +
    0x8F1BBCDC; D = (D << 30) | (D >>> 2);
    A += W[54] + ((B << 5) | (B >>> 27)) + ((C & (D | E)) | (D & E)) +
    0x8F1BBCDC; C = (C << 30) | (C >>> 2);
    E += W[55] + ((A << 5) | (A >>> 27)) + ((B & (C | D)) | (C & D)) +
    0x8F1BBCDC; B = (B << 30) | (B >>> 2);
    D += W[56] + ((E << 5) | (E >>> 27)) + ((A & (B | C)) | (B & C)) +
    0x8F1BBCDC; A = (A << 30) | (A >>> 2);
    C += W[57] + ((D << 5) | (D >>> 27)) + ((E & (A | B)) | (A & B)) +
    0x8F1BBCDC; E = (E << 30) | (E >>> 2);
    B += W[58] + ((C << 5) | (C >>> 27)) + ((D & (E | A)) | (E & A)) +
    0x8F1BBCDC; D = (D << 30) | (D >>> 2);
    A += W[59] + ((B << 5) | (B >>> 27)) + ((C & (D | E)) | (D & E)) +
    0x8F1BBCDC; C = (C << 30) | (C >>> 2);
    E += W[60] + ((A << 5) | (A >>> 27)) + (B ^ C ^ D) +
    0xCA62C1D6; B = (B << 30) | (B >>> 2);
    D += W[61] + ((E << 5) | (E >>> 27)) + (A ^ B ^ C) +
    0xCA62C1D6; A = (A << 30) | (A >>> 2);
    C += W[62] + ((D << 5) | (D >>> 27)) + (E ^ A ^ B) +
    0xCA62C1D6; E = (E << 30) | (E >>> 2);
    B += W[63] + ((C << 5) | (C >>> 27)) + (D ^ E ^ A) +
    0xCA62C1D6; D = (D << 30) | (D >>> 2);
    A += W[64] + ((B << 5) | (B >>> 27)) + (C ^ D ^ E) +
    0xCA62C1D6; C = (C << 30) | (C >>> 2);
    E += W[65] + ((A << 5) | (A >>> 27)) + (B ^ C ^ D) +
    0xCA62C1D6; B = (B << 30) | (B >>> 2);
    D += W[66] + ((E << 5) | (E >>> 27)) + (A ^ B ^ C) +
    0xCA62C1D6; A = (A << 30) | (A >>> 2);
    C += W[67] + ((D << 5) | (D >>> 27)) + (E ^ A ^ B) +
    0xCA62C1D6; E = (E << 30) | (E >>> 2);
    B += W[68] + ((C << 5) | (C >>> 27)) + (D ^ E ^ A) +
    0xCA62C1D6; D = (D << 30) | (D >>> 2);
    A += W[69] + ((B << 5) | (B >>> 27)) + (C ^ D ^ E) +
    0xCA62C1D6; C = (C << 30) | (C >>> 2);
    E += W[70] + ((A << 5) | (A >>> 27)) + (B ^ C ^ D) +
    0xCA62C1D6; B = (B << 30) | (B >>> 2);
    D += W[71] + ((E << 5) | (E >>> 27)) + (A ^ B ^ C) +
    0xCA62C1D6; A = (A << 30) | (A >>> 2);
    C += W[72] + ((D << 5) | (D >>> 27)) + (E ^ A ^ B) +
    0xCA62C1D6; E = (E << 30) | (E >>> 2);
    B += W[73] + ((C << 5) | (C >>> 27)) + (D ^ E ^ A) +
    0xCA62C1D6; D = (D << 30) | (D >>> 2);
    A += W[74] + ((B << 5) | (B >>> 27)) + (C ^ D ^ E) +
    0xCA62C1D6; C = (C << 30) | (C >>> 2);
    E += W[75] + ((A << 5) | (A >>> 27)) + (B ^ C ^ D) +
    0xCA62C1D6; B = (B << 30) | (B >>> 2);
    D += W[76] + ((E << 5) | (E >>> 27)) + (A ^ B ^ C) +
    0xCA62C1D6; A = (A << 30) | (A >>> 2);
    C += W[77] + ((D << 5) | (D >>> 27)) + (E ^ A ^ B) +
    0xCA62C1D6; E = (E << 30) | (E >>> 2);
    B += W[78] + ((C << 5) | (C >>> 27)) + (D ^ E ^ A) +
    0xCA62C1D6; D = (D << 30) | (D >>> 2);
    A += W[79] + ((B << 5) | (B >>> 27)) + (C ^ D ^ E) +
    0xCA62C1D6; C = (C << 30) | (C >>> 2);
    H[0] += A;
    H[1] += B;
    H[2] += C;
    H[3] += D;
    H[4] += E;
}
- --
L a p o   L u c h i n i
l a p o @ l a p o . i t
w w w . l a p o . i t /
http://www.megatokyo.it
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Cygwin)
Comment: Using GnuPG with Thunderbird - 
http://enigmail.mozdev.org
iEYEARECAAYFAkGsG7oACgkQaJiCLMjyUvtlNwCfY3Rzgl7mq1q/WCeucIoE0Th8
oVIAn2Pst/FiQE4yOWrrWBZ+6QNnrEi1
=fzFu
-----END PGP SIGNATURE-----

>>
&
|
?????
Grazie

>> shift right (a >>> b circa uguale a a*-2^b)
^ xor bit a bit
& and bit a bit
| or bit a bit
Da notare che tutte queste in genere occupano il minimo clock possibile
della CPU... su 386 ricordo esplicitamente che erano operazioni da 1
clock, sulle moderne CPU pipelinate nno saprei, ma sicuramente molto poco.
Lapo
- --
L a p o   L u c h i n i
l a p o @ l a p o . i t
w w w . l a p o . i t /
http://www.megatokyo.it
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Cygwin)
Comment: Using GnuPG with Thunderbird - 
http://enigmail.mozdev.org
iEYEARECAAYFAkGu7NMACgkQaJiCLMjyUvuBkQCgkQIPcldiIPIV3oukq8ITWYLd
GvwAoO3yVvbrxGoDRBRa1fMHh66gXhN3
=Mftv
-----END PGP SIGNATURE-----