diff options
author | jsing <> | 2023-02-19 13:44:29 +0000 |
---|---|---|
committer | jsing <> | 2023-02-19 13:44:29 +0000 |
commit | 0a69e4b42828860153d1be7ce5e7626ac56d6b04 (patch) | |
tree | c9e1a4b12d035a4cf5932a44ba1e4d05ec8c4ec2 /src/lib | |
parent | ecdf03e77ffc9d0b8d76db6d92b94140d641c138 (diff) | |
download | openbsd-0a69e4b42828860153d1be7ce5e7626ac56d6b04.tar.gz openbsd-0a69e4b42828860153d1be7ce5e7626ac56d6b04.tar.bz2 openbsd-0a69e4b42828860153d1be7ce5e7626ac56d6b04.zip |
First pass clean up of bn_mont.c.
Use calloc() rather than malloc() with manual initialisation of all struct
members to zero, use memset() instead of manually initialising all struct
members to zero, use consistent naming, use BN_free() instead of
BN_clear_free() (since it is the same thing).
ok tb@
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/bn/bn_mont.c | 68 |
1 files changed, 37 insertions, 31 deletions
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c index 0d110d5ca4..bf38eac303 100644 --- a/src/lib/libcrypto/bn/bn_mont.c +++ b/src/lib/libcrypto/bn/bn_mont.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_mont.c,v 1.39 2023/02/19 13:33:23 jsing Exp $ */ | 1 | /* $OpenBSD: bn_mont.c,v 1.40 2023/02/19 13:44:29 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 | * |
@@ -118,6 +118,7 @@ | |||
118 | 118 | ||
119 | #include <stdio.h> | 119 | #include <stdio.h> |
120 | #include <stdint.h> | 120 | #include <stdint.h> |
121 | #include <string.h> | ||
121 | 122 | ||
122 | #include "bn_local.h" | 123 | #include "bn_local.h" |
123 | 124 | ||
@@ -138,56 +139,61 @@ struct bn_mont_ctx_st { | |||
138 | BN_MONT_CTX * | 139 | BN_MONT_CTX * |
139 | BN_MONT_CTX_new(void) | 140 | BN_MONT_CTX_new(void) |
140 | { | 141 | { |
141 | BN_MONT_CTX *ret; | 142 | BN_MONT_CTX *mctx; |
143 | |||
144 | if ((mctx = calloc(1, sizeof(BN_MONT_CTX))) == NULL) | ||
145 | return NULL; | ||
146 | mctx->flags = BN_FLG_MALLOCED; | ||
142 | 147 | ||
143 | if ((ret = malloc(sizeof(BN_MONT_CTX))) == NULL) | 148 | BN_init(&mctx->RR); |
144 | return (NULL); | 149 | BN_init(&mctx->N); |
150 | BN_init(&mctx->Ni); | ||
145 | 151 | ||
146 | BN_MONT_CTX_init(ret); | 152 | return mctx; |
147 | ret->flags = BN_FLG_MALLOCED; | ||
148 | return (ret); | ||
149 | } | 153 | } |
150 | 154 | ||
151 | void | 155 | void |
152 | BN_MONT_CTX_init(BN_MONT_CTX *ctx) | 156 | BN_MONT_CTX_init(BN_MONT_CTX *mctx) |
153 | { | 157 | { |
154 | ctx->ri = 0; | 158 | memset(mctx, 0, sizeof(*mctx)); |
155 | BN_init(&(ctx->RR)); | 159 | |
156 | BN_init(&(ctx->N)); | 160 | BN_init(&mctx->RR); |
157 | BN_init(&(ctx->Ni)); | 161 | BN_init(&mctx->N); |
158 | ctx->n0[0] = ctx->n0[1] = 0; | 162 | BN_init(&mctx->Ni); |
159 | ctx->flags = 0; | ||
160 | } | 163 | } |
161 | 164 | ||
162 | void | 165 | void |
163 | BN_MONT_CTX_free(BN_MONT_CTX *mont) | 166 | BN_MONT_CTX_free(BN_MONT_CTX *mctx) |
164 | { | 167 | { |
165 | if (mont == NULL) | 168 | if (mctx == NULL) |
166 | return; | 169 | return; |
167 | 170 | ||
168 | BN_clear_free(&(mont->RR)); | 171 | BN_free(&mctx->RR); |
169 | BN_clear_free(&(mont->N)); | 172 | BN_free(&mctx->N); |
170 | BN_clear_free(&(mont->Ni)); | 173 | BN_free(&mctx->Ni); |
171 | if (mont->flags & BN_FLG_MALLOCED) | 174 | |
172 | free(mont); | 175 | if (mctx->flags & BN_FLG_MALLOCED) |
176 | free(mctx); | ||
173 | } | 177 | } |
174 | 178 | ||
175 | BN_MONT_CTX * | 179 | BN_MONT_CTX * |
176 | BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from) | 180 | BN_MONT_CTX_copy(BN_MONT_CTX *dst, BN_MONT_CTX *src) |
177 | { | 181 | { |
178 | if (to == from) | 182 | if (dst == src) |
179 | return (to); | 183 | return dst; |
180 | 184 | ||
181 | if (!BN_copy(&(to->RR), &(from->RR))) | 185 | if (!BN_copy(&dst->RR, &src->RR)) |
182 | return NULL; | 186 | return NULL; |
183 | if (!BN_copy(&(to->N), &(from->N))) | 187 | if (!BN_copy(&dst->N, &src->N)) |
184 | return NULL; | 188 | return NULL; |
185 | if (!BN_copy(&(to->Ni), &(from->Ni))) | 189 | if (!BN_copy(&dst->Ni, &src->Ni)) |
186 | return NULL; | 190 | return NULL; |
187 | to->ri = from->ri; | 191 | |
188 | to->n0[0] = from->n0[0]; | 192 | dst->ri = src->ri; |
189 | to->n0[1] = from->n0[1]; | 193 | dst->n0[0] = src->n0[0]; |
190 | return (to); | 194 | dst->n0[1] = src->n0[1]; |
195 | |||
196 | return dst; | ||
191 | } | 197 | } |
192 | 198 | ||
193 | int | 199 | int |