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 48e7b18efcd77890f36272b46a4603d15a1ac221 authored by Neil Horman on 26 July 2024, 15:01:05 UTC, committed by Neil Horman on 09 August 2024, 12:28:38 UTC
limit bignums to 128 bytes
Keep us from spinning forever doing huge amounts of math in the fuzzer

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/25013)

(cherry picked from commit f0768376e1639d12a328745ef69c90d584138074)
1 parent 67c6330
  • Files
  • Changes
  • 6cdbfeb
  • /
  • test
  • /
  • namemap_internal_test.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:48e7b18efcd77890f36272b46a4603d15a1ac221 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:48e7b18efcd77890f36272b46a4603d15a1ac221 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:48e7b18efcd77890f36272b46a4603d15a1ac221
content badge Iframe embedding
swh:1:cnt:b3f498004fb129ecb07259b88c22552a664c7a53
namemap_internal_test.c
/*
 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the Apache License 2.0 (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/evp.h>
#include "internal/namemap.h"
#include "testutil.h"

#define NAME1 "name1"
#define NAME2 "name2"
#define ALIAS1 "alias1"
#define ALIAS1_UC "ALIAS1"

static int test_namemap_empty(void)
{
    OSSL_NAMEMAP *nm = NULL;
    int ok;

    ok = TEST_int_eq(ossl_namemap_empty(NULL), 1)
         && TEST_ptr(nm = ossl_namemap_new())
         && TEST_int_eq(ossl_namemap_empty(nm), 1)
         && TEST_int_ne(ossl_namemap_add_name(nm, 0, NAME1), 0)
         && TEST_int_eq(ossl_namemap_empty(nm), 0);
    ossl_namemap_free(nm);
    return ok;
}

static int test_namemap(OSSL_NAMEMAP *nm)
{
    int num1 = ossl_namemap_add_name(nm, 0, NAME1);
    int num2 = ossl_namemap_add_name(nm, 0, NAME2);
    int num3 = ossl_namemap_add_name(nm, num1, ALIAS1);
    int num4 = ossl_namemap_add_name(nm, 0, ALIAS1_UC);
    int check1 = ossl_namemap_name2num(nm, NAME1);
    int check2 = ossl_namemap_name2num(nm, NAME2);
    int check3 = ossl_namemap_name2num(nm, ALIAS1);
    int check4 = ossl_namemap_name2num(nm, ALIAS1_UC);
    int false1 = ossl_namemap_name2num(nm, "cookie");

    return TEST_int_ne(num1, 0)
        && TEST_int_ne(num2, 0)
        && TEST_int_eq(num1, num3)
        && TEST_int_eq(num3, num4)
        && TEST_int_eq(num1, check1)
        && TEST_int_eq(num2, check2)
        && TEST_int_eq(num3, check3)
        && TEST_int_eq(num4, check4)
        && TEST_int_eq(false1, 0);
}

static int test_namemap_independent(void)
{
    OSSL_NAMEMAP *nm = ossl_namemap_new();
    int ok = TEST_ptr(nm) && test_namemap(nm);

    ossl_namemap_free(nm);
    return ok;
}

static int test_namemap_stored(void)
{
    OSSL_NAMEMAP *nm = ossl_namemap_stored(NULL);

    return TEST_ptr(nm)
        && test_namemap(nm);
}

/*
 * Test that EVP_get_digestbyname() will use the namemap when it can't find
 * entries in the legacy method database.
 */
static int test_digestbyname(void)
{
    int id;
    OSSL_NAMEMAP *nm = ossl_namemap_stored(NULL);
    const EVP_MD *sha256, *foo;

    if (!TEST_ptr(nm))
        return 0;
    id = ossl_namemap_add_name(nm, 0, "SHA256");
    if (!TEST_int_ne(id, 0))
        return 0;
    if (!TEST_int_eq(ossl_namemap_add_name(nm, id, "foo"), id))
        return 0;

    sha256 = EVP_get_digestbyname("SHA256");
    if (!TEST_ptr(sha256))
        return 0;
    foo = EVP_get_digestbyname("foo");
    if (!TEST_ptr_eq(sha256, foo))
        return 0;

    return 1;
}

/*
 * Test that EVP_get_cipherbyname() will use the namemap when it can't find
 * entries in the legacy method database.
 */
static int test_cipherbyname(void)
{
    int id;
    OSSL_NAMEMAP *nm = ossl_namemap_stored(NULL);
    const EVP_CIPHER *aes128, *bar;

    if (!TEST_ptr(nm))
        return 0;
    id = ossl_namemap_add_name(nm, 0, "AES-128-CBC");
    if (!TEST_int_ne(id, 0))
        return 0;
    if (!TEST_int_eq(ossl_namemap_add_name(nm, id, "bar"), id))
        return 0;

    aes128 = EVP_get_cipherbyname("AES-128-CBC");
    if (!TEST_ptr(aes128))
        return 0;
    bar = EVP_get_cipherbyname("bar");
    if (!TEST_ptr_eq(aes128, bar))
        return 0;

    return 1;
}

/*
 * Test that EVP_CIPHER_is_a() responds appropriately, even for ciphers that
 * are entirely legacy.
 */
static int test_cipher_is_a(void)
{
    EVP_CIPHER *fetched = EVP_CIPHER_fetch(NULL, "AES-256-CCM", NULL);
    int rv = 1;

    if (!TEST_ptr(fetched))
        return 0;
    if (!TEST_true(EVP_CIPHER_is_a(fetched, "id-aes256-CCM"))
        || !TEST_false(EVP_CIPHER_is_a(fetched, "AES-128-GCM")))
        rv = 0;
    if (!TEST_true(EVP_CIPHER_is_a(EVP_aes_256_gcm(), "AES-256-GCM"))
        || !TEST_false(EVP_CIPHER_is_a(EVP_aes_256_gcm(), "AES-128-CCM")))
        rv = 0;

    EVP_CIPHER_free(fetched);
    return rv;
}

/*
 * Test that EVP_MD_is_a() responds appropriately, even for MDs that are
 * entirely legacy.
 */
static int test_digest_is_a(void)
{
    EVP_MD *fetched = EVP_MD_fetch(NULL, "SHA2-512", NULL);
    int rv = 1;

    if (!TEST_ptr(fetched))
        return 0;
    if (!TEST_true(EVP_MD_is_a(fetched, "SHA512"))
        || !TEST_false(EVP_MD_is_a(fetched, "SHA1")))
        rv = 0;
    if (!TEST_true(EVP_MD_is_a(EVP_sha256(), "SHA2-256"))
        || !TEST_false(EVP_MD_is_a(EVP_sha256(), "SHA3-256")))
        rv = 0;

    EVP_MD_free(fetched);
    return rv;
}

int setup_tests(void)
{
    ADD_TEST(test_namemap_empty);
    ADD_TEST(test_namemap_independent);
    ADD_TEST(test_namemap_stored);
    ADD_TEST(test_digestbyname);
    ADD_TEST(test_cipherbyname);
    ADD_TEST(test_digest_is_a);
    ADD_TEST(test_cipher_is_a);
    return 1;
}
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