Commit 53dfa48e authored by jan.koester's avatar jan.koester
Browse files

test

parent 36a6525b
Loading
Loading
Loading
Loading

check_sha384

0 → 100755
+16.9 KiB

File added.

No diff preview for this file type.

check_sha384.cpp

0 → 100644
+29 −0
Original line number Diff line number Diff line
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <vector>

int main() {
    // Expected SHA-384 IV from FIPS 180-4
    std::cout << "SHA-384 Initial Hash Values (FIPS 180-4):" << std::endl;
    uint64_t expected_h0 = 0xcbbb9d5dc1059ed8ULL;
    uint64_t expected_h1 = 0x629a292a367cd507ULL;
    uint64_t expected_h2 = 0x9159015a3070dd17ULL;
    uint64_t expected_h3 = 0x152fecd8f70e5939ULL;
    uint64_t expected_h4 = 0x67332667ffc00b31ULL;
    uint64_t expected_h5 = 0x8eb44a8768581511ULL;
    uint64_t expected_h6 = 0xdb0c2e0d64f98fa7ULL;
    uint64_t expected_h7 = 0x47b5481dbefa4fa4ULL;

    std::cout << std::hex << std::setfill('0');
    std::cout << "h0 = 0x" << std::setw(16) << expected_h0 << std::endl;
    std::cout << "h1 = 0x" << std::setw(16) << expected_h1 << std::endl;
    std::cout << "h2 = 0x" << std::setw(16) << expected_h2 << std::endl;
    std::cout << "h3 = 0x" << std::setw(16) << expected_h3 << std::endl;
    std::cout << "h4 = 0x" << std::setw(16) << expected_h4 << std::endl;
    std::cout << "h5 = 0x" << std::setw(16) << expected_h5 << std::endl;
    std::cout << "h6 = 0x" << std::setw(16) << expected_h6 << std::endl;
    std::cout << "h7 = 0x" << std::setw(16) << expected_h7 << std::endl;

    return 0;
}

compare_round0

0 → 100755
+15.7 KiB

File added.

No diff preview for this file type.

compare_round0.cpp

0 → 100644
+93 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdint.h>
#include <openssl/evp.h>
#include <openssl/sha.h>

#define ROTR64(x, n) (((x) >> (n)) | ((x) << (64 - (n))))
#define CH(x, y, z) (((x) & (y)) ^ ((~(x)) & (z)))
#define MAJ(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
#define SIGMA0(x) (ROTR64(x, 28) ^ ROTR64(x, 34) ^ ROTR64(x, 39))
#define SIGMA1(x) (ROTR64(x, 14) ^ ROTR64(x, 18) ^ ROTR64(x, 41))
#define sigma0(x) (ROTR64(x, 1) ^ ROTR64(x, 8) ^ ((x) >> 7))
#define sigma1(x) (ROTR64(x, 19) ^ ROTR64(x, 61) ^ ((x) >> 6))

void pr_hex(const char* label, uint64_t val) {
    printf("%s=%016lx\n", label, (unsigned long)val);
}

int main() {
    // Initial values for SHA-384
    uint64_t h[8] = {
        0xcbbb9d5dc1059ed8ULL,
        0x629a292a367cd507ULL,
        0x9159015a3070dd17ULL,
        0x152fecd8f70e5939ULL,
        0x67332667ffc00b31ULL,
        0x8eb44a8768581511ULL,
        0xdb0c2e0d64f98fa7ULL,
        0x47b5481dbefa4fa4ULL
    };
    
    // K constants (first 10 for test)
    uint64_t k[10] = {
        0x428a2f98d728ae22ULL,
        0x7137449123ef65cdULL,
        0xb5c0fbcfec4d3b2fULL,
        0xe9b5dba58189dbbcULL,
        0x3956c25bf348b538ULL,
        0x59f111f1b605d019ULL,
        0x923f82a4af194f9bULL,
        0xab1c5ed5da6d8118ULL,
        0xd807aa98a3030242ULL,
        0x12835b0145706fbeULL
    };
    
    // Message block for empty string (first 10 words)
    uint64_t w[10] = {
        0x8000000000000000ULL,
        0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    
    printf("Round 0 computation:\n");
    printf("Initial state:\n");
    for (int j = 0; j < 8; j++) {
        pr_hex("h", h[j]);
    }
    
    uint64_t a = h[0], b = h[1], c = h[2], d = h[3], e = h[4], f = h[5], g = h[6], hh = h[7];
    
    printf("\nRound 0:\n");
    pr_hex("a", a); pr_hex("b", b); pr_hex("c", c); pr_hex("d", d);
    pr_hex("e", e); pr_hex("f", f); pr_hex("g", g); pr_hex("h", hh);
    
    uint64_t T1 = hh + SIGMA1(e) + CH(e, f, g) + k[0] + w[0];
    uint64_t T2 = SIGMA0(a) + MAJ(a, b, c);
    
    printf("\nT1 calculation:\n");
    pr_hex("hh", hh);
    pr_hex("SIGMA1(e)", SIGMA1(e));
    pr_hex("CH(e,f,g)", CH(e, f, g));
    pr_hex("k[0]", k[0]);
    pr_hex("w[0]", w[0]);
    pr_hex("T1", T1);
    
    printf("\nT2 calculation:\n");
    pr_hex("SIGMA0(a)", SIGMA0(a));
    pr_hex("MAJ(a,b,c)", MAJ(a, b, c));
    pr_hex("T2", T2);
    
    a = T1 + T2;
    b = h[0];
    c = h[1];
    d = h[2];
    e = h[3] + T1;
    f = h[4];
    g = h[5];
    hh = h[6];
    
    printf("\nAfter round 0:\n");
    pr_hex("a", a); pr_hex("b", b); pr_hex("c", c); pr_hex("d", d);
    pr_hex("e", e); pr_hex("f", f); pr_hex("g", g); pr_hex("h", hh);
    
    return 0;
}

debug_h_values

0 → 100755
+17 KiB

File added.

No diff preview for this file type.

Loading