2004-02-28 07:03:23 +08:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
ECDSA_SIG_new, ECDSA_SIG_free,
|
|
|
|
ECDSA_SIG_get0, ECDSA_SIG_get0_r, ECDSA_SIG_get0_s, ECDSA_SIG_set0
|
|
|
|
- Functions for creating, destroying and manipulating ECDSA_SIG objects
|
2004-02-28 07:03:23 +08:00
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
#include <openssl/ecdsa.h>
|
|
|
|
|
2016-03-15 00:45:51 +08:00
|
|
|
ECDSA_SIG *ECDSA_SIG_new(void);
|
|
|
|
void ECDSA_SIG_free(ECDSA_SIG *sig);
|
2016-06-10 05:09:48 +08:00
|
|
|
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
|
2018-05-27 15:08:08 +08:00
|
|
|
const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig);
|
|
|
|
const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig);
|
2016-06-10 05:52:04 +08:00
|
|
|
int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
|
2020-01-28 13:14:18 +08:00
|
|
|
|
2004-02-28 07:03:23 +08:00
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
2016-03-15 00:45:51 +08:00
|
|
|
B<ECDSA_SIG> is an opaque structure consisting of two BIGNUMs for the
|
2022-12-20 13:54:34 +08:00
|
|
|
I<r> and I<s> value of an Elliptic Curve Digital Signature Algorithm (ECDSA) signature
|
|
|
|
(see FIPS186-4 or X9.62).
|
|
|
|
The B<ECDSA_SIG> object was mainly used by the deprecated low level functions described in
|
|
|
|
L<ECDSA_sign(3)>, it is still required in order to be able to set or get the values of
|
|
|
|
I<r> and I<s> into or from a signature. This is mainly used for testing purposes as shown
|
|
|
|
in the L</EXAMPLES>.
|
2004-02-28 07:03:23 +08:00
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
ECDSA_SIG_new() allocates an empty B<ECDSA_SIG> structure.
|
|
|
|
Note: before OpenSSL 1.1.0, the I<r> and I<s> components were initialised.
|
2004-02-28 07:03:23 +08:00
|
|
|
|
2021-07-22 15:32:56 +08:00
|
|
|
ECDSA_SIG_free() frees the B<ECDSA_SIG> structure I<sig>.
|
2004-02-28 07:03:23 +08:00
|
|
|
|
2021-07-22 15:32:56 +08:00
|
|
|
ECDSA_SIG_get0() returns internal pointers the I<r> and I<s> values contained
|
|
|
|
in I<sig> and stores them in I<*pr> and I<*ps>, respectively.
|
|
|
|
The pointer I<pr> or I<ps> can be NULL, in which case the corresponding value
|
2018-05-27 15:08:08 +08:00
|
|
|
is not returned.
|
|
|
|
|
2021-07-22 15:32:56 +08:00
|
|
|
The values I<r>, I<s> can also be retrieved separately by the corresponding
|
2018-05-27 15:08:08 +08:00
|
|
|
function ECDSA_SIG_get0_r() and ECDSA_SIG_get0_s(), respectively.
|
2004-02-28 07:03:23 +08:00
|
|
|
|
2021-07-22 15:32:56 +08:00
|
|
|
Non-NULL I<r> and I<s> values can be set on the I<sig> by calling
|
|
|
|
ECDSA_SIG_set0(). Calling this function transfers the memory management of the
|
|
|
|
values to the B<ECDSA_SIG> object, and therefore the values that have been
|
|
|
|
passed in should not be freed by the caller.
|
2016-06-09 04:54:22 +08:00
|
|
|
|
2019-08-05 23:13:24 +08:00
|
|
|
See L<i2d_ECDSA_SIG(3)> and L<d2i_ECDSA_SIG(3)> for information about encoding
|
|
|
|
and decoding ECDSA signatures to/from DER.
|
2004-02-28 07:03:23 +08:00
|
|
|
|
|
|
|
=head1 RETURN VALUES
|
|
|
|
|
2018-06-03 04:17:32 +08:00
|
|
|
ECDSA_SIG_new() returns NULL if the allocation fails.
|
|
|
|
|
2016-06-09 04:54:22 +08:00
|
|
|
ECDSA_SIG_set0() returns 1 on success or 0 on failure.
|
|
|
|
|
2018-05-27 15:08:08 +08:00
|
|
|
ECDSA_SIG_get0_r() and ECDSA_SIG_get0_s() return the corresponding value,
|
|
|
|
or NULL if it is unset.
|
|
|
|
|
2004-02-28 07:03:23 +08:00
|
|
|
=head1 EXAMPLES
|
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
Extract signature I<r> and I<s> values from a ECDSA I<signature>
|
|
|
|
of size I<signaturelen>:
|
2004-02-28 07:03:23 +08:00
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
ECDSA_SIG *obj;
|
|
|
|
const BIGNUM *r, *s;
|
2004-02-28 07:03:23 +08:00
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
/* Load a signature into the ECDSA_SIG object */
|
|
|
|
obj = d2i_ECDSA_SIG(NULL, &signature, signaturelen);
|
|
|
|
if (obj == NULL)
|
2016-11-19 07:10:05 +08:00
|
|
|
/* error */
|
2016-03-15 00:45:51 +08:00
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
r = ECDSA_SIG_get0_r(obj);
|
|
|
|
s = ECDSA_SIG_get0_s(obj);
|
|
|
|
if (r == NULL || s == NULL)
|
2016-11-19 07:10:05 +08:00
|
|
|
/* error */
|
2016-03-15 00:45:51 +08:00
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
/* Use BN_bn2binpad() here to convert to r and s into byte arrays */
|
2004-02-28 07:03:23 +08:00
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
/*
|
|
|
|
* Do not try to access I<r> or I<s> after calling ECDSA_SIG_free(),
|
|
|
|
* as they are both freed by this call.
|
|
|
|
*/
|
|
|
|
ECDSA_SIG_free(obj);
|
2017-01-21 02:58:49 +08:00
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
Convert I<r> and I<s> byte arrays into an ECDSA_SIG I<signature> of
|
|
|
|
size I<signaturelen>:
|
2004-02-28 07:03:23 +08:00
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
ECDSA_SIG *obj = NULL;
|
|
|
|
unsigned char *signature = NULL;
|
|
|
|
size_t signaturelen;
|
|
|
|
BIGNUM *rbn = NULL, *sbn = NULL;
|
2004-02-28 07:03:23 +08:00
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
obj = ECDSA_SIG_new();
|
|
|
|
if (obj == NULL)
|
|
|
|
/* error */
|
|
|
|
rbn = BN_bin2bn(r, rlen, NULL);
|
|
|
|
sbn = BN_bin2bn(s, slen, NULL);
|
|
|
|
if (rbn == NULL || sbn == NULL)
|
|
|
|
/* error */
|
2004-02-28 07:03:23 +08:00
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
if (!ECDSA_SIG_set0(obj, rbn, sbn))
|
|
|
|
/* error */
|
|
|
|
/* Set these to NULL since they are now owned by obj */
|
|
|
|
rbn = sbn = NULL;
|
2004-02-28 07:03:23 +08:00
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
signaturelen = i2d_ECDSA_SIG(obj, &signature);
|
|
|
|
if (signaturelen <= 0)
|
|
|
|
/* error */
|
2004-02-28 07:03:23 +08:00
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
/*
|
|
|
|
* This signature could now be passed to L<EVP_DigestVerify(3)>
|
|
|
|
* or L<EVP_DigestVerifyFinal(3)>
|
|
|
|
*/
|
2004-02-28 07:03:23 +08:00
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
BN_free(rbn);
|
|
|
|
BN_free(sbn);
|
|
|
|
OPENSSL_free(signature);
|
|
|
|
ECDSA_SIG_free(obj);
|
2004-02-28 07:03:23 +08:00
|
|
|
|
|
|
|
=head1 CONFORMING TO
|
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
ANSI X9.62,
|
|
|
|
US Federal Information Processing Standard FIPS186-4
|
2004-02-28 07:03:23 +08:00
|
|
|
(Digital Signature Standard, DSS)
|
|
|
|
|
|
|
|
=head1 SEE ALSO
|
|
|
|
|
2019-04-18 22:09:45 +08:00
|
|
|
L<EC_KEY_new(3)>,
|
2016-03-15 00:45:51 +08:00
|
|
|
L<EVP_DigestSignInit(3)>,
|
2019-08-05 23:13:24 +08:00
|
|
|
L<EVP_DigestVerifyInit(3)>,
|
2020-01-28 13:14:18 +08:00
|
|
|
L<EVP_PKEY_sign(3)>
|
2019-08-05 23:13:24 +08:00
|
|
|
L<i2d_ECDSA_SIG(3)>,
|
2022-12-20 13:54:34 +08:00
|
|
|
L<d2i_ECDSA_SIG(3)>,
|
|
|
|
L<ECDSA_sign(3)>
|
2020-01-28 13:14:18 +08:00
|
|
|
|
2016-05-18 23:44:05 +08:00
|
|
|
=head1 COPYRIGHT
|
|
|
|
|
2022-12-20 13:54:34 +08:00
|
|
|
Copyright 2004-2022 The OpenSSL Project Authors. All Rights Reserved.
|
2016-05-18 23:44:05 +08:00
|
|
|
|
2018-12-06 21:04:44 +08:00
|
|
|
Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 23:44:05 +08:00
|
|
|
this file except in compliance with the License. You can obtain a copy
|
|
|
|
in the file LICENSE in the source distribution or at
|
|
|
|
L<https://www.openssl.org/source/license.html>.
|
|
|
|
|
|
|
|
=cut
|