"Fossies" - the Fresh Open Source Software Archive

Member "bahamut-2.1.5/src/libcrypto-compat.c" (28 May 2020, 2048 Bytes) of package /linux/privat/bahamut-2.1.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "libcrypto-compat.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.1.4_vs_2.1.5.

    1 /*
    2  * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
    3  *
    4  * Licensed under the OpenSSL license (the "License").  You may not use
    5  * this file except in compliance with the License.  You can obtain a copy
    6  * in the file LICENSE in the source distribution or at
    7  * https://www.openssl.org/source/license.html
    8  */
    9 
   10 #include "struct.h"
   11 #ifdef USE_SSL
   12 
   13 #if OPENSSL_VERSION_NUMBER < 0x10100000L
   14 
   15 void DH_get0_pqg(const DH *dh,
   16                  const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
   17 {
   18     if (p != NULL)
   19         *p = dh->p;
   20     if (q != NULL)
   21         *q = dh->q;
   22     if (g != NULL)
   23         *g = dh->g;
   24 }
   25 
   26 int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
   27 {
   28     /* If the fields p and g in d are NULL, the corresponding input
   29      * parameters MUST be non-NULL.  q may remain NULL.
   30      */
   31     if ((dh->p == NULL && p == NULL)
   32         || (dh->g == NULL && g == NULL))
   33         return 0;
   34 
   35     if (p != NULL) {
   36         BN_free(dh->p);
   37         dh->p = p;
   38     }
   39     if (q != NULL) {
   40         BN_free(dh->q);
   41         dh->q = q;
   42     }
   43     if (g != NULL) {
   44         BN_free(dh->g);
   45         dh->g = g;
   46     }
   47 
   48     if (q != NULL) {
   49         dh->length = BN_num_bits(q);
   50     }
   51 
   52     return 1;
   53 }
   54 
   55 void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key)
   56 {
   57     if (pub_key != NULL)
   58         *pub_key = dh->pub_key;
   59     if (priv_key != NULL)
   60         *priv_key = dh->priv_key;
   61 }
   62 
   63 int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key)
   64 {
   65     /* If the field pub_key in dh is NULL, the corresponding input
   66      * parameters MUST be non-NULL.  The priv_key field may
   67      * be left NULL.
   68      */
   69     if (dh->pub_key == NULL && pub_key == NULL)
   70         return 0;
   71 
   72     if (pub_key != NULL) {
   73         BN_free(dh->pub_key);
   74         dh->pub_key = pub_key;
   75     }
   76     if (priv_key != NULL) {
   77         BN_free(dh->priv_key);
   78         dh->priv_key = priv_key;
   79     }
   80 
   81     return 1;
   82 }
   83 
   84 int DH_set_length(DH *dh, long length)
   85 {
   86     dh->length = length;
   87     return 1;
   88 }
   89 
   90 #endif /* OPENSSL_VERSION_NUMBER */
   91 
   92 #endif /* USE_SSL */