Ruby: ext/openssl/openssl_missing.c Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

openssl_missing.c
Go to the documentation of this file.
1/*
2 * 'OpenSSL for Ruby' project
3 * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
4 * All rights reserved.
5 */
6/*
7 * This program is licensed under the same licence as Ruby.
8 * (See the file 'LICENCE'.)
9 */
10#include RUBY_EXTCONF_H
11
12#include <string.h> /* memcpy() */
13#if !defined(OPENSSL_NO_ENGINE)
14# include <openssl/engine.h>
15#endif
16#if !defined(OPENSSL_NO_HMAC)
17# include <openssl/hmac.h>
18#endif
19#include <openssl/x509_vfy.h>
20
21#include "openssl_missing.h"
22
23/* added in 1.0.2 */
24#if !defined(OPENSSL_NO_EC)
25#if !defined(HAVE_EC_CURVE_NIST2NID)
26static struct {
27 const char *name;
28 int nid;
29} nist_curves[] = {
30 {"B-163", NID_sect163r2},
31 {"B-233", NID_sect233r1},
32 {"B-283", NID_sect283r1},
33 {"B-409", NID_sect409r1},
34 {"B-571", NID_sect571r1},
35 {"K-163", NID_sect163k1},
36 {"K-233", NID_sect233k1},
37 {"K-283", NID_sect283k1},
38 {"K-409", NID_sect409k1},
39 {"K-571", NID_sect571k1},
40 {"P-192", NID_X9_62_prime192v1},
41 {"P-224", NID_secp224r1},
42 {"P-256", NID_X9_62_prime256v1},
43 {"P-384", NID_secp384r1},
44 {"P-521", NID_secp521r1}
45};
46
47int
48ossl_EC_curve_nist2nid(const char *name)
49{
50 size_t i;
51 for (i = 0; i < (sizeof(nist_curves) / sizeof(nist_curves[0])); i++) {
52 if (!strcmp(nist_curves[i].name, name))
53 return nist_curves[i].nid;
54 }
55 return NID_undef;
56}
57#endif
58#endif
59
60/*** added in 1.1.0 ***/
61#if !defined(HAVE_HMAC_CTX_NEW)
62HMAC_CTX *
63ossl_HMAC_CTX_new(void)
64{
65 HMAC_CTX *ctx = OPENSSL_malloc(sizeof(HMAC_CTX));
66 if (!ctx)
67 return NULL;
68 HMAC_CTX_init(ctx);
69 return ctx;
70}
71#endif
72
73#if !defined(HAVE_HMAC_CTX_FREE)
74void
75ossl_HMAC_CTX_free(HMAC_CTX *ctx)
76{
77 if (ctx) {
78 HMAC_CTX_cleanup(ctx);
79 OPENSSL_free(ctx);
80 }
81}
82#endif
83
84#if !defined(HAVE_X509_CRL_GET0_SIGNATURE)
85void
86ossl_X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig,
87 const X509_ALGOR **palg)
88{
89 if (psig != NULL)
90 *psig = crl->signature;
91 if (palg != NULL)
92 *palg = crl->sig_alg;
93}
94#endif
95
96#if !defined(HAVE_X509_REQ_GET0_SIGNATURE)
97void
98ossl_X509_REQ_get0_signature(const X509_REQ *req, const ASN1_BIT_STRING **psig,
99 const X509_ALGOR **palg)
100{
101 if (psig != NULL)
102 *psig = req->signature;
103 if (palg != NULL)
104 *palg = req->sig_alg;
105}
106#endif
ossl_HMAC_CTX_new
HMAC_CTX * ossl_HMAC_CTX_new(void)
Definition: openssl_missing.c:63
ossl_HMAC_CTX_free
void ossl_HMAC_CTX_free(HMAC_CTX *ctx)
Definition: openssl_missing.c:75
nid
int nid
Definition: openssl_missing.c:28
name
const char * name
Definition: openssl_missing.c:27
ossl_X509_REQ_get0_signature
void ossl_X509_REQ_get0_signature(const X509_REQ *req, const ASN1_BIT_STRING **psig, const X509_ALGOR **palg)
Definition: openssl_missing.c:98
ossl_X509_CRL_get0_signature
void ossl_X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig, const X509_ALGOR **palg)
Definition: openssl_missing.c:86
ossl_EC_curve_nist2nid
int ossl_EC_curve_nist2nid(const char *name)
Definition: openssl_missing.c:48
openssl_missing.h
NULL
#define NULL
Definition: regenc.h:69