summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ecdsa/ecdsa.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/ecdsa/ecdsa.c (renamed from src/lib/libcrypto/ecdsa/ecs_ossl.c)101
1 files changed, 95 insertions, 6 deletions
diff --git a/src/lib/libcrypto/ecdsa/ecs_ossl.c b/src/lib/libcrypto/ecdsa/ecdsa.c
index 9886852e0f..c831e9f716 100644
--- a/src/lib/libcrypto/ecdsa/ecs_ossl.c
+++ b/src/lib/libcrypto/ecdsa/ecdsa.c
@@ -1,9 +1,6 @@
1/* $OpenBSD: ecs_ossl.c,v 1.73 2023/07/05 11:37:46 tb Exp $ */ 1/* $OpenBSD: ecdsa.c,v 1.1 2023/07/05 12:18:21 tb Exp $ */
2/*
3 * Written by Nils Larsch for the OpenSSL project
4 */
5/* ==================================================================== 2/* ====================================================================
6 * Copyright (c) 1998-2004 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2000-2002 The OpenSSL Project. All rights reserved.
7 * 4 *
8 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -25,7 +22,7 @@
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without 23 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact 24 * prior written permission. For written permission, please contact
28 * openssl-core@OpenSSL.org. 25 * licensing@OpenSSL.org.
29 * 26 *
30 * 5. Products derived from this software may not be called "OpenSSL" 27 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written 28 * nor may "OpenSSL" appear in their names without prior written
@@ -60,6 +57,7 @@
60 57
61#include <openssl/opensslconf.h> 58#include <openssl/opensslconf.h>
62 59
60#include <openssl/asn1t.h>
63#include <openssl/bn.h> 61#include <openssl/bn.h>
64#include <openssl/err.h> 62#include <openssl/err.h>
65#include <openssl/evp.h> 63#include <openssl/evp.h>
@@ -69,6 +67,97 @@
69#include "ec_local.h" 67#include "ec_local.h"
70#include "ecdsa_local.h" 68#include "ecdsa_local.h"
71 69
70static const ASN1_TEMPLATE ECDSA_SIG_seq_tt[] = {
71 {
72 .flags = 0,
73 .tag = 0,
74 .offset = offsetof(ECDSA_SIG, r),
75 .field_name = "r",
76 .item = &BIGNUM_it,
77 },
78 {
79 .flags = 0,
80 .tag = 0,
81 .offset = offsetof(ECDSA_SIG, s),
82 .field_name = "s",
83 .item = &BIGNUM_it,
84 },
85};
86
87const ASN1_ITEM ECDSA_SIG_it = {
88 .itype = ASN1_ITYPE_SEQUENCE,
89 .utype = V_ASN1_SEQUENCE,
90 .templates = ECDSA_SIG_seq_tt,
91 .tcount = sizeof(ECDSA_SIG_seq_tt) / sizeof(ASN1_TEMPLATE),
92 .funcs = NULL,
93 .size = sizeof(ECDSA_SIG),
94 .sname = "ECDSA_SIG",
95};
96
97ECDSA_SIG *ECDSA_SIG_new(void);
98void ECDSA_SIG_free(ECDSA_SIG *a);
99ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **a, const unsigned char **in, long len);
100int i2d_ECDSA_SIG(const ECDSA_SIG *a, unsigned char **out);
101
102ECDSA_SIG *
103d2i_ECDSA_SIG(ECDSA_SIG **a, const unsigned char **in, long len)
104{
105 return (ECDSA_SIG *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
106 &ECDSA_SIG_it);
107}
108
109int
110i2d_ECDSA_SIG(const ECDSA_SIG *a, unsigned char **out)
111{
112 return ASN1_item_i2d((ASN1_VALUE *)a, out, &ECDSA_SIG_it);
113}
114
115ECDSA_SIG *
116ECDSA_SIG_new(void)
117{
118 return (ECDSA_SIG *)ASN1_item_new(&ECDSA_SIG_it);
119}
120
121void
122ECDSA_SIG_free(ECDSA_SIG *a)
123{
124 ASN1_item_free((ASN1_VALUE *)a, &ECDSA_SIG_it);
125}
126
127void
128ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps)
129{
130 if (pr != NULL)
131 *pr = sig->r;
132 if (ps != NULL)
133 *ps = sig->s;
134}
135
136const BIGNUM *
137ECDSA_SIG_get0_r(const ECDSA_SIG *sig)
138{
139 return sig->r;
140}
141
142const BIGNUM *
143ECDSA_SIG_get0_s(const ECDSA_SIG *sig)
144{
145 return sig->s;
146}
147
148int
149ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s)
150{
151 if (r == NULL || s == NULL)
152 return 0;
153
154 BN_free(sig->r);
155 BN_free(sig->s);
156 sig->r = r;
157 sig->s = s;
158 return 1;
159}
160
72/* 161/*
73 * FIPS 186-5, section 6.4.1, step 2: convert hashed message into an integer. 162 * FIPS 186-5, section 6.4.1, step 2: convert hashed message into an integer.
74 * Use the order_bits leftmost bits if it exceeds the group order. 163 * Use the order_bits leftmost bits if it exceeds the group order.