/** * \brief Decrypts a 32-bit word using Acorn128. * * \param state The state for the Acorn128 cipher. * \param ciphertext The ciphertext word. * * \return The plaintext word. */ static inline uint32_t acornDecrypt32(Acorn128State *state, uint32_t ciphertext) { // Extract out various sub-parts of the state as 32-bit words. #define s_extract_32(name, shift) \ ((state->name##_l >> (shift)) | \ (((uint32_t)(state->name##_h)) << (32 - (shift)))) uint32_t s244 = s_extract_32(s6, 14); uint32_t s235 = s_extract_32(s6, 5); uint32_t s196 = s_extract_32(s5, 3); uint32_t s160 = s_extract_32(s4, 6); uint32_t s111 = s_extract_32(s3, 4); uint32_t s66 = s_extract_32(s2, 5); uint32_t s23 = s_extract_32(s1, 23); uint32_t s12 = s_extract_32(s1, 12); // Update the LFSR's. uint32_t s7_l = state->s7 ^ s235 ^ state->s6_l; state->s6_l ^= s196 ^ state->s5_l; state->s5_l ^= s160 ^ state->s4_l; state->s4_l ^= s111 ^ state->s3_l; state->s3_l ^= s66 ^ state->s2_l; state->s2_l ^= s23 ^ state->s1_l; // Generate the next 32 keystream bits and decrypt the ciphertext. // k = S[12] ^ S[154] ^ maj(S[235], S[61], S[193]) // ^ ch(S[230], S[111], S[66]) uint32_t ks = s12 ^ state->s4_l ^ maj(s235, state->s2_l, state->s5_l) ^ ch(state->s6_l, s111, s66); uint32_t plaintext = ciphertext ^ ks; // Generate the next 32 non-linear feedback bits. // f = S[0] ^ ~S[107] ^ maj(S[244], S[23], S[160]) // ^ (ca & S[196]) ^ (cb & ks) // f ^= plaintext // Note: ca will always be 1 and cb will always be 0. uint32_t f = state->s1_l ^ (~state->s3_l) ^ maj(s244, s23, s160) ^ s196; f ^= plaintext; // Shift the state downwards by 32 bits. #define s_shift_32(name1, name2, shift) \ (state->name1##_l = state->name1##_h | (state->name2##_l << (shift)), \ state->name1##_h = (state->name2##_l >> (32 - (shift)))) s7_l ^= (f << 4); state->s7 = (uint8_t)(f >> 28); s_shift_32(s1, s2, 29); s_shift_32(s2, s3, 14); s_shift_32(s3, s4, 15); s_shift_32(s4, s5, 7); s_shift_32(s5, s6, 5); state->s6_l = state->s6_h | (s7_l << 27); state->s6_h = s7_l >> 5; // Return the plaintext word to the caller. return plaintext; }
void sha256::transform( const void *m, size_t block_nb ) { const uint8_t *msg = reinterpret_cast<const uint8_t*>( m ); uint32_t w[64]; uint32_t wv[8]; uint32_t t1, t2; const uint8_t *sub_block; for ( size_t i = 0; i < block_nb; i++ ) { sub_block = msg + ( i << 6 ); for ( size_t j = 0; j < 16; j++ ) pack32( &sub_block[j << 2], w[j] ); for ( size_t j = 16; j < 64; j++ ) w[j] = f4( w[j - 2] ) + w[j - 7] + f3( w[j - 15] ) + w[j - 16]; for ( size_t j = 0; j < 8; j++ ) wv[j] = _hash[j]; for ( size_t j = 0; j < 64; j++ ) { t1 = wv[7] + f2( wv[4] ) + ch( wv[4], wv[5], wv[6] ) + K[j] + w[j]; t2 = f1( wv[0] ) + maj( wv[0], wv[1], wv[2] ); wv[7] = wv[6]; wv[6] = wv[5]; wv[5] = wv[4]; wv[4] = wv[3] + t1; wv[3] = wv[2]; wv[2] = wv[1]; wv[1] = wv[0]; wv[0] = t1 + t2; } for ( size_t j = 0; j < 8; j++ ) _hash[j] += wv[j]; } }
static void _BRSHA256Compress(uint32_t *r, uint32_t *x) { static const uint32_t k[] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 }; int i; uint32_t a = r[0], b = r[1], c = r[2], d = r[3], e = r[4], f = r[5], g = r[6], h = r[7], t1, t2, w[64]; for (i = 0; i < 16; i++) w[i] = be32(x[i]); for (; i < 64; i++) w[i] = s3(w[i - 2]) + w[i - 7] + s2(w[i - 15]) + w[i - 16]; for (i = 0; i < 64; i++) { t1 = h + s1(e) + ch(e, f, g) + k[i] + w[i]; t2 = s0(a) + maj(a, b, c); h = g, g = f, f = e, e = d + t1, d = c, c = b, b = a, a = t1 + t2; } r[0] += a, r[1] += b, r[2] += c, r[3] += d, r[4] += e, r[5] += f, r[6] += g, r[7] += h; var_clean(&a, &b, &c, &d, &e, &f, &g, &h, &t1, &t2); mem_clean(w, sizeof(w)); }
Prototype::Prototype(const QString& xmlfilepath) : QObject(0), _elementsParType(), _mode_generation_bagage(AUTOMATIQUE), _id_bagage_genere(ID_BAGAGE_GENERE_INITIAL), _dt (INTERVALLE_RAFRAICHISSEMENT_MODELE / 1000.0) { qsrand(time(0)); // Désérialise le fichier XML. // Extrait et classe par type des pointeurs d'éléments. XmlConfigFactory handler; QXmlSimpleReader reader; reader.setContentHandler(&handler); reader.setErrorHandler(&handler); QFile file(xmlfilepath); if (!file.open(QFile::ReadOnly | QFile::Text)) { qDebug() << "Cannot read XML file." << endl; exit(1); } QXmlInputSource xmlInputSource(&file); if (reader.parse(xmlInputSource)) { _elementsParType = handler.resultat(); qDebug() << _elementsParType; } _horloge.setInterval(INTERVALLE_RAFRAICHISSEMENT_MODELE); connect(&_horloge, SIGNAL(timeout()), this, SLOT(ajouterBagageAleatoire())); connect(&_horloge, SIGNAL(timeout()), this, SLOT(maj())); }
static gboolean time_handler(GtkWidget *widget) { maj(); // printf("TH : maj done (%p <- %p)\n", ximg->mem, bgra.data); // memcpy(ximg->mem, bgra.data, bgra.size << 2); // printf("TH : mcpy done\n"); gtk_widget_queue_draw_area(widget, 0, 0, width, height); printf("TH : queue done\n"); return TRUE; }
void Slider::setValue(int value) { _value = value; // clamp if (_value < _min) _value = _min; else if (_value > _max) _value = _max; maj(); // un peu bourrin }
Slider::Slider(Frame frame, sf::Sprite spritebg, sf::Sprite spritecurs, int min, int max, int value, Slider::Listener *pListener) : WidgetBase(frame, spritebg), _min(min), _max(max), _value(value), _cursor(spritecurs), _pListener(pListener) { assert(min < max); maj(); }
/////////////////////////////////////////////////////////////////////////////// // Function Name:void ProChunk() // Feature:To compute sha1_A sha1 value of datas in blocks of fixed size(512 bit) /////////////////////////////////////////////////////////////////////////////// static void ProChunk() { short t; unsigned long wTmp; sha_ClearW(); CopyM2W(); for(t=16;t<80;t++) { wTmp=sha1_w[t-3]^sha1_w[t-8]^sha1_w[t-14]^sha1_w[t-16]; sha1_w[t]=S_LEFT(wTmp,1); } sha1_A=sha1_h[0]; sha1_B=sha1_h[1]; sha1_C=sha1_h[2]; sha1_D=sha1_h[3]; sha1_E=sha1_h[4]; for(t=0;t<80;t++) { sha1_temp=S_LEFT(sha1_A,5); sha1_temp=sha1_temp+sha1_E; sha1_temp=sha1_temp+sha1_w[t]; if(0<=t&&t<=19) { sha1_temp+=ch(sha1_B,sha1_C,sha1_D)+KT1; } if(20<=t&&t<=39) { sha1_temp+=parity(sha1_B,sha1_C,sha1_D)+KT2; } if(40<=t&&t<=59) { sha1_temp+=maj(sha1_B,sha1_C,sha1_D)+KT3; } if(60<=t&&t<=79) { sha1_temp+=parity(sha1_B,sha1_C,sha1_D)+KT4; } sha1_E=sha1_D; sha1_D=sha1_C; sha1_C=S_LEFT(sha1_B,30); sha1_B=sha1_A; sha1_A=sha1_temp; } sha1_h[0]+=sha1_A; sha1_h[1]+=sha1_B; sha1_h[2]+=sha1_C; sha1_h[3]+=sha1_D; sha1_h[4]+=sha1_E; }
void Serveur::majPatcher() { if(connexion(Patcher)) { maj(2); } else { param->setMessage(1);//serveur Patcher indisponible sf::Sleep(3); } param->setMessage(5); if(connexion(Jeux)) { maj(6); param->setMessage(9); } else param->setMessage(8); Jouer->setActive(true); Desinstaller->setActive(true); }
static void _BRSHA512Compress(uint64_t *r, uint64_t *x) { static const uint64_t k[] = { 0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc, 0x3956c25bf348b538, 0x59f111f1b605d019, 0x923f82a4af194f9b, 0xab1c5ed5da6d8118, 0xd807aa98a3030242, 0x12835b0145706fbe, 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2, 0x72be5d74f27b896f, 0x80deb1fe3b1696b1, 0x9bdc06a725c71235, 0xc19bf174cf692694, 0xe49b69c19ef14ad2, 0xefbe4786384f25e3, 0x0fc19dc68b8cd5b5, 0x240ca1cc77ac9c65, 0x2de92c6f592b0275, 0x4a7484aa6ea6e483, 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5, 0x983e5152ee66dfab, 0xa831c66d2db43210, 0xb00327c898fb213f, 0xbf597fc7beef0ee4, 0xc6e00bf33da88fc2, 0xd5a79147930aa725, 0x06ca6351e003826f, 0x142929670a0e6e70, 0x27b70a8546d22ffc, 0x2e1b21385c26c926, 0x4d2c6dfc5ac42aed, 0x53380d139d95b3df, 0x650a73548baf63de, 0x766a0abb3c77b2a8, 0x81c2c92e47edaee6, 0x92722c851482353b, 0xa2bfe8a14cf10364, 0xa81a664bbc423001, 0xc24b8b70d0f89791, 0xc76c51a30654be30, 0xd192e819d6ef5218, 0xd69906245565a910, 0xf40e35855771202a, 0x106aa07032bbd1b8, 0x19a4c116b8d2d0c8, 0x1e376c085141ab53, 0x2748774cdf8eeb99, 0x34b0bcb5e19b48a8, 0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb, 0x5b9cca4f7763e373, 0x682e6ff3d6b2b8a3, 0x748f82ee5defb2fc, 0x78a5636f43172f60, 0x84c87814a1f0ab72, 0x8cc702081a6439ec, 0x90befffa23631e28, 0xa4506cebde82bde9, 0xbef9a3f7b2c67915, 0xc67178f2e372532b, 0xca273eceea26619c, 0xd186b8c721c0c207, 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178, 0x06f067aa72176fba, 0x0a637dc5a2c898a6, 0x113f9804bef90dae, 0x1b710b35131c471b, 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc, 0x431d67c49c100d4c, 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 }; int i; uint64_t a = r[0], b = r[1], c = r[2], d = r[3], e = r[4], f = r[5], g = r[6], h = r[7], t1, t2, w[80]; for (i = 0; i < 16; i++) w[i] = be64(x[i]); for (; i < 80; i++) w[i] = S3(w[i - 2]) + w[i - 7] + S2(w[i - 15]) + w[i - 16]; for (i = 0; i < 80; i++) { t1 = h + S1(e) + ch(e, f, g) + k[i] + w[i]; t2 = S0(a) + maj(a, b, c); h = g, g = f, f = e, e = d + t1, d = c, c = b, b = a, a = t1 + t2; } r[0] += a, r[1] += b, r[2] += c, r[3] += d, r[4] += e, r[5] += f, r[6] += g, r[7] += h; var_clean(&a, &b, &c, &d, &e, &f, &g, &h, &t1, &t2); mem_clean(w, sizeof(w)); }
void ActiviteView::sauver() { ActiviteManager *am = Manager<ActiviteManager, Activite>::getInstance(); QString st = this->titre->text(); QString sd = this->details->text(); if(a == 0) { try{ am->ajouterActivite(st, sd); } catch(ProjectException p) { p.show(); } } else { // Comme les outils d'éditions sont vérouillés, les valeurs resteront identiques a->setTitre(st); a->setDetails(sd); } emit maj(); }
/** * \brief Decrypts an 8-bit byte using Acorn128. * * \param state The state for the Acorn128 cipher. * \param ciphertext The ciphertext byte. * * \return The plaintext byte. */ static inline uint8_t acornDecrypt8(Acorn128State *state, uint8_t ciphertext) { // Extract out various sub-parts of the state as 8-bit bytes. #define s_extract_8(name, shift) \ ((uint8_t)(state->name##_l >> (shift))) uint8_t s244 = s_extract_8(s6, 14); uint8_t s235 = s_extract_8(s6, 5); uint8_t s196 = s_extract_8(s5, 3); uint8_t s160 = s_extract_8(s4, 6); uint8_t s111 = s_extract_8(s3, 4); uint8_t s66 = s_extract_8(s2, 5); uint8_t s23 = s_extract_8(s1, 23); uint8_t s12 = s_extract_8(s1, 12); // Update the LFSR's. uint8_t s7_l = state->s7 ^ s235 ^ state->s6_l; state->s6_l ^= s196 ^ ((uint8_t)(state->s5_l)); state->s5_l ^= s160 ^ ((uint8_t)(state->s4_l)); state->s4_l ^= s111 ^ ((uint8_t)(state->s3_l)); state->s3_l ^= s66 ^ ((uint8_t)(state->s2_l)); state->s2_l ^= s23 ^ ((uint8_t)(state->s1_l)); // Generate the next 8 keystream bits and decrypt the ciphertext. // k = S[12] ^ S[154] ^ maj(S[235], S[61], S[193]) // ^ ch(S[230], S[111], S[66]) uint8_t ks = s12 ^ state->s4_l ^ maj(s235, state->s2_l, state->s5_l) ^ ch(state->s6_l, s111, s66); uint8_t plaintext = ciphertext ^ ks; // Generate the next 8 non-linear feedback bits. // f = S[0] ^ ~S[107] ^ maj(S[244], S[23], S[160]) // ^ (ca & S[196]) ^ (cb & ks) // f ^= plaintext // Note: ca will always be 1 and cb will always be 0. uint8_t f = state->s1_l ^ (~state->s3_l) ^ maj(s244, s23, s160) ^ s196; f ^= plaintext; // Shift the state downwards by 8 bits. #define s_shift_8(name1, name2, shift) \ (state->name1##_l = (state->name1##_l >> 8) | \ (((uint32_t)(state->name1##_h)) << 24), \ state->name1##_h = (state->name1##_h >> 8) | \ ((state->name2##_l & 0xFF) << ((shift) - 40))) #define s_shift_8_mixed(name1, name2, shift) \ (state->name1##_l = (state->name1##_l >> 8) | \ (((uint32_t)(state->name1##_h)) << 24) | \ (state->name2##_l << ((shift) - 8)), \ state->name1##_h = ((state->name2##_l & 0xFF) >> (40 - (shift)))) s7_l ^= (f << 4); state->s7 = f >> 4; s_shift_8(s1, s2, 61); s_shift_8(s2, s3, 46); s_shift_8(s3, s4, 47); s_shift_8_mixed(s4, s5, 39); s_shift_8_mixed(s5, s6, 37); state->s6_l = (state->s6_l >> 8) | (state->s6_h << 24); state->s6_h = (state->s6_h >> 8) | (((uint32_t)s7_l) << 19); // Return the plaintext byte to the caller. return plaintext; }
int main(int argc, char *argv[]) { int chance = 10 , chan = 10 , menu , *lettreTrouvee = NULL , l , i , a , donnees[2] = {0}; char mot[100] , caract; do { do { printf("\n\n ----------PENDU----------\n\n\n"); printf("\t\t1 : Jouer\n\t\t2 : Nombre de chance\n\t\t3 : Quitter\n"); printf("\n\t\t? "); scanf("%ld", &menu); printf("\n\n"); } while (menu < 1 || menu > 3); if (menu == 1) { a = 0; mot[100] = motAleatoire(mot); l = strlen(mot); lettreTrouvee = malloc(l*sizeof(int)); for(i = 0 ; i < l ; i++) { lettreTrouvee[i] = 0; } chance = chan; while (a < l && chance > 0) { printf("Mot secret : "); for(i = 0 ; i < l ; i++) { if (lettreTrouvee[i] == 1) printf("%c" , mot[i]); else printf("="); } printf("\nChance(s) : %ld" , chance); printf("\nLettre : "); do { caract = getchar(); caract = maj(caract); } while (caract == '\n'); printf("\n"); donnees[1] = a; donnees[2] = chance; verification(caract , mot , lettreTrouvee , donnees); a = donnees[1]; chance = donnees[2]; } if (a == l) { printf("\nVous avez GAGNE :D !!!!!\nLe mot etait bien : %s\n\n", mot); chance = chan; } if (chance == 0 && a != l) { printf("\nVous avez PERDU :(\nLe mot etait : %s\n\n", mot); chance = chan; } } if (menu == 2) { do { printf("\nNombre de chance (defaut : 10 ) ? "); scanf("%ld", &chance); } while (chance <= 0); chan = chance; } } while (menu != 3); return 0; }
int main(int argc, char *argv[]) { // GtkWidget *window; GtkWidget *fixed; GtkWidget *area; // gtk_init(&argc, &argv); // Window window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "gui"); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_container_set_border_width(GTK_CONTAINER(window), 0); gtk_window_set_default_size(GTK_WINDOW(window), width, height); printf("window ok\n"); // layout fixed = gtk_fixed_new(); gtk_container_add(GTK_CONTAINER(window), fixed); printf("fixed ok\n"); // Image GList *visuals = gdk_list_visuals(); void tst(gpointer data, gpointer udata) { if (((GdkVisual*)data)->depth == 32) printf("visual :\n\ttype = %d\n\ttype = %d\n\tdepth = %d\n\tbits/rgb = %d\n\torder = %d\n\tred = %08X\n\tgreen = %08X\n\tblue = %08X\n" , ((GdkVisual*)data)->type , ((GdkVisual*)data)->colormap_size , ((GdkVisual*)data)->depth , ((GdkVisual*)data)->bits_per_rgb , ((GdkVisual*)data)->byte_order , ((GdkVisual*)data)->red_mask , ((GdkVisual*)data)->green_mask , ((GdkVisual*)data)->blue_mask ); } g_list_foreach(visuals, &tst, NULL); GdkVisual *visu = gdk_visual_get_best_with_depth(32); ximg = gdk_image_new(GDK_IMAGE_SHARED, visu, width, height); printf("GdkImage : bytes/pix = %d, linesize = %d, bits/pix = %d ; type %d (mem = %p)\n" , ximg->bpp, ximg->bpl, ximg->bits_per_pixel , ximg->type, ximg->mem ); // GdkPixbufAnimation //gtk_image_set_from_pixbuf // GdkColormap *dcm = gdk_colormap_new(visu, FALSE); // drawing area area = gtk_drawing_area_new(); gdk_drawable_set_colormap(window, dcm); gdk_drawable_set_colormap(area, dcm); gtk_drawing_area_size(GTK_DRAWING_AREA(area), width, height); printf("area ok\n"); // gtk_fixed_put(GTK_FIXED(fixed), area, 0, 0); printf("fixed ok\n"); // bgra_alloc650(&bgra, width, height); bgra_origin650(&bgra, +width/2, +height/2); bgra_scale650(&bgra, 1, -1); printf("bgra alloc ok\n"); maj(); printf("bgra maj done, still (%p <- %p)\n", ximg->mem, bgra.data); // // Ximg // memcpy(ximg->mem, bgra.data, bgra.size); // printf("mcpy done\n"); // Pixmap GdkColor bg; GdkColor fg; fg.pixel = 0xff000000; fg.red = 0; fg.green = 0; fg.blue = 0; bg.pixel = 0xff000000; bg.red = 0; bg.green = 0; bg.blue = 0; pixmap = gdk_pixmap_create_from_data( GTK_WINDOW(window) , bgra.data , width , height , 32 , &fg , &bg ); // img = gdk_pixbuf_new_from_data( // (guchar*)bgra.data // , GDK_COLORSPACE_RGB // , TRUE // , 8 // , width // , height // , width << 2 // , &pbd, NULL // ); // printf("PixBuf new ok\n"); // // Image // frame = gtk_image_new_from_pixbuf(img); //// frame = gtimg; // gtk_fixed_put(GTK_FIXED(fixed), frame, 0, 0); // printf("fixed ok\n"); // Events g_signal_connect(area, "expose-event", G_CALLBACK (on_expose_event), NULL); // g_signal_connect(frame, "expose-event", G_CALLBACK (on_expose_event), NULL); g_signal_connect(window, "delete-event", G_CALLBACK (delete_event), NULL); g_signal_connect(window, "destroy", G_CALLBACK (destroy), NULL); printf("signals ok\n"); // Show // gtk_widget_show(area); gtk_widget_show(fixed); gtk_widget_show_all(window); printf("show ok\n"); // Timer g_timeout_add(500, (GSourceFunc)time_handler, (gpointer)area); printf("timer ok\n"); gtk_main(); return 0; }
uint64_t* SHA512Hash::hash(size_t data_length, uint64_t* data, uint64_t* dest_buffer) { //Set the initial hash value memcpy((void*) hash_value, (const void*) H0, 8*sizeof(uint64_t)); //Generate a padded copy of the message size_t work_data_length = padded_message_length(data_length); uint64_t* work_data = new uint64_t[work_data_length]; if(!work_data) { log_error(SHA_512_HASH_NAME, ERR_BAD_ALLOC.arg(QString("work_data"))); return NULL; } gen_padded_message(data_length, data, work_data); //Slice padded data in blocks of 16 quadwords, process each block. uint64_t* final_block = work_data+work_data_length; for(uint64_t* current_block = work_data; current_block < final_block; current_block+=16) { prepare_message_schedule(current_block); a = hash_value[0]; b = hash_value[1]; c = hash_value[2]; d = hash_value[3]; e = hash_value[4]; f = hash_value[5]; g = hash_value[6]; h = hash_value[7]; for(int t=0; t<80; ++t) { T1 = h + capital_sigma_1(e) + ch(e,f,g) + K[t] + W[t]; T2 = capital_sigma_0(a) + maj(a,b,c); h = g; g = f; f = e; e = d + T1; d = c; c = b; b = a; a = T1 + T2; } hash_value[0]+= a; hash_value[1]+= b; hash_value[2]+= c; hash_value[3]+= d; hash_value[4]+= e; hash_value[5]+= f; hash_value[6]+= g; hash_value[7]+= h; } //Copy hash value to destination, clean up, return final hash value memcpy((void*) dest_buffer, (const void*) hash_value, 8*sizeof(uint64_t)); memset((void*) W, 0, 80*sizeof(uint64_t)); a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, T1 = 0, T2 = 0; memset((void*) hash_value, 0, 8*sizeof(uint64_t)); memset((void*) work_data, 0, work_data_length*sizeof(uint64_t)); delete[] work_data; return dest_buffer; }
/* block is the 512-bit/64-byte/16-word input block. * hash is the 160-bit/20-byte/5-word input and output hash * native_in is 1 if we don't have to revert the bytes of the block on * a little-endian machine */ static void compute_sha512 (const uint64_t * block, uint512 * hash, int native_in) { uint64_t W [80]; int t; /* step 1 */ #if __BYTE_ORDER == __LITTLE_ENDIAN if (native_in) #endif /* __BYTE_ORDER == __LITTLE_ENDIAN */ init_w_native_byte_order (W, block); #if __BYTE_ORDER == __LITTLE_ENDIAN else init_w (W, block); #endif /* __BYTE_ORDER == __LITTLE_ENDIAN */ /* step 2 */ uint64_t a = hash->i [0]; uint64_t b = hash->i [1]; uint64_t c = hash->i [2]; uint64_t d = hash->i [3]; uint64_t e = hash->i [4]; uint64_t f = hash->i [5]; uint64_t g = hash->i [6]; uint64_t h = hash->i [7]; #ifdef DEBUG_PRINT if (debugging) printf ("in: %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 "\n", a, b, c, d, e, f, g, h); if (debugging) printf (" A B C D E F G H\n"); #endif /* DEBUG_PRINT */ /* step 3 */ for (t = 0; t < 80; t++) { uint64_t t1 = h + SIGMA1 (e) + ch (e, f, g) + K512 [t] + W [t]; uint64_t t2 = SIGMA0 (a) + maj (a, b, c); h = g; g = f; f = e; e = d + t1; d = c; c = b; b = a; a = t1 + t2; #ifdef DEBUG_PRINT if (debugging) printf ("t = %2d: %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 "\n", t, a, b, c, d, e, f, g, h); #endif /* DEBUG_PRINT */ } /* step 4 */ hash->i [0] += a; hash->i [1] += b; hash->i [2] += c; hash->i [3] += d; hash->i [4] += e; hash->i [5] += f; hash->i [6] += g; hash->i [7] += h; if (debugging) printf ("hash = %16" PRIx64 " %16" PRIx64 " %16" PRIx64 " %16" PRIx64 " %16" PRIx64 " %16" PRIx64 " %16" PRIx64 " %16" PRIx64 "\n", hash->i [0], hash->i [1], hash->i [2], hash->i [3], hash->i [4], hash->i [5], hash->i [6], hash->i [7]); }