Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f7450d2d44
Fetching contributors…

Cannot retrieve contributors at this time

file 173 lines (144 sloc) 5.701 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
#include <stdio.h>
#include <stdint.h>
#include <string.h>

#if BLAKE256
# include "blake256.h"
#elif BLAKE512
# include "blake512.h"
#endif

#if BLAKE256

// These tests are copied from the original blake256_light.c.
int runtests256() {
    int i, v, e;
    uint8_t data[72], digest[32];
    uint8_t test1[]= {0x0C, 0xE8, 0xD4, 0xEF, 0x4D, 0xD7, 0xCD, 0x8D, 0x62, 0xDF, 0xDE, 0xD9, 0xD4, 0xED, 0xB0, 0xA7,
           0x74, 0xAE, 0x6A, 0x41, 0x92, 0x9A, 0x74, 0xDA, 0x23, 0x10, 0x9E, 0x8F, 0x11, 0x13, 0x9C, 0x87};
    uint8_t test2[]= {0xD4, 0x19, 0xBA, 0xD3, 0x2D, 0x50, 0x4F, 0xB7, 0xD4, 0x4D, 0x46, 0x0C, 0x42, 0xC5, 0x59, 0x3F,
           0xE5, 0x44, 0xFA, 0x4C, 0x13, 0x5D, 0xEC, 0x31, 0xE2, 0x1B, 0xD9, 0xAB, 0xDC, 0xC2, 0x2D, 0x41};

    for (i = 0; i < 72; ++i) data[i] = 0;

    blake256_hash(digest, data, 1);
    v = 0; e = 0;
    for (i = 0; i < 32; ++i) {
        printf("%02X", digest[i]);
        if (digest[i] != test1[i]) v = 1;
    }
    if (v) { printf("\nerror\n"); e++; }
    else printf("\nok\n");

    for (i = 0; i < 72; ++i) data[i] = 0;

    blake256_hash(digest, data, 72);
    v = 0;
    for (i = 0; i < 32; ++i) {
        printf("%02X", digest[i]);
        if (digest[i] != test2[i]) v = 1;
    }
    if (v) { printf("\nerror\n"); e++; }
    else printf("\nok\n");

    return e;
}

// These tests are copied from the original blake224_light.c.
int runtests224() {
    int i, v, e;
    uint8_t data[72], digest[32];
    uint8_t test1[]= {0x45, 0x04, 0xCB, 0x03, 0x14, 0xFB, 0x2A, 0x4F, 0x7A, 0x69, 0x2E, 0x69, 0x6E, 0x48, 0x79, 0x12,
           0xFE, 0x3F, 0x24, 0x68, 0xFE, 0x31, 0x2C, 0x73, 0xA5, 0x27, 0x8E, 0xC5};
    uint8_t test2[]= {0xF5, 0xAA, 0x00, 0xDD, 0x1C, 0xB8, 0x47, 0xE3, 0x14, 0x03, 0x72, 0xAF, 0x7B, 0x5C, 0x46, 0xB4,
           0x88, 0x8D, 0x82, 0xC8, 0xC0, 0xA9, 0x17, 0x91, 0x3C, 0xFB, 0x5D, 0x04};

    for (i = 0; i < 72; ++i) data[i] = 0;

    blake224_hash(digest, data, 1);
    v = 0; e = 0;
    for (i = 0; i < 28; ++i) {
        printf("%02X", digest[i]);
        if (digest[i] != test1[i]) v = 1;
    }
    if (v) { printf("\nerror\n"); e++; }
    else printf("\nok\n");

    for (i = 0; i < 72; ++i) data[i] = 0;

    blake224_hash(digest, data, 72);
    v = 0;
    for (i = 0; i < 28; ++i) {
        printf("%02X", digest[i]);
        if (digest[i] != test2[i]) v = 1;
    }
    if (v) { printf("\nerror\n"); e++; }
    else printf("\nok\n");

    return e;
}

#elif BLAKE512

// These tests are copied from the original blake512_light.c.
int runtests512() {
    int i, v, e;
    uint8_t data[144], digest[64];
    uint8_t test1[]= {0x97, 0x96, 0x15, 0x87, 0xF6, 0xD9, 0x70, 0xFA, 0xBA, 0x6D, 0x24, 0x78, 0x04, 0x5D, 0xE6, 0xD1,
           0xFA, 0xBD, 0x09, 0xB6, 0x1A, 0xE5, 0x09, 0x32, 0x05, 0x4D, 0x52, 0xBC, 0x29, 0xD3, 0x1B, 0xE4,
           0xFF, 0x91, 0x02, 0xB9, 0xF6, 0x9E, 0x2B, 0xBD, 0xB8, 0x3B, 0xE1, 0x3D, 0x4B, 0x9C, 0x06, 0x09,
           0x1E, 0x5F, 0xA0, 0xB4, 0x8B, 0xD0, 0x81, 0xB6, 0x34, 0x05, 0x8B, 0xE0, 0xEC, 0x49, 0xBE, 0xB3};
    uint8_t test2[]= {0x31, 0x37, 0x17, 0xD6, 0x08, 0xE9, 0xCF, 0x75, 0x8D, 0xCB, 0x1E, 0xB0, 0xF0, 0xC3, 0xCF, 0x9F,
           0xC1, 0x50, 0xB2, 0xD5, 0x00, 0xFB, 0x33, 0xF5, 0x1C, 0x52, 0xAF, 0xC9, 0x9D, 0x35, 0x8A, 0x2F,
           0x13, 0x74, 0xB8, 0xA3, 0x8B, 0xBA, 0x79, 0x74, 0xE7, 0xF6, 0xEF, 0x79, 0xCA, 0xB1, 0x6F, 0x22,
           0xCE, 0x1E, 0x64, 0x9D, 0x6E, 0x01, 0xAD, 0x95, 0x89, 0xC2, 0x13, 0x04, 0x5D, 0x54, 0x5D, 0xDE};

    for (i = 0; i < 144; ++i) data[i] = 0;

    blake512_hash(digest, data, 1);
    v = 0; e = 0;
    for (i = 0; i < 64; ++i) {
        printf("%02X", digest[i]);
        if (digest[i] != test1[i]) v = 1;
    }
    if (v) { printf("\nerror\n"); e++; }
    else printf("\nok\n");

    for (i = 0; i < 144; ++i) data[i] = 0;

    blake512_hash(digest, data, 144);
    v = 0;
    for (i = 0; i < 64; ++i) {
        printf("%02X", digest[i]);
        if (digest[i] != test2[i]) v = 1;
    }
    if (v) { printf("\nerror\n"); e++; }
    else printf("\nok\n");

    return e;
}

// These tests are copied from the original blake384_light.c.
int runtests384() {
    int i, v, e;
    uint8_t data[144], digest[64];
    uint8_t test1[]= {0x10, 0x28, 0x1F, 0x67, 0xE1, 0x35, 0xE9, 0x0A, 0xE8, 0xE8, 0x82, 0x25, 0x1A, 0x35, 0x55, 0x10,
           0xA7, 0x19, 0x36, 0x7A, 0xD7, 0x02, 0x27, 0xB1, 0x37, 0x34, 0x3E, 0x1B, 0xC1, 0x22, 0x01, 0x5C,
           0x29, 0x39, 0x1E, 0x85, 0x45, 0xB5, 0x27, 0x2D, 0x13, 0xA7, 0xC2, 0x87, 0x9D, 0xA3, 0xD8, 0x07};
    uint8_t test2[]= {0x0B, 0x98, 0x45, 0xDD, 0x42, 0x95, 0x66, 0xCD, 0xAB, 0x77, 0x2B, 0xA1, 0x95, 0xD2, 0x71, 0xEF,
           0xFE, 0x2D, 0x02, 0x11, 0xF1, 0x69, 0x91, 0xD7, 0x66, 0xBA, 0x74, 0x94, 0x47, 0xC5, 0xCD, 0xE5,
           0x69, 0x78, 0x0B, 0x2D, 0xAA, 0x66, 0xC4, 0xB2, 0x24, 0xA2, 0xEC, 0x2E, 0x5D, 0x09, 0x17, 0x4C};

    for (i = 0; i < 144; ++i) data[i] = 0;

    blake384_hash(digest, data, 1);
    v = 0; e = 0;
    for (i = 0; i < 48; ++i) {
        printf("%02X", digest[i]);
        if (digest[i] != test1[i]) v = 1;
    }
    if (v) { printf("\nerror\n"); e++; }
    else printf("\nok\n");

    for (i = 0; i < 144; ++i) data[i] = 0;

    blake384_hash(digest, data, 144);
    v = 0;
    for (i = 0; i < 48; ++i) {
        printf("%02X", digest[i]);
        if (digest[i] != test2[i]) v = 1;
    }
    if (v) { printf("\nerror\n"); e++; }
    else printf("\nok\n");

    return e;
}

#endif

int main() {
    int e = 0;
#if BLAKE256
    printf("BLAKE-256:\n");
    e += runtests256();
    printf("\nBLAKE-224:\n");
    e += runtests224();
#elif BLAKE512
    printf("BLAKE-512:\n");
    e += runtests512();
    printf("\nBLAKE-384:\n");
    e += runtests384();
#endif
    return e;
}
Something went wrong with that request. Please try again.