Re: [SOLVED] SHA384 mbed Implementation

All of the T[] array values get incorrectly set between the 32th and 48th iterations.
It seems weird that the values aren't incorrect in the first 32 iterations as well if there is something wrong with the hashing.
Checking all of the operations that the macro is performing by hand, they seem to compare perfectly with the Linux VM values, however, I am using word64 temp variables to hold the values with the printf() code I'm using. It seems unlikely that this would change any results however.

Share

Re: [SOLVED] SHA384 mbed Implementation

Are you setting USE_SLOW_SHA2 or CTAOCRYPT_SLOW_WORD64?

28 (edited by Vanger 2015-02-25 13:24:28)

Re: [SOLVED] SHA384 mbed Implementation

Yes, trying with either USE_SLOW_SHA2 or CTAOCRYPT_SLOW_WORD64 turned on, the test will still fail.
I've had it set to CTAOCRYPT_SLOW_WORD64 for debugging the data values.

Share

Re: [SOLVED] SHA384 mbed Implementation

The first mismatch in calculations between what the values should be versus what they are is:
(On iteration 33: j=32, i=1):

What the mbed board spit out:
W[1]  =                                     00030000000000C0
h(1) from iteration 32                7973AADBDE294BE9
Calculated value to add to h(1)   CD3E67D18505477B
Calculated sum value:                46AF12AD632E92A4

What the sum value should be: 146b212ad632e9364
(Using online hex calculator)

Difference between the actual and expected hex values: 100030000000000c0

Note that the difference between what the board should have gotten and what it DID get, is equal to the value in W[1].
All of the values are equal until this iteration during the runtime code, although many of the W[] values are initialized to 0, so it could be that the algorithm properly calculates values when the initial value is 0, but when it is not, it screws up.

Share

Re: [SOLVED] SHA384 mbed Implementation

On your platform, we're depending on the compiler to make the 64-bit data operations work using its 32-bit registers/math. I'm wondering if it is messing up. I made a little test application that did a couple rotations on my Mac.

#include "wolfssl/wolfcrypt/types.h"
#include "wolfcrypt/src/misc.c"
#include <stdio.h>

int main(void)
{
    word64 test;

    test = 1;
    printf("test = %lu\n", test);
    test = rotlFixed64(test, 33);
    printf("test = %lX\n", test);

    test = 1;
    printf("test = %lu\n", test);
    test = rotrFixed64(test, 5);
    printf("test = %lX\n", test);
}

The output was:

test = 1
test = 200000000
test = 1
test = 800000000000000

Can you try it out, or something like it, on your device?

Re: [SOLVED] SHA384 mbed Implementation

I ran some test code:

        word64 test;
    
        test = 1;
        printf("test = %lu\n", test);
        printf("test = %llX\n",test);
        test = rotlFixed64(test, 33);
        printf("test = %lX\n", test);
        printf("test = %llX\n",test);
    
        test = 1;
        printf("test = %lu\n", test);
        printf("test = %llX\n",test);
        test = rotrFixed64(test, 5);
        printf("test = %lX\n", test);
        printf("test = %llX\n",test);

Here's the resulting printf's:

test = 3675008525
test = 1
test = A
test = 200000000
test = 10
test = 1
test = A
test = 800000000000000

From debugging printf values on the library before is how I found that %llX is the formatting to access the word64 variables, as I defined SIZEOF_LONG_LONG 8, which then defines the word64 variables as "unsigned long long"

#elif defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG == 8
    #define WORD64_AVAILABLE
    #define W64LIT(x) x##LL
    typedef unsigned long long word64;

Share

Re: [SOLVED] SHA384 mbed Implementation

I wrote up a test code to run the SHA384 Hash separately from all of the wolfSSL code, pulling out the needed constants and such. It seems as if some values stored in memory are getting corrupted/changed separately from when the code accesses them?

I've attached the test code I ran. On iteration 17, the value for the "C" variable is printed out, showing that the value in memory had the upper half or so of the variable set to 0.

This could be a hardware issue, but I'm hesitant to say it is without positively identifying that the code should be running perfectly.

Test Code:

#include "mbed.h"

typedef unsigned long long word64;
typedef unsigned int   word32;

static const word64 K512[80] = {
    (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)
};
word64 rotrFixed64(word64 x, word64 y)
{
    return (x >> y) | (x << (sizeof(y) * 8 - y));
}

int main(){
    const word64* K = K512;
    word64 T[8];
    T[0] = (0xcbbb9d5dc1059ed8);
    T[1] = (0x629a292a367cd507);
    T[2] = (0x9159015a3070dd17);
    T[3] = (0x152fecd8f70e5939);
    T[4] = (0x67332667ffc00b31);
    T[5] = (0x8eb44a8768581511);
    T[6] = (0xdb0c2e0d64f98fa7);
    T[7] = (0x47b5481dbefa4fa4);
    printf("Testing SHA384 calculations:\r\n");
        word64 A = T[0],
               B = T[1],
               C = T[2],
               D = T[3],
               E = T[4],
               F = T[5],
               G = T[6],
               H = T[7];
//Word is the test string “abc” formatted for hashing
        word64 Word[16];
        Word[0] = 0x6162638000000000;
        Word[1] = 0;
        Word[2] = 0;
        Word[3] = 0;
        Word[4] = 0;
        Word[5] = 0;
        Word[6] = 0;
        Word[7] = 0;
        Word[8] = 0;
        Word[9] = 0;
        Word[10] = 0;
        Word[11] = 0;
        Word[12] = 0;
        Word[13] = 0;
        Word[14] = 0;
        Word[15] = 0x18;
        word64 Ch,Maj,Sum0,Sum1;
        word64 Temp1, Temp2;
        printf("init\t%016llX\t%016llX\t%016llX\t%016llX\r\n",A,B,C,D);
        printf("\t%016llX\t%016llX\t%016llX\t%016llX\r\n",E,F,G,H);
        for(int Jay=0; Jay<80; Jay++) {
            Ch = ((E&F)^((~E)&G));
            Maj = ((A&B)^(A&C)^(B&C));
            Sum0 = (rotrFixed64(A,28)^rotrFixed64(A,34)^rotrFixed64(A,39));
            Sum1 = (rotrFixed64(E,14)^rotrFixed64(E,18)^rotrFixed64(E,41));
            if(Jay < 16) {
                Word[Jay] = Word[Jay]; //Initialize value
            } else {
                //Word[(Jay-2)&15]  Word[(Jay-15)&15]
                Word[Jay] = (rotrFixed64(Word[(Jay-2)&15],19)^rotrFixed64(Word[(Jay-2)&15],61)^(Word[(Jay-2)&15]>>7)\
                 + Word[(Jay-7)&15]\
                 + rotrFixed64(Word[(Jay-15)&15],1)^rotrFixed64(Word[(Jay-15)&15],8)^(Word[(Jay-15)&15]>>6)\
                 + Word[(Jay-16)&15]);
            }
            Temp1 = (H + Sum1 + Ch + K[Jay] + Word[Jay]);
            Temp2 = (Sum0 + Maj);
            H = G;
            G = F;
            F = E;
            E = (D + Temp1);
            D = C;
            C = B;
            B = A;
            A = (Temp1 + Temp2);
            printf("t = %d\t%016llX\t%016llX\t%016llX\t%016llX\r\n",Jay,A,B,C,D);
            printf("\t%016llX\t%016llX\t%016llX\t%016llX\r\n",E,F,G,H);
        }
}

Share

Re: [SOLVED] SHA384 mbed Implementation

I successfully implemented a SHA384 hash algorithm using the mbed platform, but unfortunately, I'm unable to figure out what is different between what is going wrong with the wolfSSL code and the code I have written.

It is written with only the standard mbed includes, and seems to get the right hash and intermediate words. As I said though, reading through the wolfSSL code I'm unable to determine what is different.


#include "mbed.h"

typedef unsigned long long word64;
typedef uint32_t word32;

static const word64 Record[80*8] = {
    //t = 0
    (0x470994ad30873f88), (0xcbbb9d5dc1059ed8), (0x629a292a367cd507), (0x9159015a3070dd17),
    (0xbd03f724be6075f9), (0x67332667ffc00b31), (0x8eb44a8768581511), (0xdb0c2e0d64f98fa7),
    //t = 1
    (0x2e91230306a12ae0), (0x470994ad30873f88), (0xcbbb9d5dc1059ed8), (0x629a292a367cd507),
    (0x5e1b4e1695372b9e), (0xbd03f724be6075f9), (0x67332667ffc00b31), (0x8eb44a8768581511),
    //t = 2
    (0xeebe5d379be707ad), (0x2e91230306a12ae0), (0x470994ad30873f88), (0xcbbb9d5dc1059ed8),
    (0x54074a65aef34336), (0x5e1b4e1695372b9e), (0xbd03f724be6075f9), (0x67332667ffc00b31),
    //t = 3
    (0xe308483153e15ad6), (0xeebe5d379be707ad), (0x2e91230306a12ae0), (0x470994ad30873f88),
    (0x086c5b2d36a89178), (0x54074a65aef34336), (0x5e1b4e1695372b9e), (0xbd03f724be6075f9),
    //t = 4
    (0x3a7a023c593d8479), (0xe308483153e15ad6), (0xeebe5d379be707ad), (0x2e91230306a12ae0),
    (0x8aa1144850633794), (0x086c5b2d36a89178), (0x54074a65aef34336), (0x5e1b4e1695372b9e),
    //t = 5
    (0x333199a85f92b052), (0x3a7a023c593d8479), (0xe308483153e15ad6), (0xeebe5d379be707ad),
    (0x7a6316f0ef047ce7), (0x8aa1144850633794), (0x086c5b2d36a89178), (0x54074a65aef34336),
    //t = 6
    (0x76f0741213dd2ef6), (0x333199a85f92b052), (0x3a7a023c593d8479), (0xe308483153e15ad6),
    (0x74063cba385f0675), (0x7a6316f0ef047ce7), (0x8aa1144850633794), (0x086c5b2d36a89178),
    //t = 7
    (0x02f2a04d3aab1629), (0x76f0741213dd2ef6), (0x333199a85f92b052), (0x3a7a023c593d8479),
    (0x1688b9bf14980fc0), (0x74063cba385f0675), (0x7a6316f0ef047ce7), (0x8aa1144850633794),
    //t = 8
    (0x73e5b2a1704a0349), (0x02f2a04d3aab1629), (0x76f0741213dd2ef6), (0x333199a85f92b052),
    (0xfd00139f705907d0), (0x1688b9bf14980fc0), (0x74063cba385f0675), (0x7a6316f0ef047ce7),
    //t = 9
    (0xbf3f67ba12882648), (0x73e5b2a1704a0349), (0x02f2a04d3aab1629), (0x76f0741213dd2ef6),
    (0x652e311d4f0a4257), (0xfd00139f705907d0), (0x1688b9bf14980fc0), (0x74063cba385f0675),
    //t = 10
    (0x33254508bb2ea48d), (0xbf3f67ba12882648), (0x73e5b2a1704a0349), (0x02f2a04d3aab1629),
    (0x9e18991c4f39f0ba), (0x652e311d4f0a4257), (0xfd00139f705907d0), (0x1688b9bf14980fc0),
    //t = 11
    (0xc1fdb2a0205ea0e5), (0x33254508bb2ea48d), (0xbf3f67ba12882648), (0x73e5b2a1704a0349),
    (0x04732e8bc4044582), (0x9e18991c4f39f0ba), (0x652e311d4f0a4257), (0xfd00139f705907d0),
    //t = 12
    (0x185f9ff038a50f39), (0xc1fdb2a0205ea0e5), (0x33254508bb2ea48d), (0xbf3f67ba12882648),
    (0x8b4acfc4d2b8afe6), (0x04732e8bc4044582), (0x9e18991c4f39f0ba), (0x652e311d4f0a4257),
    //t = 13
    (0xe5f06744c0d7563a), (0x185f9ff038a50f39), (0xc1fdb2a0205ea0e5), (0x33254508bb2ea48d),
    (0x2fa93d1ce9523015), (0x8b4acfc4d2b8afe6), (0x04732e8bc4044582), (0x9e18991c4f39f0ba),
    //t = 14
    (0x7e32dc0e9f414783), (0xe5f06744c0d7563a), (0x185f9ff038a50f39), (0xc1fdb2a0205ea0e5),
    (0x3a9950aaa5e75884), (0x2fa93d1ce9523015), (0x8b4acfc4d2b8afe6), (0x04732e8bc4044582),
    //t = 15
    (0x1eab6159ae87ef6d), (0x7e32dc0e9f414783), (0xe5f06744c0d7563a), (0x185f9ff038a50f39),
    (0x153b895cfbc436c5), (0x3a9950aaa5e75884), (0x2fa93d1ce9523015), (0x8b4acfc4d2b8afe6),
    //t = 16
    (0x33ef2cebbf1739aa), (0x1eab6159ae87ef6d), (0x7e32dc0e9f414783), (0xe5f06744c0d7563a),
    (0x9d1a64baf1d366aa), (0x153b895cfbc436c5), (0x3a9950aaa5e75884), (0x2fa93d1ce9523015),
    //t = 17
    (0x7df1b65f1b87d6ca), (0x33ef2cebbf1739aa), (0x1eab6159ae87ef6d), (0x7e32dc0e9f414783),
    (0x5b6e369d36e8e181), (0x9d1a64baf1d366aa), (0x153b895cfbc436c5), (0x3a9950aaa5e75884),
    //t = 18
    (0x63a24014a34bb0f6), (0x7df1b65f1b87d6ca), (0x33ef2cebbf1739aa), (0x1eab6159ae87ef6d),
    (0xe13e610eae680d85), (0x5b6e369d36e8e181), (0x9d1a64baf1d366aa), (0x153b895cfbc436c5),
    //t = 19
    (0xf1aabd313309509b), (0x63a24014a34bb0f6), (0x7df1b65f1b87d6ca), (0x33ef2cebbf1739aa),
    (0x674385f0d87db94f), (0xe13e610eae680d85), (0x5b6e369d36e8e181), (0x9d1a64baf1d366aa),
    //t = 20
    (0x9ba737ae88a72c64), (0xf1aabd313309509b), (0x63a24014a34bb0f6), (0x7df1b65f1b87d6ca),
    (0x3fc2614c43906c0f), (0x674385f0d87db94f), (0xe13e610eae680d85), (0x5b6e369d36e8e181),
    //t = 21
    (0x042c2dc9a5bf558a), (0x9ba737ae88a72c64), (0xf1aabd313309509b), (0x63a24014a34bb0f6),
    (0x19316bebc88e01f2), (0x3fc2614c43906c0f), (0x674385f0d87db94f), (0xe13e610eae680d85),
    //t = 22
    (0x7799c75acc748c0f), (0x042c2dc9a5bf558a), (0x9ba737ae88a72c64), (0xf1aabd313309509b),
    (0xa7bbd65bf64f58c8), (0x19316bebc88e01f2), (0x3fc2614c43906c0f), (0x674385f0d87db94f),
    //t = 23
    (0xccf99a80f92bf002), (0x7799c75acc748c0f), (0x042c2dc9a5bf558a), (0x9ba737ae88a72c64),
    (0xe52a24fae4e8fc9b), (0xa7bbd65bf64f58c8), (0x19316bebc88e01f2), (0x3fc2614c43906c0f),
    //t = 24
    (0xae993474363efe68), (0xccf99a80f92bf002), (0x7799c75acc748c0f), (0x042c2dc9a5bf558a),
    (0x587f308d58681928), (0xe52a24fae4e8fc9b), (0xa7bbd65bf64f58c8), (0x19316bebc88e01f2),
    //t = 25
    (0x335063d1a2aec92f), (0xae993474363efe68), (0xccf99a80f92bf002), (0x7799c75acc748c0f),
    (0xc2d6d65e38c6ea79), (0x587f308d58681928), (0xe52a24fae4e8fc9b), (0xa7bbd65bf64f58c8),
    //t = 26
    (0x53a78b0cca01ba37), (0x335063d1a2aec92f), (0xae993474363efe68), (0xccf99a80f92bf002),
    (0x3b65a26c3c92c8f3), (0xc2d6d65e38c6ea79), (0x587f308d58681928), (0xe52a24fae4e8fc9b),
    (0xab7ffa529f622930), (0x53a78b0cca01ba37), (0x335063d1a2aec92f), (0xae993474363efe68),
    (0xb9d8a2f2762901ea), (0x3b65a26c3c92c8f3), (0xc2d6d65e38c6ea79), (0x587f308d58681928),
    (0xe428bb43afe3d63e), (0xab7ffa529f622930), (0x53a78b0cca01ba37), (0x335063d1a2aec92f),
    (0x6a8527525f898726), (0xb9d8a2f2762901ea), (0x3b65a26c3c92c8f3), (0xc2d6d65e38c6ea79),
    (0xbbed541a5128088c), (0xe428bb43afe3d63e), (0xab7ffa529f622930), (0x53a78b0cca01ba37),
    (0x7973aadbde294be9), (0x6a8527525f898726), (0xb9d8a2f2762901ea), (0x3b65a26c3c92c8f3),
    (0x4c5c38df7ec8baf4), (0xbbed541a5128088c), (0xe428bb43afe3d63e), (0xab7ffa529f622930),
    (0x422ceea0200e9ee4), (0x7973aadbde294be9), (0x6a8527525f898726), (0xb9d8a2f2762901ea),
    (0x4ba456ec244033ed), (0x4c5c38df7ec8baf4), (0xbbed541a5128088c), (0xe428bb43afe3d63e),
    (0x7cf40857056d86b0), (0x422ceea0200e9ee4), (0x7973aadbde294be9), (0x6a8527525f898726),
    (0xaa4a6ab2ac5f5dd8), (0x4ba456ec244033ed), (0x4c5c38df7ec8baf4), (0xbbed541a5128088c),
    (0xad2b1ecfb5bfc556), (0x7cf40857056d86b0), (0x422ceea0200e9ee4), (0x7973aadbde294be9),
    (0x9cb941f2ced774b3), (0xaa4a6ab2ac5f5dd8), (0x4ba456ec244033ed), (0x4c5c38df7ec8baf4),
    (0x029f66c7b4569bf0), (0xad2b1ecfb5bfc556), (0x7cf40857056d86b0), (0x422ceea0200e9ee4),
    (0x39265f358594de27), (0x9cb941f2ced774b3), (0xaa4a6ab2ac5f5dd8), (0x4ba456ec244033ed),
    (0x3f7b1c260c82e54f), (0x029f66c7b4569bf0), (0xad2b1ecfb5bfc556), (0x7cf40857056d86b0),
    (0x09cca487d39b02a1), (0x39265f358594de27), (0x9cb941f2ced774b3), (0xaa4a6ab2ac5f5dd8),
    (0x4a22b37b58a5b1b0), (0x3f7b1c260c82e54f), (0x029f66c7b4569bf0), (0xad2b1ecfb5bfc556),
    (0xd48d97ce438cf4f0), (0x09cca487d39b02a1), (0x39265f358594de27), (0x9cb941f2ced774b3),
    (0xa239e00b8baa0410), (0x4a22b37b58a5b1b0), (0x3f7b1c260c82e54f), (0x029f66c7b4569bf0),
    (0xd6f41e25a8b634d6), (0xd48d97ce438cf4f0), (0x09cca487d39b02a1), (0x39265f358594de27),
    (0x25755cb8179dd0b0), (0xa239e00b8baa0410), (0x4a22b37b58a5b1b0), (0x3f7b1c260c82e54f),
    (0x54078334358573b4), (0xd6f41e25a8b634d6), (0xd48d97ce438cf4f0), (0x09cca487d39b02a1),
    (0x0e419fb0802b0efc), (0x25755cb8179dd0b0), (0xa239e00b8baa0410), (0x4a22b37b58a5b1b0),
    (0xdb24f9a03f4fff6b), (0x54078334358573b4), (0xd6f41e25a8b634d6), (0xd48d97ce438cf4f0),
    (0xd30e99b4b394b090), (0x0e419fb0802b0efc), (0x25755cb8179dd0b0), (0xa239e00b8baa0410),
    (0x3604c53a845efc37), (0xdb24f9a03f4fff6b), (0x54078334358573b4), (0xd6f41e25a8b634d6),
    (0x791b2b4af7338b99), (0xd30e99b4b394b090), (0x0e419fb0802b0efc), (0x25755cb8179dd0b0),
    (0xf41b1c0eee89bdc6), (0x3604c53a845efc37), (0xdb24f9a03f4fff6b), (0x54078334358573b4),
    (0xe319b77d9e4e87f9), (0x791b2b4af7338b99), (0xd30e99b4b394b090), (0x0e419fb0802b0efc),
    (0x36644ae374632e3a), (0xf41b1c0eee89bdc6), (0x3604c53a845efc37), (0xdb24f9a03f4fff6b),
    (0x458250878a3972b2), (0xe319b77d9e4e87f9), (0x791b2b4af7338b99), (0xd30e99b4b394b090),
    (0x88806f6ae9fcd65b), (0x36644ae374632e3a), (0xf41b1c0eee89bdc6), (0x3604c53a845efc37),
    (0xcfde2e6ea54fa576), (0x458250878a3972b2), (0xe319b77d9e4e87f9), (0x791b2b4af7338b99),
    (0x51dcaa36995c301d), (0x88806f6ae9fcd65b), (0x36644ae374632e3a), (0xf41b1c0eee89bdc6),
    (0xe37f778353998050), (0xcfde2e6ea54fa576), (0x458250878a3972b2), (0xe319b77d9e4e87f9),
    (0xef5e3885a2f238df), (0x51dcaa36995c301d), (0x88806f6ae9fcd65b), (0x36644ae374632e3a),
    (0x740e347f24e18fda), (0xe37f778353998050), (0xcfde2e6ea54fa576), (0x458250878a3972b2),
    (0xeb3753f4283f4818), (0xef5e3885a2f238df), (0x51dcaa36995c301d), (0x88806f6ae9fcd65b),
    (0x0ae48cf840bb8be9), (0x740e347f24e18fda), (0xe37f778353998050), (0xcfde2e6ea54fa576),
    (0xa6998d63a5d09e04), (0xeb3753f4283f4818), (0xef5e3885a2f238df), (0x51dcaa36995c301d),
    (0xe21095012ee0b72a), (0x0ae48cf840bb8be9), (0x740e347f24e18fda), (0xe37f778353998050),
    (0xd3698fb64df175b0), (0xa6998d63a5d09e04), (0xeb3753f4283f4818), (0xef5e3885a2f238df),
    (0xc2f0b90ffce80739), (0xe21095012ee0b72a), (0x0ae48cf840bb8be9), (0x740e347f24e18fda),
    (0x317a3b295b991914), (0xd3698fb64df175b0), (0xa6998d63a5d09e04), (0xeb3753f4283f4818),
    (0x1cadff2e6cb5aa4d), (0xc2f0b90ffce80739), (0xe21095012ee0b72a), (0x0ae48cf840bb8be9),
    (0x0941da08148ba463), (0x317a3b295b991914), (0xd3698fb64df175b0), (0xa6998d63a5d09e04),
    (0x833eb9a4bb5a073e), (0x1cadff2e6cb5aa4d), (0xc2f0b90ffce80739), (0xe21095012ee0b72a),
    (0x494ac238d68c3d0b), (0x0941da08148ba463), (0x317a3b295b991914), (0xd3698fb64df175b0),
    (0x80c8fc138e645028), (0x833eb9a4bb5a073e), (0x1cadff2e6cb5aa4d), (0xc2f0b90ffce80739),
    (0xc87e9168db9e97de), (0x494ac238d68c3d0b), (0x0941da08148ba463), (0x317a3b295b991914),
    (0x65cf7f6a829aca04), (0x80c8fc138e645028), (0x833eb9a4bb5a073e), (0x1cadff2e6cb5aa4d),
    (0xedb4448879391dbb), (0xc87e9168db9e97de), (0x494ac238d68c3d0b), (0x0941da08148ba463),
    (0x7729c85475dd318f), (0x65cf7f6a829aca04), (0x80c8fc138e645028), (0x833eb9a4bb5a073e),
    (0x073775c2456dc7db), (0xedb4448879391dbb), (0xc87e9168db9e97de), (0x494ac238d68c3d0b),
    (0xa9cca0b6266b1d77), (0x7729c85475dd318f), (0x65cf7f6a829aca04), (0x80c8fc138e645028),
    (0x54de8857b24afaf7), (0x073775c2456dc7db), (0xedb4448879391dbb), (0xc87e9168db9e97de),
    (0x8de51cff2ae4b068), (0xa9cca0b6266b1d77), (0x7729c85475dd318f), (0x65cf7f6a829aca04),
    (0x8a9cdd80f7f09c05), (0x54de8857b24afaf7), (0x073775c2456dc7db), (0xedb4448879391dbb),
    (0xa60ba5e9ebaeb96a), (0x8de51cff2ae4b068), (0xa9cca0b6266b1d77), (0x7729c85475dd318f),
    (0x3eeb22a7524d8d7f), (0x8a9cdd80f7f09c05), (0x54de8857b24afaf7), (0x073775c2456dc7db),
    (0xe2e6830b139df58f), (0xa60ba5e9ebaeb96a), (0x8de51cff2ae4b068), (0xa9cca0b6266b1d77),
    (0x0ed77c9cde8883d3), (0x3eeb22a7524d8d7f), (0x8a9cdd80f7f09c05), (0x54de8857b24afaf7),
    (0x38413a2052387a9e), (0xe2e6830b139df58f), (0xa60ba5e9ebaeb96a), (0x8de51cff2ae4b068),
    (0xe64e4135f9d30dbc), (0x0ed77c9cde8883d3), (0x3eeb22a7524d8d7f), (0x8a9cdd80f7f09c05),
    (0x45b640454c75c349), (0x38413a2052387a9e), (0xe2e6830b139df58f), (0xa60ba5e9ebaeb96a),
    (0x1ca93a293d544328), (0xe64e4135f9d30dbc), (0x0ed77c9cde8883d3), (0x3eeb22a7524d8d7f),
    (0xefbef83a35c0319e), (0x45b640454c75c349), (0x38413a2052387a9e), (0xe2e6830b139df58f),
    (0x3dc764f89e54043a), (0x1ca93a293d544328), (0xe64e4135f9d30dbc), (0x0ed77c9cde8883d3),
    (0xa57784945550cf94), (0xefbef83a35c0319e), (0x45b640454c75c349), (0x38413a2052387a9e),
    (0x56fb5883f1c87a05), (0x3dc764f89e54043a), (0x1ca93a293d544328), (0xe64e4135f9d30dbc),
    (0xf5198a41eb80e022), (0xa57784945550cf94), (0xefbef83a35c0319e), (0x45b640454c75c349),
    (0x24a1124262a331c7), (0x56fb5883f1c87a05), (0x3dc764f89e54043a), (0x1ca93a293d544328),
    (0x06edacae6e7b54ad), (0xf5198a41eb80e022), (0xa57784945550cf94), (0xefbef83a35c0319e),
    (0xeb85d19201c89694), (0x24a1124262a331c7), (0x56fb5883f1c87a05), (0x3dc764f89e54043a),
    (0x9ced24983eec8723), (0x06edacae6e7b54ad), (0xf5198a41eb80e022), (0xa57784945550cf94),
    (0xcc981ab3a59c1db4), (0xeb85d19201c89694), (0x24a1124262a331c7), (0x56fb5883f1c87a05),
    (0xeac5516336bc8882), (0x9ced24983eec8723), (0x06edacae6e7b54ad), (0xf5198a41eb80e022),
    (0xceef5d997e148b44), (0xcc981ab3a59c1db4), (0xeb85d19201c89694), (0x24a1124262a331c7),
    (0x617bbf70bb165212), (0xeac5516336bc8882), (0x9ced24983eec8723), (0x06edacae6e7b54ad),
    (0x689edf608a8e3f14), (0xceef5d997e148b44), (0xcc981ab3a59c1db4), (0xeb85d19201c89694),
    (0x3280d88472c100fd), (0x617bbf70bb165212), (0xeac5516336bc8882), (0x9ced24983eec8723),
    (0x1e6e0255ab88079f), (0x689edf608a8e3f14), (0xceef5d997e148b44), (0xcc981ab3a59c1db4),
    (0xf2001138439902b1), (0x3280d88472c100fd), (0x617bbf70bb165212), (0xeac5516336bc8882),
    (0x8c5d3b7fdad66e70), (0x1e6e0255ab88079f), (0x689edf608a8e3f14), (0xceef5d997e148b44),
    (0x90d18ec8b69f0345), (0xf2001138439902b1), (0x3280d88472c100fd), (0x617bbf70bb165212),
    (0x32e5ed8655871e9b), (0x8c5d3b7fdad66e70), (0x1e6e0255ab88079f), (0x689edf608a8e3f14),
    (0x51105f6241313777), (0x90d18ec8b69f0345), (0xf2001138439902b1), (0x3280d88472c100fd),
    (0xbcd5061679be7336), (0x32e5ed8655871e9b), (0x8c5d3b7fdad66e70), (0x1e6e0255ab88079f),
    (0x454b99f654443ad0), (0x51105f6241313777), (0x90d18ec8b69f0345), (0xf2001138439902b1),
    (0xe7d913b6678e78ef), (0xbcd5061679be7336), (0x32e5ed8655871e9b), (0x8c5d3b7fdad66e70),
    (0x1ff613b5aa63776e), (0x454b99f654443ad0), (0x51105f6241313777), (0x90d18ec8b69f0345),
    (0xe6b8cb8dfa3475ab), (0xe7d913b6678e78ef), (0xbcd5061679be7336), (0x32e5ed8655871e9b),
    (0x2e75f34303d39bb0), (0x1ff613b5aa63776e), (0x454b99f654443ad0), (0x51105f6241313777),
    (0xfdd4a30e168c4ae5), (0xe6b8cb8dfa3475ab), (0xe7d913b6678e78ef), (0xbcd5061679be7336),
    (0x83a35dbe2a64fc26), (0x2e75f34303d39bb0), (0x1ff613b5aa63776e), (0x454b99f654443ad0),
    (0x12aeb6268dfa3e14), (0xfdd4a30e168c4ae5), (0xe6b8cb8dfa3475ab), (0xe7d913b6678e78ef),
    (0xf660943b276786f7), (0x83a35dbe2a64fc26), (0x2e75f34303d39bb0), (0x1ff613b5aa63776e),
    (0x055b73814cf102b4), (0x12aeb6268dfa3e14), (0xfdd4a30e168c4ae5), (0xe6b8cb8dfa3475ab),
    (0xc4b149710f5d6a71), (0xf660943b276786f7), (0x83a35dbe2a64fc26), (0x2e75f34303d39bb0),
    (0x95d33150de6df44c), (0x055b73814cf102b4), (0x12aeb6268dfa3e14), (0xfdd4a30e168c4ae5),
    (0xc7f7bff08ebf0d30), (0xc4b149710f5d6a71), (0xf660943b276786f7), (0x83a35dbe2a64fc26),
    (0x5306143f64497b00), (0x95d33150de6df44c), (0x055b73814cf102b4), (0x12aeb6268dfa3e14),
    (0xca06a219cc701096), (0xc7f7bff08ebf0d30), (0xc4b149710f5d6a71), (0xf660943b276786f7),
    (0xff44d7e1849dbfb3), (0x5306143f64497b00), (0x95d33150de6df44c), (0x055b73814cf102b4),
    (0x1952e0c3a227c0f2), (0xca06a219cc701096), (0xc7f7bff08ebf0d30), (0xc4b149710f5d6a71)
};
static const word64 K512[80] = {
    (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)
};
word64 rotrFixed64(word64 x, word64 y)
{
    return (x >> y) | (x << (sizeof(y) * 8 - y));
}

int main(){
    printf("Size of word64 %d\r\n",sizeof(word64));
    printf("Size of word32 %d\r\n",sizeof(word32));
    
    printf("Checking bitwise operators\r\n");
    printf("Test \"AND\" %llX = 0xA0C0E00234128000\r\n",(0xABCDEF1234568888)&(0xA0C0E00234128040));
    printf("Test \"OR\"  %llX = 0x514789485ABEFDCE\r\n",(0x110388004882D586)|(0x40440148123C2848));
    printf("Text \"XOR\" %llX = 0x2531253186752093\r\n",(0xFFFFFFFF11111111)^(0xDACEDACE97643182));
    printf("Text \"NOT\" %llX = 0xFEDCBA9876543210\r\n",~(0x0123456789ABCDEF));
    printf("1 shifted right 61 bits: %llX = 0x0000000000000008\r\n", rotrFixed64(0x0000000000000001,61));
    printf("ABC shifted right 32 bits: %llX = 0x00000ABC00000000\r\n", rotrFixed64(0x0000000000000ABC,32));
    printf("1 shifted right 1 bits: %llX = 0x8000000000000000\r\n", rotrFixed64(0x0000000000000001,1));
    printf("1 shifted right 3 bits: %llX = 0x2000000000000000\r\n", rotrFixed64(0x0000000000000001,3));
    
    const word64* K = K512;
    word64 T[8];
    T[0] = (0xcbbb9d5dc1059ed8);
    T[1] = (0x629a292a367cd507);
    T[2] = (0x9159015a3070dd17);
    T[3] = (0x152fecd8f70e5939);
    T[4] = (0x67332667ffc00b31);
    T[5] = (0x8eb44a8768581511);
    T[6] = (0xdb0c2e0d64f98fa7);
    T[7] = (0x47b5481dbefa4fa4);
    printf("Testing SHA384 calculations:\r\n");
    
        word64 Word[16];
        Word[0] = 0x6162638000000000;
        Word[1] = 0;
        Word[2] = 0;
        Word[3] = 0;
        Word[4] = 0;
        Word[5] = 0;
        Word[6] = 0;
        Word[7] = 0;
        Word[8] = 0;
        Word[9] = 0;
        Word[10] = 0;
        Word[11] = 0;
        Word[12] = 0;
        Word[13] = 0;
        Word[14] = 0;
        Word[15] = 0x18;
        word64 Ch,Maj,Sum0,Sum1;
        word64 Temp1, Temp2;
        //printf("init\t%016llX\t%016llX\t%016llX\t%016llX\r\n",A,B,C,D);
        //printf("\t%016llX\t%016llX\t%016llX\t%016llX\r\n",E,F,G,H);
        for(int j=0; j<80; j++) {
            Ch = ((T[4] & T[5])^((~T[4]) & T[6]));
            Maj = ((T[0]&T[1])^(T[0]&T[2])^(T[1]&T[2]));
            Sum0 = (rotrFixed64(T[0],28)^rotrFixed64(T[0],34)^rotrFixed64(T[0],39));
            Sum1 = (rotrFixed64(T[4],14)^rotrFixed64(T[4],18)^rotrFixed64(T[4],41));
            if(j < 16) {
                Word[j] = Word[j]; //Initialize value
            } else {
                word64 s1 = rotrFixed64(Word[(j-2)&15],19)^rotrFixed64(Word[(j-2)&15],61)^(Word[(j-2)&15]>>6); //S19^S61^R6
                word64 s0 = rotrFixed64(Word[(j-15)&15],1)^rotrFixed64(Word[(j-15)&15],8)^(Word[(j-15)&15]>>7); //S1^S8^R7
                
                Word[j&15] = s1 + Word[(j-7)&15] + s0 + Word[(j-16)&15];
            }
            
            Temp1 = T[7] + Sum1 + Ch + K[j] + Word[(j)&(0xF)];
            Temp2 = Sum0 + Maj;
            
            T[7] = T[6];
            T[6] = T[5];
            T[5] = T[4];
            T[4] = T[3] + Temp1;
            T[3] = T[2];
            T[2] = T[1];
            T[1] = T[0];
            T[0] = Temp1 + Temp2;
            printf("t = %d\t%016llX\t%016llX\t%016llX\t%016llX\r\n",j,T[0],T[1],T[2],T[3]);
            printf("\t%016llX\t%016llX\t%016llX\t%016llX\r\n",T[4],T[5],T[6],T[7]);
        }
        printf("Hash(0): %llX\r\n",T[0] + (0xcbbb9d5dc1059ed8));
        printf("Hash(1): %llX\r\n",T[1] + (0x629a292a367cd507));
        printf("Hash(2): %llX\r\n",T[2] + (0x9159015a3070dd17));
        printf("Hash(3): %llX\r\n",T[3] + (0x152fecd8f70e5939));
        printf("Hash(4): %llX\r\n",T[4] + (0x67332667ffc00b31));
        printf("Hash(5): %llX\r\n",T[5] + (0x8eb44a8768581511));
        printf("Hash(6): %llX\r\n",T[6] + (0xdb0c2e0d64f98fa7));
        printf("Hash(7): %llX\r\n",T[7] + (0x47b5481dbefa4fa4));
}

Results of the code:

Size of word64 8
Size of word32 4
Checking bitwise operators
Test "AND" A0C0E00234128000 = 0xA0C0E00234128000
Test "OR"  514789485ABEFDCE = 0x514789485ABEFDCE
Text "XOR" 2531253186752093 = 0x2531253186752093
Text "NOT" FEDCBA9876543210 = 0xFEDCBA9876543210
1 shifted right 61 bits: 8 = 0x0000000000000008
ABC shifted right 32 bits: ABC00000000 = 0x00000ABC00000000
1 shifted right 1 bits: 8000000000000000 = 0x8000000000000000
1 shifted right 3 bits: 2000000000000000 = 0x2000000000000000
Testing SHA384 calculations:
t = 0   470994AD30873F88        CBBB9D5DC1059ED8        629A292A367CD507        9159015A3070DD17
        BD03F724BE6075F9        67332667FFC00B31        8EB44A8768581511        DB0C2E0D64F98FA7
t = 1   2E91230306A12AE0        470994AD30873F88        CBBB9D5DC1059ED8        629A292A367CD507
        5E1B4E1695372B9E        BD03F724BE6075F9        67332667FFC00B31        8EB44A8768581511
t = 2   EEBE5D379BE707AD        2E91230306A12AE0        470994AD30873F88        CBBB9D5DC1059ED8
        54074A65AEF34336        5E1B4E1695372B9E        BD03F724BE6075F9        67332667FFC00B31
t = 3   E308483153E15AD6        EEBE5D379BE707AD        2E91230306A12AE0        470994AD30873F88
        086C5B2D36A89178        54074A65AEF34336        5E1B4E1695372B9E        BD03F724BE6075F9
t = 4   3A7A023C593D8479        E308483153E15AD6        EEBE5D379BE707AD        2E91230306A12AE0
        8AA1144850633794        086C5B2D36A89178        54074A65AEF34336        5E1B4E1695372B9E
t = 5   333199A85F92B052        3A7A023C593D8479        E308483153E15AD6        EEBE5D379BE707AD
        7A6316F0EF047CE7        8AA1144850633794        086C5B2D36A89178        54074A65AEF34336
t = 6   76F0741213DD2EF6        333199A85F92B052        3A7A023C593D8479        E308483153E15AD6
        74063CBA385F0675        7A6316F0EF047CE7        8AA1144850633794        086C5B2D36A89178
t = 7   02F2A04D3AAB1629        76F0741213DD2EF6        333199A85F92B052        3A7A023C593D8479
        1688B9BF14980FC0        74063CBA385F0675        7A6316F0EF047CE7        8AA1144850633794
t = 8   73E5B2A1704A0349        02F2A04D3AAB1629        76F0741213DD2EF6        333199A85F92B052
        FD00139F705907D0        1688B9BF14980FC0        74063CBA385F0675        7A6316F0EF047CE7
t = 9   BF3F67BA12882648        73E5B2A1704A0349        02F2A04D3AAB1629        76F0741213DD2EF6
        652E311D4F0A4257        FD00139F705907D0        1688B9BF14980FC0        74063CBA385F0675
t = 10  33254508BB2EA48D        BF3F67BA12882648        73E5B2A1704A0349        02F2A04D3AAB1629
        9E18991C4F39F0BA        652E311D4F0A4257        FD00139F705907D0        1688B9BF14980FC0
t = 11  C1FDB2A0205EA0E5        33254508BB2EA48D        BF3F67BA12882648        73E5B2A1704A0349
        04732E8BC4044582        9E18991C4F39F0BA        652E311D4F0A4257        FD00139F705907D0
t = 12  185F9FF038A50F39        C1FDB2A0205EA0E5        33254508BB2EA48D        BF3F67BA12882648
        8B4ACFC4D2B8AFE6        04732E8BC4044582        9E18991C4F39F0BA        652E311D4F0A4257
t = 13  E5F06744C0D7563A        185F9FF038A50F39        C1FDB2A0205EA0E5        33254508BB2EA48D
        2FA93D1CE9523015        8B4ACFC4D2B8AFE6        04732E8BC4044582        9E18991C4F39F0BA
t = 14  7E32DC0E9F414783        E5F06744C0D7563A        185F9FF038A50F39        C1FDB2A0205EA0E5
        3A9950AAA5E75884        2FA93D1CE9523015        8B4ACFC4D2B8AFE6        04732E8BC4044582
t = 15  1EAB6159AE87EF6D        7E32DC0E9F414783        E5F06744C0D7563A        185F9FF038A50F39
        153B895CFBC436C5        3A9950AAA5E75884        2FA93D1CE9523015        8B4ACFC4D2B8AFE6
t = 16  33EF2CEBBF1739AA        1EAB6159AE87EF6D        7E32DC0E9F414783        E5F06744C0D7563A
        9D1A64BAF1D366AA        153B895CFBC436C5        3A9950AAA5E75884        2FA93D1CE9523015
t = 17  7DF1B65F1B87D6CA        33EF2CEBBF1739AA        1EAB6159AE87EF6D        7E32DC0E9F414783
        5B6E369D36E8E181        9D1A64BAF1D366AA        153B895CFBC436C5        3A9950AAA5E75884
t = 18  63A24014A34BB0F6        7DF1B65F1B87D6CA        33EF2CEBBF1739AA        1EAB6159AE87EF6D
        E13E610EAE680D85        5B6E369D36E8E181        9D1A64BAF1D366AA        153B895CFBC436C5
t = 19  F1AABD313309509B        63A24014A34BB0F6        7DF1B65F1B87D6CA        33EF2CEBBF1739AA
        674385F0D87DB94F        E13E610EAE680D85        5B6E369D36E8E181        9D1A64BAF1D366AA
t = 20  9BA737AE88A72C64        F1AABD313309509B        63A24014A34BB0F6        7DF1B65F1B87D6CA
        3FC2614C43906C0F        674385F0D87DB94F        E13E610EAE680D85        5B6E369D36E8E181
t = 21  042C2DC9A5BF558A        9BA737AE88A72C64        F1AABD313309509B        63A24014A34BB0F6
        19316BEBC88E01F2        3FC2614C43906C0F        674385F0D87DB94F        E13E610EAE680D85
t = 22  7799C75ACC748C0F        042C2DC9A5BF558A        9BA737AE88A72C64        F1AABD313309509B
        A7BBD65BF64F58C8        19316BEBC88E01F2        3FC2614C43906C0F        674385F0D87DB94F
t = 23  CCF99A80F92BF002        7799C75ACC748C0F        042C2DC9A5BF558A        9BA737AE88A72C64
        E52A24FAE4E8FC9B        A7BBD65BF64F58C8        19316BEBC88E01F2        3FC2614C43906C0F
t = 24  AE993474363EFE68        CCF99A80F92BF002        7799C75ACC748C0F        042C2DC9A5BF558A
        587F308D58681928        E52A24FAE4E8FC9B        A7BBD65BF64F58C8        19316BEBC88E01F2
t = 25  335063D1A2AEC92F        AE993474363EFE68        CCF99A80F92BF002        7799C75ACC748C0F
        C2D6D65E38C6EA79        587F308D58681928        E52A24FAE4E8FC9B        A7BBD65BF64F58C8
t = 26  53A78B0CCA01BA37        335063D1A2AEC92F        AE993474363EFE68        CCF99A80F92BF002
        3B65A26C3C92C8F3        C2D6D65E38C6EA79        587F308D58681928        E52A24FAE4E8FC9B
t = 27  AB7FFA529F622930        53A78B0CCA01BA37        335063D1A2AEC92F        AE993474363EFE68
        B9D8A2F2762901EA        3B65A26C3C92C8F3        C2D6D65E38C6EA79        587F308D58681928
t = 28  E428BB43AFE3D63E        AB7FFA529F622930        53A78B0CCA01BA37        335063D1A2AEC92F
        6A8527525F898726        B9D8A2F2762901EA        3B65A26C3C92C8F3        C2D6D65E38C6EA79
t = 29  BBED541A5128088C        E428BB43AFE3D63E        AB7FFA529F622930        53A78B0CCA01BA37
        7973AADBDE294BE9        6A8527525F898726        B9D8A2F2762901EA        3B65A26C3C92C8F3
t = 30  4C5C38DF7EC8BAF4        BBED541A5128088C        E428BB43AFE3D63E        AB7FFA529F622930
        422CEEA0200E9EE4        7973AADBDE294BE9        6A8527525F898726        B9D8A2F2762901EA
t = 31  4BA456EC244033ED        4C5C38DF7EC8BAF4        BBED541A5128088C        E428BB43AFE3D63E
        7CF40857056D86B0        422CEEA0200E9EE4        7973AADBDE294BE9        6A8527525F898726
t = 32  AA4A6AB2AC5F5DD8        4BA456EC244033ED        4C5C38DF7EC8BAF4        BBED541A5128088C
        AD2B1ECFB5BFC556        7CF40857056D86B0        422CEEA0200E9EE4        7973AADBDE294BE9
t = 33  9CB941F2CED774B3        AA4A6AB2AC5F5DD8        4BA456EC244033ED        4C5C38DF7EC8BAF4
        029F66C7B4569BF0        AD2B1ECFB5BFC556        7CF40857056D86B0        422CEEA0200E9EE4
t = 34  39265F358594DE27        9CB941F2CED774B3        AA4A6AB2AC5F5DD8        4BA456EC244033ED
        3F7B1C260C82E54F        029F66C7B4569BF0        AD2B1ECFB5BFC556        7CF40857056D86B0
t = 35  09CCA487D39B02A1        39265F358594DE27        9CB941F2CED774B3        AA4A6AB2AC5F5DD8
        4A22B37B58A5B1B0        3F7B1C260C82E54F        029F66C7B4569BF0        AD2B1ECFB5BFC556
t = 36  D48D97CE438CF4F0        09CCA487D39B02A1        39265F358594DE27        9CB941F2CED774B3
        A239E00B8BAA0410        4A22B37B58A5B1B0        3F7B1C260C82E54F        029F66C7B4569BF0
t = 37  D6F41E25A8B634D6        D48D97CE438CF4F0        09CCA487D39B02A1        39265F358594DE27
        25755CB8179DD0B0        A239E00B8BAA0410        4A22B37B58A5B1B0        3F7B1C260C82E54F
t = 38  54078334358573B4        D6F41E25A8B634D6        D48D97CE438CF4F0        09CCA487D39B02A1
        0E419FB0802B0EFC        25755CB8179DD0B0        A239E00B8BAA0410        4A22B37B58A5B1B0
t = 39  DB24F9A03F4FFF6B        54078334358573B4        D6F41E25A8B634D6        D48D97CE438CF4F0
        D30E99B4B394B090        0E419FB0802B0EFC        25755CB8179DD0B0        A239E00B8BAA0410
t = 40  3604C53A845EFC37        DB24F9A03F4FFF6B        54078334358573B4        D6F41E25A8B634D6
        791B2B4AF7338B99        D30E99B4B394B090        0E419FB0802B0EFC        25755CB8179DD0B0
t = 41  F41B1C0EEE89BDC6        3604C53A845EFC37        DB24F9A03F4FFF6B        54078334358573B4
        E319B77D9E4E87F9        791B2B4AF7338B99        D30E99B4B394B090        0E419FB0802B0EFC
t = 42  36644AE374632E3A        F41B1C0EEE89BDC6        3604C53A845EFC37        DB24F9A03F4FFF6B
        458250878A3972B2        E319B77D9E4E87F9        791B2B4AF7338B99        D30E99B4B394B090
t = 43  88806F6AE9FCD65B        36644AE374632E3A        F41B1C0EEE89BDC6        3604C53A845EFC37
        CFDE2E6EA54FA576        458250878A3972B2        E319B77D9E4E87F9        791B2B4AF7338B99
t = 44  51DCAA36995C301D        88806F6AE9FCD65B        36644AE374632E3A        F41B1C0EEE89BDC6
        E37F778353998050        CFDE2E6EA54FA576        458250878A3972B2        E319B77D9E4E87F9
t = 45  EF5E3885A2F238DF        51DCAA36995C301D        88806F6AE9FCD65B        36644AE374632E3A
        740E347F24E18FDA        E37F778353998050        CFDE2E6EA54FA576        458250878A3972B2
t = 46  EB3753F4283F4818        EF5E3885A2F238DF        51DCAA36995C301D        88806F6AE9FCD65B
        0AE48CF840BB8BE9        740E347F24E18FDA        E37F778353998050        CFDE2E6EA54FA576
t = 47  A6998D63A5D09E04        EB3753F4283F4818        EF5E3885A2F238DF        51DCAA36995C301D
        E21095012EE0B72A        0AE48CF840BB8BE9        740E347F24E18FDA        E37F778353998050
t = 48  D3698FB64DF175B0        A6998D63A5D09E04        EB3753F4283F4818        EF5E3885A2F238DF
        C2F0B90FFCE80739        E21095012EE0B72A        0AE48CF840BB8BE9        740E347F24E18FDA
t = 49  317A3B295B991914        D3698FB64DF175B0        A6998D63A5D09E04        EB3753F4283F4818
        1CADFF2E6CB5AA4D        C2F0B90FFCE80739        E21095012EE0B72A        0AE48CF840BB8BE9
t = 50  0941DA08148BA463        317A3B295B991914        D3698FB64DF175B0        A6998D63A5D09E04
        833EB9A4BB5A073E        1CADFF2E6CB5AA4D        C2F0B90FFCE80739        E21095012EE0B72A
t = 51  494AC238D68C3D0B        0941DA08148BA463        317A3B295B991914        D3698FB64DF175B0
        80C8FC138E645028        833EB9A4BB5A073E        1CADFF2E6CB5AA4D        C2F0B90FFCE80739
t = 52  C87E9168DB9E97DE        494AC238D68C3D0B        0941DA08148BA463        317A3B295B991914
        65CF7F6A829ACA04        80C8FC138E645028        833EB9A4BB5A073E        1CADFF2E6CB5AA4D
t = 53  EDB4448879391DBB        C87E9168DB9E97DE        494AC238D68C3D0B        0941DA08148BA463
        7729C85475DD318F        65CF7F6A829ACA04        80C8FC138E645028        833EB9A4BB5A073E
t = 54  073775C2456DC7DB        EDB4448879391DBB        C87E9168DB9E97DE        494AC238D68C3D0B
        A9CCA0B6266B1D77        7729C85475DD318F        65CF7F6A829ACA04        80C8FC138E645028
t = 55  54DE8857B24AFAF7        073775C2456DC7DB        EDB4448879391DBB        C87E9168DB9E97DE
        8DE51CFF2AE4B068        A9CCA0B6266B1D77        7729C85475DD318F        65CF7F6A829ACA04
t = 56  8A9CDD80F7F09C05        54DE8857B24AFAF7        073775C2456DC7DB        EDB4448879391DBB
        A60BA5E9EBAEB96A        8DE51CFF2AE4B068        A9CCA0B6266B1D77        7729C85475DD318F
t = 57  3EEB22A7524D8D7F        8A9CDD80F7F09C05        54DE8857B24AFAF7        073775C2456DC7DB
        E2E6830B139DF58F        A60BA5E9EBAEB96A        8DE51CFF2AE4B068        A9CCA0B6266B1D77
t = 58  0ED77C9CDE8883D3        3EEB22A7524D8D7F        8A9CDD80F7F09C05        54DE8857B24AFAF7
        38413A2052387A9E        E2E6830B139DF58F        A60BA5E9EBAEB96A        8DE51CFF2AE4B068
t = 59  E64E4135F9D30DBC        0ED77C9CDE8883D3        3EEB22A7524D8D7F        8A9CDD80F7F09C05
        45B640454C75C349        38413A2052387A9E        E2E6830B139DF58F        A60BA5E9EBAEB96A
t = 60  1CA93A293D544328        E64E4135F9D30DBC        0ED77C9CDE8883D3        3EEB22A7524D8D7F
        EFBEF83A35C0319E        45B640454C75C349        38413A2052387A9E        E2E6830B139DF58F
t = 61  3DC764F89E54043A        1CA93A293D544328        E64E4135F9D30DBC        0ED77C9CDE8883D3
        A57784945550CF94        EFBEF83A35C0319E        45B640454C75C349        38413A2052387A9E
t = 62  56FB5883F1C87A05        3DC764F89E54043A        1CA93A293D544328        E64E4135F9D30DBC
        F5198A41EB80E022        A57784945550CF94        EFBEF83A35C0319E        45B640454C75C349
t = 63  24A1124262A331C7        56FB5883F1C87A05        3DC764F89E54043A        1CA93A293D544328
        06EDACAE6E7B54AD        F5198A41EB80E022        A57784945550CF94        EFBEF83A35C0319E
t = 64  EB85D19201C89694        24A1124262A331C7        56FB5883F1C87A05        3DC764F89E54043A
        9CED24983EEC8723        06EDACAE6E7B54AD        F5198A41EB80E022        A57784945550CF94
t = 65  CC981AB3A59C1DB4        EB85D19201C89694        24A1124262A331C7        56FB5883F1C87A05
        EAC5516336BC8882        9CED24983EEC8723        06EDACAE6E7B54AD        F5198A41EB80E022
t = 66  CEEF5D997E148B44        CC981AB3A59C1DB4        EB85D19201C89694        24A1124262A331C7
        617BBF70BB165212        EAC5516336BC8882        9CED24983EEC8723        06EDACAE6E7B54AD
t = 67  689EDF608A8E3F14        CEEF5D997E148B44        CC981AB3A59C1DB4        EB85D19201C89694
        3280D88472C100FD        617BBF70BB165212        EAC5516336BC8882        9CED24983EEC8723
t = 68  1E6E0255AB88079F        689EDF608A8E3F14        CEEF5D997E148B44        CC981AB3A59C1DB4
        F2001138439902B1        3280D88472C100FD        617BBF70BB165212        EAC5516336BC8882
t = 69  8C5D3B7FDAD66E70        1E6E0255AB88079F        689EDF608A8E3F14        CEEF5D997E148B44
        90D18EC8B69F0345        F2001138439902B1        3280D88472C100FD        617BBF70BB165212
t = 70  32E5ED8655871E9B        8C5D3B7FDAD66E70        1E6E0255AB88079F        689EDF608A8E3F14
        51105F6241313777        90D18EC8B69F0345        F2001138439902B1        3280D88472C100FD
t = 71  BCD5061679BE7336        32E5ED8655871E9B        8C5D3B7FDAD66E70        1E6E0255AB88079F
        454B99F654443AD0        51105F6241313777        90D18EC8B69F0345        F2001138439902B1
t = 72  E7D913B6678E78EF        BCD5061679BE7336        32E5ED8655871E9B        8C5D3B7FDAD66E70
        1FF613B5AA63776E        454B99F654443AD0        51105F6241313777        90D18EC8B69F0345
t = 73  E6B8CB8DFA3475AB        E7D913B6678E78EF        BCD5061679BE7336        32E5ED8655871E9B
        2E75F34303D39BB0        1FF613B5AA63776E        454B99F654443AD0        51105F6241313777
t = 74  FDD4A30E168C4AE5        E6B8CB8DFA3475AB        E7D913B6678E78EF        BCD5061679BE7336
        83A35DBE2A64FC26        2E75F34303D39BB0        1FF613B5AA63776E        454B99F654443AD0
t = 75  12AEB6268DFA3E14        FDD4A30E168C4AE5        E6B8CB8DFA3475AB        E7D913B6678E78EF
        F660943B276786F7        83A35DBE2A64FC26        2E75F34303D39BB0        1FF613B5AA63776E
t = 76  055B73814CF102B4        12AEB6268DFA3E14        FDD4A30E168C4AE5        E6B8CB8DFA3475AB
        C4B149710F5D6A71        F660943B276786F7        83A35DBE2A64FC26        2E75F34303D39BB0
t = 77  95D33150DE6DF44C        055B73814CF102B4        12AEB6268DFA3E14        FDD4A30E168C4AE5
        C7F7BFF08EBF0D30        C4B149710F5D6A71        F660943B276786F7        83A35DBE2A64FC26
t = 78  5306143F64497B00        95D33150DE6DF44C        055B73814CF102B4        12AEB6268DFA3E14
        CA06A219CC701096        C7F7BFF08EBF0D30        C4B149710F5D6A71        F660943B276786F7
t = 79  FF44D7E1849DBFB3        5306143F64497B00        95D33150DE6DF44C        055B73814CF102B4
        1952E0C3A227C0F2        CA06A219CC701096        C7F7BFF08EBF0D30        C4B149710F5D6A71
Hash(0): CB00753F45A35E8B
Hash(1): B5A03D699AC65007
Hash(2): 272C32AB0EDED163
Hash(3): 1A8B605A43FF5BED
Hash(4): 8086072BA1E7CC23
Hash(5): 58BAECA134C825A7
Hash(6): A303EDFDF3B89CD7
Hash(7): C66918ECE57BA15

Share

Re: [SOLVED] SHA384 mbed Implementation

I believe I have found the compile issue that was causing unexpected behaviour with the SHA384 ans SHA512 code.
The R2(i) and R(i) macros both add the W["i"] through the use of another macro:

#define R(i) h(i)+=S1(e(i))+Ch(e(i),f(i),g(i))+K[i+j]+(j?blk2(i):blk0(i));\

Where blk0 and blk2 are:

#define blk0(i) (W["i"] = sha512->buffer["i"])
#define blk2(i) (W[i&15] += s1(W[(i-2)&15])+W[(i-7)&15]+s0(W[(i-15)&15])+0)

Apparently, the compiler was not adding the variable to h(i) after assigning W["i"]. Specifically, to fix the code on mbed to work, I moved the word variable assignments to a separate line, then called the word itself to use for modifying h(i) in the next line. Example code below:

#define R2(i) (j?blk2(i):blk384(i));\
    h(i)+=S1(e(i))+Ch(e(i),f(i),g(i))+K[i+j]+W[i&15];\
    d(i)+=h(i);\
    h(i)+=S0(a(i))+Maj(a(i),b(i),c(i))

Share

Re: [SOLVED] SHA384 mbed Implementation

I'm glad to see you found a work-around for the problem. I have a colleague looking into this right now as well. We will investigate a more permanent solution for this.

Thanks!

Re: [SOLVED] SHA384 mbed Implementation

Thank you.
I believe the gcc compiler compiles it just fine, so it might be a bug with only the online mbed compiler. Might be worth a question or two to the ARM coders.
Thanks for all of the help with finding the problem; I'll mark the thread as solved.

Share

Re: [SOLVED] SHA384 mbed Implementation

Hello,

I just want to let you know that I also struggled with this issue and the fix described here worked for me. I am compiling for an ARM using Keil MDK.

Share