VirtualBox

Ignore:
Timestamp:
Mar 3, 2022 7:17:34 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
150325
Message:

libs/openssl-3.0.1: started applying and adjusting our OpenSSL changes to 3.0.1. bugref:10128

Location:
trunk/src/libs/openssl-3.0.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/openssl-3.0.1

    • Property svn:mergeinfo
      •  

        old new  
        1212/vendor/openssl/1.1.1c:131722-131725
        1313/vendor/openssl/1.1.1k:145841-145843
         14/vendor/openssl/3.0.1:150323-150324
         15/vendor/openssl/current:147554-150322
  • trunk/src/libs/openssl-3.0.1/crypto/ec/ec_mult.c

    r91772 r94082  
    11/*
    2  * Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
     2 * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
    33 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
    44 *
    5  * Licensed under the OpenSSL license (the "License").  You may not use
     5 * Licensed under the Apache License 2.0 (the "License").  You may not use
    66 * this file except in compliance with the License.  You can obtain a copy
    77 * in the file LICENSE in the source distribution or at
    88 * https://www.openssl.org/source/license.html
    99 */
     10
     11/*
     12 * ECDSA low level APIs are deprecated for public use, but still ok for
     13 * internal use.
     14 */
     15#include "internal/deprecated.h"
    1016
    1117#include <string.h>
     
    5258    ret = OPENSSL_zalloc(sizeof(*ret));
    5359    if (ret == NULL) {
    54         ECerr(EC_F_EC_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
     60        ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
    5561        return ret;
    5662    }
     
    6369    ret->lock = CRYPTO_THREAD_lock_new();
    6470    if (ret->lock == NULL) {
    65         ECerr(EC_F_EC_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
     71        ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
    6672        OPENSSL_free(ret);
    6773        return NULL;
     
    137143 * Returns 1 on success, 0 otherwise.
    138144 */
    139 int ec_scalar_mul_ladder(const EC_GROUP *group, EC_POINT *r,
    140                          const BIGNUM *scalar, const EC_POINT *point,
    141                          BN_CTX *ctx)
     145int ossl_ec_scalar_mul_ladder(const EC_GROUP *group, EC_POINT *r,
     146                              const BIGNUM *scalar, const EC_POINT *point,
     147                              BN_CTX *ctx)
    142148{
    143149    int i, cardinality_bits, group_top, kbit, pbit, Z_is_one;
     
    154160
    155161    if (BN_is_zero(group->order)) {
    156         ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_UNKNOWN_ORDER);
     162        ERR_raise(ERR_LIB_EC, EC_R_UNKNOWN_ORDER);
    157163        return 0;
    158164    }
    159165    if (BN_is_zero(group->cofactor)) {
    160         ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_UNKNOWN_COFACTOR);
     166        ERR_raise(ERR_LIB_EC, EC_R_UNKNOWN_COFACTOR);
    161167        return 0;
    162168    }
     
    166172    if (((p = EC_POINT_new(group)) == NULL)
    167173        || ((s = EC_POINT_new(group)) == NULL)) {
    168         ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_MALLOC_FAILURE);
     174        ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
    169175        goto err;
    170176    }
     
    172178    if (point == NULL) {
    173179        if (!EC_POINT_copy(p, group->generator)) {
    174             ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_EC_LIB);
     180            ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
    175181            goto err;
    176182        }
    177183    } else {
    178184        if (!EC_POINT_copy(p, point)) {
    179             ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_EC_LIB);
     185            ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
    180186            goto err;
    181187        }
     
    190196    k = BN_CTX_get(ctx);
    191197    if (k == NULL) {
    192         ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_MALLOC_FAILURE);
     198        ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
    193199        goto err;
    194200    }
    195201
    196202    if (!BN_mul(cardinality, group->order, group->cofactor, ctx)) {
    197         ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);
     203        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
    198204        goto err;
    199205    }
     
    209215    if ((bn_wexpand(k, group_top + 2) == NULL)
    210216        || (bn_wexpand(lambda, group_top + 2) == NULL)) {
    211         ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);
     217        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
    212218        goto err;
    213219    }
    214220
    215221    if (!BN_copy(k, scalar)) {
    216         ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);
     222        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
    217223        goto err;
    218224    }
     
    226232         */
    227233        if (!BN_nnmod(k, k, cardinality, ctx)) {
    228             ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);
     234            ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
    229235            goto err;
    230236        }
     
    232238
    233239    if (!BN_add(lambda, k, cardinality)) {
    234         ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);
     240        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
    235241        goto err;
    236242    }
    237243    BN_set_flags(lambda, BN_FLG_CONSTTIME);
    238244    if (!BN_add(k, lambda, cardinality)) {
    239         ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);
     245        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
    240246        goto err;
    241247    }
     
    257263        || (bn_wexpand(p->Y, group_top) == NULL)
    258264        || (bn_wexpand(p->Z, group_top) == NULL)) {
    259         ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);
     265        ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
    260266        goto err;
    261267    }
    262268
    263269    /* ensure input point is in affine coords for ladder step efficiency */
    264     if (!p->Z_is_one && !EC_POINT_make_affine(group, p, ctx)) {
    265             ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_EC_LIB);
     270    if (!p->Z_is_one && (group->meth->make_affine == NULL
     271                         || !group->meth->make_affine(group, p, ctx))) {
     272            ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
    266273            goto err;
    267274    }
     
    269276    /* Initialize the Montgomery ladder */
    270277    if (!ec_point_ladder_pre(group, r, s, p, ctx)) {
    271         ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_LADDER_PRE_FAILURE);
     278        ERR_raise(ERR_LIB_EC, EC_R_LADDER_PRE_FAILURE);
    272279        goto err;
    273280    }
     
    349356        /* Perform a single step of the Montgomery ladder */
    350357        if (!ec_point_ladder_step(group, r, s, p, ctx)) {
    351             ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_LADDER_STEP_FAILURE);
     358            ERR_raise(ERR_LIB_EC, EC_R_LADDER_STEP_FAILURE);
    352359            goto err;
    353360        }
     
    364371    /* Finalize ladder (and recover full point coordinates) */
    365372    if (!ec_point_ladder_post(group, r, s, p, ctx)) {
    366         ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_LADDER_POST_FAILURE);
     373        ERR_raise(ERR_LIB_EC, EC_R_LADDER_POST_FAILURE);
    367374        goto err;
    368375    }
     
    381388
    382389/*
    383  * TODO: table should be optimised for the wNAF-based implementation,
     390 * Table could be optimised for the wNAF-based implementation,
    384391 * sometimes smaller windows will give better performance (thus the
    385392 * boundaries should be increased)
     
    401408 * in the addition if scalar != NULL
    402409 */
    403 int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
    404                 size_t num, const EC_POINT *points[], const BIGNUM *scalars[],
    405                 BN_CTX *ctx)
     410int ossl_ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
     411                     size_t num, const EC_POINT *points[],
     412                     const BIGNUM *scalars[], BN_CTX *ctx)
    406413{
    407414    const EC_POINT *generator = NULL;
     
    444451             * always call the ladder version.
    445452             */
    446             return ec_scalar_mul_ladder(group, r, scalar, NULL, ctx);
     453            return ossl_ec_scalar_mul_ladder(group, r, scalar, NULL, ctx);
    447454        }
    448455        if ((scalar == NULL) && (num == 1) && (scalars[0] != group->order)) {
     
    454461             * actually set and we always call the ladder version.
    455462             */
    456             return ec_scalar_mul_ladder(group, r, scalars[0], points[0], ctx);
     463            return ossl_ec_scalar_mul_ladder(group, r, scalars[0], points[0],
     464                                             ctx);
    457465        }
    458466    }
     
    461469        generator = EC_GROUP_get0_generator(group);
    462470        if (generator == NULL) {
    463             ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR);
     471            ERR_raise(ERR_LIB_EC, EC_R_UNDEFINED_GENERATOR);
    464472            goto err;
    465473        }
     
    489497            /* check that pre_comp looks sane */
    490498            if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) {
    491                 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
     499                ERR_raise(ERR_LIB_EC, ERR_R_INTERNAL_ERROR);
    492500                goto err;
    493501            }
     
    514522
    515523    if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) {
    516         ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);
     524        ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
    517525        goto err;
    518526    }
     
    544552        if (pre_comp == NULL) {
    545553            if (num_scalar != 1) {
    546                 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
     554                ERR_raise(ERR_LIB_EC, ERR_R_INTERNAL_ERROR);
    547555                goto err;
    548556            }
     
    553561
    554562            if (num_scalar != 0) {
    555                 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
     563                ERR_raise(ERR_LIB_EC, ERR_R_INTERNAL_ERROR);
    556564                goto err;
    557565            }
     
    596604                    numblocks = (tmp_len + blocksize - 1) / blocksize;
    597605                    if (numblocks > pre_comp->numblocks) {
    598                         ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
     606                        ERR_raise(ERR_LIB_EC, ERR_R_INTERNAL_ERROR);
    599607                        OPENSSL_free(tmp_wNAF);
    600608                        goto err;
     
    611619                        wNAF_len[i] = blocksize;
    612620                        if (tmp_len < blocksize) {
    613                             ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
     621                            ERR_raise(ERR_LIB_EC, ERR_R_INTERNAL_ERROR);
    614622                            OPENSSL_free(tmp_wNAF);
    615623                            goto err;
     
    626634                    wNAF[i] = OPENSSL_malloc(wNAF_len[i]);
    627635                    if (wNAF[i] == NULL) {
    628                         ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);
     636                        ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
    629637                        OPENSSL_free(tmp_wNAF);
    630638                        goto err;
     
    635643
    636644                    if (*tmp_points == NULL) {
    637                         ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
     645                        ERR_raise(ERR_LIB_EC, ERR_R_INTERNAL_ERROR);
    638646                        OPENSSL_free(tmp_wNAF);
    639647                        goto err;
     
    655663    val = OPENSSL_malloc((num_val + 1) * sizeof(val[0]));
    656664    if (val == NULL) {
    657         ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);
     665        ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
    658666        goto err;
    659667    }
     
    672680    }
    673681    if (!(v == val + num_val)) {
    674         ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
     682        ERR_raise(ERR_LIB_EC, ERR_R_INTERNAL_ERROR);
    675683        goto err;
    676684    }
     
    706714    }
    707715
    708     if (!EC_POINTs_make_affine(group, num_val, val, ctx))
     716    if (group->meth->points_make_affine == NULL
     717        || !group->meth->points_make_affine(group, num_val, val, ctx))
    709718        goto err;
    710719
     
    746755                         *
    747756                         * The underlying EC_METHOD can optionally implement this function:
    748                          * ec_point_blind_coordinates() returns 0 in case of errors or 1 on
     757                         * ossl_ec_point_blind_coordinates() returns 0 in case of errors or 1 on
    749758                         * success or if coordinate blinding is not implemented for this
    750759                         * group.
    751760                         */
    752                         if (!ec_point_blind_coordinates(group, r, ctx)) {
    753                             ECerr(EC_F_EC_WNAF_MUL, EC_R_POINT_COORDINATES_BLIND_FAILURE);
     761                        if (!ossl_ec_point_blind_coordinates(group, r, ctx)) {
     762                            ERR_raise(ERR_LIB_EC, EC_R_POINT_COORDINATES_BLIND_FAILURE);
    754763                            goto err;
    755764                        }
     
    800809
    801810/*-
    802  * ec_wNAF_precompute_mult()
     811 * ossl_ec_wNAF_precompute_mult()
    803812 * creates an EC_PRE_COMP object with preprecomputed multiples of the generator
    804  * for use with wNAF splitting as implemented in ec_wNAF_mul().
     813 * for use with wNAF splitting as implemented in ossl_ec_wNAF_mul().
    805814 *
    806815 * 'pre_comp->points' is an array of multiples of the generator
     
    819828 * points[2^(w-1)*numblocks]       = NULL
    820829 */
    821 int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
     830int ossl_ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
    822831{
    823832    const EC_POINT *generator;
    824833    EC_POINT *tmp_point = NULL, *base = NULL, **var;
    825     BN_CTX *new_ctx = NULL;
    826834    const BIGNUM *order;
    827835    size_t i, bits, w, pre_points_per_block, blocksize, numblocks, num;
     
    829837    EC_PRE_COMP *pre_comp;
    830838    int ret = 0;
     839    int used_ctx = 0;
     840#ifndef FIPS_MODULE
     841    BN_CTX *new_ctx = NULL;
     842#endif
    831843
    832844    /* if there is an old EC_PRE_COMP object, throw it away */
     
    837849    generator = EC_GROUP_get0_generator(group);
    838850    if (generator == NULL) {
    839         ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, EC_R_UNDEFINED_GENERATOR);
    840         goto err;
    841     }
    842 
    843     if (ctx == NULL) {
     851        ERR_raise(ERR_LIB_EC, EC_R_UNDEFINED_GENERATOR);
     852        goto err;
     853    }
     854
     855#ifndef FIPS_MODULE
     856    if (ctx == NULL)
    844857        ctx = new_ctx = BN_CTX_new();
    845         if (ctx == NULL)
    846             goto err;
    847     }
     858#endif
     859    if (ctx == NULL)
     860        goto err;
    848861
    849862    BN_CTX_start(ctx);
     863    used_ctx = 1;
    850864
    851865    order = EC_GROUP_get0_order(group);
     
    853867        goto err;
    854868    if (BN_is_zero(order)) {
    855         ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, EC_R_UNKNOWN_ORDER);
     869        ERR_raise(ERR_LIB_EC, EC_R_UNKNOWN_ORDER);
    856870        goto err;
    857871    }
     
    881895    points = OPENSSL_malloc(sizeof(*points) * (num + 1));
    882896    if (points == NULL) {
    883         ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE);
     897        ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
    884898        goto err;
    885899    }
     
    889903    for (i = 0; i < num; i++) {
    890904        if ((var[i] = EC_POINT_new(group)) == NULL) {
    891             ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE);
     905            ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
    892906            goto err;
    893907        }
     
    896910    if ((tmp_point = EC_POINT_new(group)) == NULL
    897911        || (base = EC_POINT_new(group)) == NULL) {
    898         ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE);
     912        ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
    899913        goto err;
    900914    }
     
    928942
    929943            if (blocksize <= 2) {
    930                 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_INTERNAL_ERROR);
     944                ERR_raise(ERR_LIB_EC, ERR_R_INTERNAL_ERROR);
    931945                goto err;
    932946            }
     
    941955    }
    942956
    943     if (!EC_POINTs_make_affine(group, num, points, ctx))
     957    if (group->meth->points_make_affine == NULL
     958        || !group->meth->points_make_affine(group, num, points, ctx))
    944959        goto err;
    945960
     
    956971
    957972 err:
    958     BN_CTX_end(ctx);
     973    if (used_ctx)
     974        BN_CTX_end(ctx);
     975#ifndef FIPS_MODULE
    959976    BN_CTX_free(new_ctx);
     977#endif
    960978    EC_ec_pre_comp_free(pre_comp);
    961979    if (points) {
     
    971989}
    972990
    973 int ec_wNAF_have_precompute_mult(const EC_GROUP *group)
     991int ossl_ec_wNAF_have_precompute_mult(const EC_GROUP *group)
    974992{
    975993    return HAVEPRECOMP(group, ec);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette