Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision d4d986441132212c24107fc6163fd9ba28bec1e4 authored by Roelof duToit on 13 July 2017, 18:09:19 UTC, committed by Matt Caswell on 14 July 2017, 10:19:07 UTC
Update PR#3925
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3925)
1 parent a071d72
  • Files
  • Changes
  • 2917e44
  • /
  • test
  • /
  • sha256t.c
Raw File
Cook and download a directory from the Software Heritage Vault

You have requested the cooking of the directory with identifier None into a standard tar.gz archive.

Are you sure you want to continue ?

Download a directory from the Software Heritage Vault

You have requested the download of the directory with identifier None as a standard tar.gz archive.

Are you sure you want to continue ?

Cook and download a revision from the Software Heritage Vault

You have requested the cooking of the history heading to revision with identifier swh:1:rev:d4d986441132212c24107fc6163fd9ba28bec1e4 into a bare git archive.

Are you sure you want to continue ?

Download a revision from the Software Heritage Vault

You have requested the download of the history heading to revision with identifier swh:1:rev:d4d986441132212c24107fc6163fd9ba28bec1e4 as a bare git archive.

Are you sure you want to continue ?

Invalid Email !

The provided email is not well-formed.

Download link has expired

The requested archive is no longer available for download from the Software Heritage Vault.

Do you want to cook it again ?

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • content
revision badge
swh:1:rev:d4d986441132212c24107fc6163fd9ba28bec1e4
content badge Iframe embedding
swh:1:cnt:c6ce1ae1873c5eab97d7ac943e009bce1bc94fdc
sha256t.c
/*
 * Copyright 2004-2017 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the OpenSSL license (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

#include <openssl/sha.h>
#include <openssl/evp.h>

#include "testutil.h"

static const unsigned char app_b1[SHA256_DIGEST_LENGTH] = {
    0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
    0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
    0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
    0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
};

static const unsigned char app_b2[SHA256_DIGEST_LENGTH] = {
    0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8,
    0xe5, 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39,
    0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67,
    0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1
};

static const unsigned char app_b3[SHA256_DIGEST_LENGTH] = {
    0xcd, 0xc7, 0x6e, 0x5c, 0x99, 0x14, 0xfb, 0x92,
    0x81, 0xa1, 0xc7, 0xe2, 0x84, 0xd7, 0x3e, 0x67,
    0xf1, 0x80, 0x9a, 0x48, 0xa4, 0x97, 0x20, 0x0e,
    0x04, 0x6d, 0x39, 0xcc, 0xc7, 0x11, 0x2c, 0xd0
};

static const unsigned char addenum_1[SHA224_DIGEST_LENGTH] = {
    0x23, 0x09, 0x7d, 0x22, 0x34, 0x05, 0xd8, 0x22,
    0x86, 0x42, 0xa4, 0x77, 0xbd, 0xa2, 0x55, 0xb3,
    0x2a, 0xad, 0xbc, 0xe4, 0xbd, 0xa0, 0xb3, 0xf7,
    0xe3, 0x6c, 0x9d, 0xa7
};

static const unsigned char addenum_2[SHA224_DIGEST_LENGTH] = {
    0x75, 0x38, 0x8b, 0x16, 0x51, 0x27, 0x76, 0xcc,
    0x5d, 0xba, 0x5d, 0xa1, 0xfd, 0x89, 0x01, 0x50,
    0xb0, 0xc6, 0x45, 0x5c, 0xb4, 0xf5, 0x8b, 0x19,
    0x52, 0x52, 0x25, 0x25
};

static const unsigned char addenum_3[SHA224_DIGEST_LENGTH] = {
    0x20, 0x79, 0x46, 0x55, 0x98, 0x0c, 0x91, 0xd8,
    0xbb, 0xb4, 0xc1, 0xea, 0x97, 0x61, 0x8a, 0x4b,
    0xf0, 0x3f, 0x42, 0x58, 0x19, 0x48, 0xb2, 0xee,
    0x4e, 0xe7, 0xad, 0x67
};

static int test_sha256_short(void)
{
    unsigned char md[SHA256_DIGEST_LENGTH];

    if (!TEST_true(EVP_Digest("abc", 3, md, NULL, EVP_sha256(), NULL)))
        return 0;
    return TEST_mem_eq(md, sizeof(md), app_b1, sizeof(app_b1));
}

static int test_sha256_long(void)
{
    unsigned char md[SHA256_DIGEST_LENGTH];

    if (!TEST_true(EVP_Digest("abcdbcde" "cdefdefg" "efghfghi" "ghijhijk"
                              "ijkljklm" "klmnlmno" "mnopnopq", 56, md,
                               NULL, EVP_sha256(), NULL)))
        return 0;
    return TEST_mem_eq(md, sizeof(md), app_b2, sizeof(app_b2));
}

static int test_sha256_multi(void)
{
    unsigned char md[SHA256_DIGEST_LENGTH];
    int i, testresult = 0;
    EVP_MD_CTX *evp;
    static const char *updstr = "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
                                "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
                                "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
                                "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
                                "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
                                "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
                                "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
                                "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
                                "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa";

    evp = EVP_MD_CTX_new();
    if (!TEST_ptr(evp))
        return 0;
    if (!TEST_true(EVP_DigestInit_ex(evp, EVP_sha256(), NULL)))
        goto end;
    for (i = 0; i < 1000000; i += 288)
        if (!TEST_true(EVP_DigestUpdate(evp, updstr,
                                        (1000000 - i) < 288 ? 1000000 - i
                                                            : 288)))
            goto end;
    if (!TEST_true(EVP_DigestFinal_ex(evp, md, NULL))
        || !TEST_mem_eq(md, sizeof(md), app_b3, sizeof(app_b3)))
        goto end;

    testresult = 1;
 end:
    EVP_MD_CTX_free(evp);
    return testresult;
}

static int test_sha224_short(void)
{
    unsigned char md[SHA224_DIGEST_LENGTH];

    if (!TEST_true(EVP_Digest("abc", 3, md, NULL, EVP_sha224(), NULL)))
        return 0;
    return TEST_mem_eq(md, sizeof(md), addenum_1, sizeof(addenum_1));
}

static int test_sha224_long(void)
{
    unsigned char md[SHA224_DIGEST_LENGTH];

    if (!TEST_true(EVP_Digest("abcdbcde" "cdefdefg" "efghfghi" "ghijhijk"
                              "ijkljklm" "klmnlmno" "mnopnopq", 56, md,
                              NULL, EVP_sha224(), NULL)))
        return 0;
    return TEST_mem_eq(md, sizeof(md), addenum_2, sizeof(addenum_2));
}

static int test_sha224_multi(void)
{
    unsigned char md[SHA224_DIGEST_LENGTH];
    int i, testresult = 0;
    EVP_MD_CTX *evp;
    static const char *updstr = "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
                                "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa";

    evp = EVP_MD_CTX_new();
    if (!TEST_ptr(evp))
        return 0;
    if (!TEST_true(EVP_DigestInit_ex(evp, EVP_sha224(), NULL)))
        goto end;
    for (i = 0; i < 1000000; i += 64)
        if (!TEST_true(EVP_DigestUpdate(evp, updstr,
                                        (1000000 - i) < 64 ? 1000000 - i : 64)))
            goto end;
    if (!TEST_true(EVP_DigestFinal_ex(evp, md, NULL))
        || !TEST_mem_eq(md, sizeof(md), addenum_3, sizeof(addenum_3)))
        goto end;

    testresult = 1;
 end:
    EVP_MD_CTX_free(evp);
    return testresult;
}

void register_tests(void)
{
    ADD_TEST(test_sha256_short);
    ADD_TEST(test_sha256_long);
    ADD_TEST(test_sha256_multi);
    ADD_TEST(test_sha224_short);
    ADD_TEST(test_sha224_long);
    ADD_TEST(test_sha224_multi);
}
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top