summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_mul.c
diff options
context:
space:
mode:
authorjsing <>2023-01-20 17:31:52 +0000
committerjsing <>2023-01-20 17:31:52 +0000
commitec907bb8e44028294d6c2a6faf9c735ce8012e48 (patch)
treeb7a2361e00d87650a48e90b0530c6a86d27e0039 /src/lib/libcrypto/bn/bn_mul.c
parenta50b434b87829ee0d12767c21ae98194684ab720 (diff)
downloadopenbsd-ec907bb8e44028294d6c2a6faf9c735ce8012e48.tar.gz
openbsd-ec907bb8e44028294d6c2a6faf9c735ce8012e48.tar.bz2
openbsd-ec907bb8e44028294d6c2a6faf9c735ce8012e48.zip
Move bn_{mul,sqr}_comba{4,8}() from bn_asm.c to bn_mul.c/bn_sqr.c.
Wrap these in HAVE_BN_{MUL,SQR}_COMBA{4,8} defines. Add these defines to bn_arch.h where the architecture currently provides its own version. ok tb@
Diffstat (limited to 'src/lib/libcrypto/bn/bn_mul.c')
-rw-r--r--src/lib/libcrypto/bn/bn_mul.c151
1 files changed, 150 insertions, 1 deletions
diff --git a/src/lib/libcrypto/bn/bn_mul.c b/src/lib/libcrypto/bn/bn_mul.c
index b7a7f8bcef..3a69ef35da 100644
--- a/src/lib/libcrypto/bn/bn_mul.c
+++ b/src/lib/libcrypto/bn/bn_mul.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_mul.c,v 1.27 2023/01/20 12:16:46 jsing Exp $ */ 1/* $OpenBSD: bn_mul.c,v 1.28 2023/01/20 17:31:52 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -62,8 +62,157 @@
62 62
63#include <openssl/opensslconf.h> 63#include <openssl/opensslconf.h>
64 64
65#include "bn_arch.h"
65#include "bn_local.h" 66#include "bn_local.h"
66 67
68#ifndef HAVE_BN_MUL_COMBA4
69void
70bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
71{
72 BN_ULONG c1, c2, c3;
73
74 c1 = 0;
75 c2 = 0;
76 c3 = 0;
77 mul_add_c(a[0], b[0], c1, c2, c3);
78 r[0] = c1;
79 c1 = 0;
80 mul_add_c(a[0], b[1], c2, c3, c1);
81 mul_add_c(a[1], b[0], c2, c3, c1);
82 r[1] = c2;
83 c2 = 0;
84 mul_add_c(a[2], b[0], c3, c1, c2);
85 mul_add_c(a[1], b[1], c3, c1, c2);
86 mul_add_c(a[0], b[2], c3, c1, c2);
87 r[2] = c3;
88 c3 = 0;
89 mul_add_c(a[0], b[3], c1, c2, c3);
90 mul_add_c(a[1], b[2], c1, c2, c3);
91 mul_add_c(a[2], b[1], c1, c2, c3);
92 mul_add_c(a[3], b[0], c1, c2, c3);
93 r[3] = c1;
94 c1 = 0;
95 mul_add_c(a[3], b[1], c2, c3, c1);
96 mul_add_c(a[2], b[2], c2, c3, c1);
97 mul_add_c(a[1], b[3], c2, c3, c1);
98 r[4] = c2;
99 c2 = 0;
100 mul_add_c(a[2], b[3], c3, c1, c2);
101 mul_add_c(a[3], b[2], c3, c1, c2);
102 r[5] = c3;
103 c3 = 0;
104 mul_add_c(a[3], b[3], c1, c2, c3);
105 r[6] = c1;
106 r[7] = c2;
107}
108#endif
109
110#ifndef HAVE_BN_MUL_COMBA8
111void
112bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
113{
114 BN_ULONG c1, c2, c3;
115
116 c1 = 0;
117 c2 = 0;
118 c3 = 0;
119 mul_add_c(a[0], b[0], c1, c2, c3);
120 r[0] = c1;
121 c1 = 0;
122 mul_add_c(a[0], b[1], c2, c3, c1);
123 mul_add_c(a[1], b[0], c2, c3, c1);
124 r[1] = c2;
125 c2 = 0;
126 mul_add_c(a[2], b[0], c3, c1, c2);
127 mul_add_c(a[1], b[1], c3, c1, c2);
128 mul_add_c(a[0], b[2], c3, c1, c2);
129 r[2] = c3;
130 c3 = 0;
131 mul_add_c(a[0], b[3], c1, c2, c3);
132 mul_add_c(a[1], b[2], c1, c2, c3);
133 mul_add_c(a[2], b[1], c1, c2, c3);
134 mul_add_c(a[3], b[0], c1, c2, c3);
135 r[3] = c1;
136 c1 = 0;
137 mul_add_c(a[4], b[0], c2, c3, c1);
138 mul_add_c(a[3], b[1], c2, c3, c1);
139 mul_add_c(a[2], b[2], c2, c3, c1);
140 mul_add_c(a[1], b[3], c2, c3, c1);
141 mul_add_c(a[0], b[4], c2, c3, c1);
142 r[4] = c2;
143 c2 = 0;
144 mul_add_c(a[0], b[5], c3, c1, c2);
145 mul_add_c(a[1], b[4], c3, c1, c2);
146 mul_add_c(a[2], b[3], c3, c1, c2);
147 mul_add_c(a[3], b[2], c3, c1, c2);
148 mul_add_c(a[4], b[1], c3, c1, c2);
149 mul_add_c(a[5], b[0], c3, c1, c2);
150 r[5] = c3;
151 c3 = 0;
152 mul_add_c(a[6], b[0], c1, c2, c3);
153 mul_add_c(a[5], b[1], c1, c2, c3);
154 mul_add_c(a[4], b[2], c1, c2, c3);
155 mul_add_c(a[3], b[3], c1, c2, c3);
156 mul_add_c(a[2], b[4], c1, c2, c3);
157 mul_add_c(a[1], b[5], c1, c2, c3);
158 mul_add_c(a[0], b[6], c1, c2, c3);
159 r[6] = c1;
160 c1 = 0;
161 mul_add_c(a[0], b[7], c2, c3, c1);
162 mul_add_c(a[1], b[6], c2, c3, c1);
163 mul_add_c(a[2], b[5], c2, c3, c1);
164 mul_add_c(a[3], b[4], c2, c3, c1);
165 mul_add_c(a[4], b[3], c2, c3, c1);
166 mul_add_c(a[5], b[2], c2, c3, c1);
167 mul_add_c(a[6], b[1], c2, c3, c1);
168 mul_add_c(a[7], b[0], c2, c3, c1);
169 r[7] = c2;
170 c2 = 0;
171 mul_add_c(a[7], b[1], c3, c1, c2);
172 mul_add_c(a[6], b[2], c3, c1, c2);
173 mul_add_c(a[5], b[3], c3, c1, c2);
174 mul_add_c(a[4], b[4], c3, c1, c2);
175 mul_add_c(a[3], b[5], c3, c1, c2);
176 mul_add_c(a[2], b[6], c3, c1, c2);
177 mul_add_c(a[1], b[7], c3, c1, c2);
178 r[8] = c3;
179 c3 = 0;
180 mul_add_c(a[2], b[7], c1, c2, c3);
181 mul_add_c(a[3], b[6], c1, c2, c3);
182 mul_add_c(a[4], b[5], c1, c2, c3);
183 mul_add_c(a[5], b[4], c1, c2, c3);
184 mul_add_c(a[6], b[3], c1, c2, c3);
185 mul_add_c(a[7], b[2], c1, c2, c3);
186 r[9] = c1;
187 c1 = 0;
188 mul_add_c(a[7], b[3], c2, c3, c1);
189 mul_add_c(a[6], b[4], c2, c3, c1);
190 mul_add_c(a[5], b[5], c2, c3, c1);
191 mul_add_c(a[4], b[6], c2, c3, c1);
192 mul_add_c(a[3], b[7], c2, c3, c1);
193 r[10] = c2;
194 c2 = 0;
195 mul_add_c(a[4], b[7], c3, c1, c2);
196 mul_add_c(a[5], b[6], c3, c1, c2);
197 mul_add_c(a[6], b[5], c3, c1, c2);
198 mul_add_c(a[7], b[4], c3, c1, c2);
199 r[11] = c3;
200 c3 = 0;
201 mul_add_c(a[7], b[5], c1, c2, c3);
202 mul_add_c(a[6], b[6], c1, c2, c3);
203 mul_add_c(a[5], b[7], c1, c2, c3);
204 r[12] = c1;
205 c1 = 0;
206 mul_add_c(a[6], b[7], c2, c3, c1);
207 mul_add_c(a[7], b[6], c2, c3, c1);
208 r[13] = c2;
209 c2 = 0;
210 mul_add_c(a[7], b[7], c3, c1, c2);
211 r[14] = c3;
212 r[15] = c1;
213}
214#endif
215
67#if defined(OPENSSL_NO_ASM) || !defined(OPENSSL_BN_ASM_PART_WORDS) 216#if defined(OPENSSL_NO_ASM) || !defined(OPENSSL_BN_ASM_PART_WORDS)
68/* 217/*
69 * Here follows a specialised variant of bn_sub_words(), which has the property 218 * Here follows a specialised variant of bn_sub_words(), which has the property