Coverage Report

Created: 2026-09-12 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl40/crypto/ml_dsa/ml_dsa_sign.c
Line
Count
Source
1
/*
2
 * Copyright 2024-2026 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#include <openssl/core_dispatch.h>
11
#include <openssl/core_names.h>
12
#include <openssl/params.h>
13
#include <openssl/rand.h>
14
#include <openssl/err.h>
15
#include <openssl/proverr.h>
16
#include "internal/common.h"
17
#include "ml_dsa_local.h"
18
#include "ml_dsa_key.h"
19
#include "ml_dsa_matrix.h"
20
#include "ml_dsa_sign.h"
21
#include "ml_dsa_hash.h"
22
23
#define ML_DSA_MAX_LAMBDA 256 /* bit strength for ML-DSA-87 */
24
25
/*
26
 * @brief Initialize a Signature object by pointing all of its objects to
27
 * preallocated blocks. The values passed for hint, z and
28
 * c_tilde values are not owned/freed by the |sig| object.
29
 *
30
 * @param sig The ML_DSA_SIG to initialize.
31
 * @param hint A preallocated array of |k| polynomial blocks
32
 * @param k The number of |hint| polynomials
33
 * @param z A preallocated array of |l| polynomial blocks
34
 * @param l The number of |z| polynomials
35
 * @param c_tilde A preallocated buffer
36
 * @param c_tilde_len The size of |c_tilde|
37
 */
38
static void signature_init(ML_DSA_SIG *sig,
39
    POLY *hint, uint32_t k, POLY *z, uint32_t l,
40
    uint8_t *c_tilde, size_t c_tilde_len)
41
1.78k
{
42
1.78k
    vector_init(&sig->z, z, l);
43
1.78k
    vector_init(&sig->hint, hint, k);
44
1.78k
    sig->c_tilde = c_tilde;
45
1.78k
    sig->c_tilde_len = c_tilde_len;
46
1.78k
}
47
48
/*
49
 * @brief: Auxiliary functions to compute ML-DSA's MU.
50
 * This combines the steps of creating M' and concatenating it
51
 * to the Public Key Hash to obtain MU.
52
 * See FIPS 204 Algorithm 2 Step 10 (and algorithm 3 Step 5) as
53
 * well as Algorithm 7 Step 6 (and algorithm 8 Step 7)
54
 *
55
 * ML_DSA pure signatures are encoded as M' = 00 || ctx_len || ctx || msg
56
 * Where ctx is the empty string by default and ctx_len <= 255.
57
 * The message is appended to the encoded context.
58
 * Finally a public key hash is prepended, and the whole is hashed
59
 * to derive the mu value.
60
 *
61
 * @param key: A public or private ML-DSA key;
62
 * @param encode: if not set, assumes that M' is provided raw and the
63
 * following parameters are ignored.
64
 * @param ctx An optional context to add to the message encoding.
65
 * @param ctx_len The size of |ctx|. It must be in the range 0..255
66
 * @returns an EVP_MD_CTX if the operation is successful, NULL otherwise.
67
 */
68
EVP_MD_CTX *ossl_ml_dsa_mu_init_int(EVP_MD *shake256_md,
69
    const uint8_t *tr, size_t tr_len, int encode, int prehash,
70
    const uint8_t *ctx, size_t ctx_len)
71
975
{
72
975
    EVP_MD_CTX *md_ctx;
73
975
    uint8_t itb[2];
74
75
975
    md_ctx = EVP_MD_CTX_new();
76
975
    if (md_ctx == NULL)
77
0
        return NULL;
78
79
    /* H(.. */
80
975
    if (!EVP_DigestInit_ex2(md_ctx, shake256_md, NULL))
81
0
        goto err;
82
    /* ..pk (= key->tr) */
83
975
    if (!EVP_DigestUpdate(md_ctx, tr, tr_len))
84
0
        goto err;
85
    /* M' = .. */
86
975
    if (encode) {
87
975
        if (ctx_len > ML_DSA_MAX_CONTEXT_STRING_LEN)
88
0
            goto err;
89
        /* IntegerToBytes(0, 1) .. */
90
975
        itb[0] = prehash ? 1 : 0;
91
        /* || IntegerToBytes(|ctx|, 1) || .. */
92
975
        itb[1] = (uint8_t)ctx_len;
93
975
        if (!EVP_DigestUpdate(md_ctx, itb, 2))
94
0
            goto err;
95
        /* ctx || .. */
96
975
        if (!EVP_DigestUpdate(md_ctx, ctx, ctx_len))
97
0
            goto err;
98
        /* .. msg) will follow in update and final functions */
99
975
    }
100
101
975
    return md_ctx;
102
103
0
err:
104
0
    EVP_MD_CTX_free(md_ctx);
105
0
    return NULL;
106
975
}
107
108
EVP_MD_CTX *ossl_ml_dsa_mu_init(const ML_DSA_KEY *key, int encode,
109
    const uint8_t *ctx, size_t ctx_len)
110
968
{
111
968
    if (key == NULL)
112
0
        return NULL;
113
968
    return ossl_ml_dsa_mu_init_int(key->shake256_md, key->tr, sizeof(key->tr),
114
968
        encode, 0, ctx, ctx_len);
115
968
}
116
117
/*
118
 * @brief: updates the internal ML-DSA hash with an additional message chunk.
119
 *
120
 * @param md_ctx: The hashing context
121
 * @param msg: The next message chunk
122
 * @param msg_len: The length of the msg buffer to process
123
 * @returns 1 on success, 0 on error
124
 */
125
int ossl_ml_dsa_mu_update(EVP_MD_CTX *md_ctx, const uint8_t *msg, size_t msg_len)
126
1.37k
{
127
1.37k
    return EVP_DigestUpdate(md_ctx, msg, msg_len);
128
1.37k
}
129
130
/*
131
 * @brief: finalizes the internal ML-DSA hash
132
 *
133
 * @param md_ctx: The hashing context
134
 * @param mu: The output buffer for Mu
135
 * @param mu_len: The size of the output buffer
136
 * @returns 1 on success, 0 on error
137
 */
138
int ossl_ml_dsa_mu_finalize(EVP_MD_CTX *md_ctx, uint8_t *mu, size_t mu_len)
139
1.36k
{
140
1.36k
    if (!ossl_assert(mu_len == ML_DSA_MU_BYTES)) {
141
0
        ERR_raise(ERR_LIB_PROV, PROV_R_BAD_LENGTH);
142
0
        return 0;
143
0
    }
144
1.36k
    return EVP_DigestSqueeze(md_ctx, mu, mu_len);
145
1.36k
}
146
147
/*
148
 * @brief FIPS 204, Algorithm 7, ML-DSA.Sign_internal()
149
 *
150
 * This algorithm is decomposed in 2 steps, a set of functions to compute mu
151
 * and then the actual signing function.
152
 *
153
 * @param priv: The private ML-DSA key
154
 * @param mu: The pre-computed mu hash
155
 * @param mu_len: The length of the mu buffer
156
 * @param rnd: The random buffer
157
 * @param rnd_len: The length of the random buffer
158
 * @param out_sig: The output signature buffer
159
 * @returns 1 on success, 0 on error
160
 */
161
static int ml_dsa_sign_internal(const ML_DSA_KEY *priv,
162
    const uint8_t *mu, size_t mu_len, const uint8_t *rnd, size_t rnd_len,
163
    uint8_t *out_sig)
164
418
{
165
418
    int ret = 0;
166
418
    const ML_DSA_PARAMS *params = priv->params;
167
418
    EVP_MD_CTX *md_ctx = NULL;
168
418
    uint32_t k = (uint32_t)params->k, l = (uint32_t)params->l;
169
418
    uint32_t gamma1 = params->gamma1, gamma2 = params->gamma2;
170
418
    uint8_t *alloc = NULL, *w1_encoded;
171
418
    size_t alloc_len, w1_encoded_len;
172
418
    size_t num_polys_sig_k = 2 * k;
173
418
    size_t num_polys_k = 5 * k;
174
418
    size_t num_polys_l = 3 * l;
175
418
    size_t num_polys_k_by_l = k * l;
176
418
    POLY *p, *c_ntt;
177
418
    VECTOR s1_ntt, s2_ntt, t0_ntt, w, w1, cs1, cs2, y;
178
418
    MATRIX a_ntt;
179
418
    ML_DSA_SIG sig;
180
418
    uint8_t rho_prime[ML_DSA_RHO_PRIME_BYTES];
181
418
    uint8_t c_tilde[ML_DSA_MAX_LAMBDA / 4];
182
418
    size_t c_tilde_len = params->bit_strength >> 2;
183
418
    size_t kappa;
184
185
418
    if (mu_len != ML_DSA_MU_BYTES) {
186
0
        ERR_raise(ERR_LIB_PROV, PROV_R_BAD_LENGTH);
187
0
        return 0;
188
0
    }
189
190
    /*
191
     * Allocate a single blob for most of the variable size temporary variables.
192
     * Mostly used for VECTOR POLYNOMIALS (every POLY is 1K).
193
     */
194
418
    w1_encoded_len = k * (gamma2 == ML_DSA_GAMMA2_Q_MINUS1_DIV88 ? 192 : 128);
195
418
    alloc_len = w1_encoded_len
196
418
        + sizeof(*p) * (1 + num_polys_k + num_polys_l + num_polys_k_by_l + num_polys_sig_k);
197
418
    alloc = OPENSSL_malloc(alloc_len);
198
418
    if (alloc == NULL)
199
0
        return 0;
200
418
    md_ctx = EVP_MD_CTX_new();
201
418
    if (md_ctx == NULL)
202
0
        goto err;
203
204
418
    w1_encoded = alloc;
205
    /* Init the temp vectors to point to the allocated polys blob */
206
418
    p = (POLY *)(w1_encoded + w1_encoded_len);
207
418
    c_ntt = p++;
208
418
    matrix_init(&a_ntt, p, k, l);
209
418
    p += num_polys_k_by_l;
210
418
    vector_init(&s2_ntt, p, k);
211
418
    vector_init(&t0_ntt, s2_ntt.poly + k, k);
212
418
    vector_init(&w, t0_ntt.poly + k, k);
213
418
    vector_init(&w1, w.poly + k, k);
214
418
    vector_init(&cs2, w1.poly + k, k);
215
418
    p += num_polys_k;
216
418
    vector_init(&s1_ntt, p, l);
217
418
    vector_init(&y, p + l, l);
218
418
    vector_init(&cs1, p + 2 * l, l);
219
418
    p += num_polys_l;
220
418
    signature_init(&sig, p, k, p + k, l, c_tilde, c_tilde_len);
221
    /* End of the allocated blob setup */
222
223
418
    if (!matrix_expand_A(md_ctx, priv->shake128_md, priv->rho, &a_ntt))
224
0
        goto err;
225
226
418
    if (!shake_xof_3(md_ctx, priv->shake256_md, priv->K, sizeof(priv->K),
227
418
            rnd, rnd_len, mu, mu_len,
228
418
            rho_prime, sizeof(rho_prime)))
229
0
        goto err;
230
231
418
    vector_copy(&s1_ntt, &priv->s1);
232
418
    vector_ntt(&s1_ntt);
233
418
    vector_copy(&s2_ntt, &priv->s2);
234
418
    vector_ntt(&s2_ntt);
235
418
    vector_copy(&t0_ntt, &priv->t0);
236
418
    vector_ntt(&t0_ntt);
237
238
    /*
239
     * kappa must not exceed 2^16. But the probability of it
240
     * exceeding even 1000 iterations is vanishingly small.
241
     */
242
1.97k
    for (kappa = 0;; kappa += l) {
243
1.97k
        VECTOR *y_ntt = &cs1;
244
1.97k
        VECTOR *r0 = &w1;
245
1.97k
        VECTOR *ct0 = &w1;
246
1.97k
        uint32_t z_max, r0_max, ct0_max, h_ones;
247
248
1.97k
        vector_expand_mask(&y, rho_prime, sizeof(rho_prime), (uint32_t)kappa,
249
1.97k
            gamma1, md_ctx, priv->shake256_md);
250
1.97k
        vector_copy(y_ntt, &y);
251
1.97k
        vector_ntt(y_ntt);
252
253
1.97k
        matrix_mult_vector(&a_ntt, y_ntt, &w);
254
1.97k
        vector_ntt_inverse(&w);
255
256
1.97k
        vector_high_bits(&w, gamma2, &w1);
257
1.97k
        ossl_ml_dsa_w1_encode(&w1, gamma2, w1_encoded, w1_encoded_len);
258
259
1.97k
        if (!shake_xof_2(md_ctx, priv->shake256_md, mu, mu_len,
260
1.97k
                w1_encoded, w1_encoded_len, c_tilde, c_tilde_len))
261
0
            break;
262
263
1.97k
        if (!poly_sample_in_ball_ntt(c_ntt, c_tilde, (int)c_tilde_len,
264
1.97k
                md_ctx, priv->shake256_md, params->tau))
265
0
            break;
266
267
1.97k
        vector_mult_scalar(&s1_ntt, c_ntt, &cs1);
268
1.97k
        vector_ntt_inverse(&cs1);
269
1.97k
        vector_mult_scalar(&s2_ntt, c_ntt, &cs2);
270
1.97k
        vector_ntt_inverse(&cs2);
271
272
1.97k
        vector_add(&y, &cs1, &sig.z);
273
274
        /* r0 = lowbits(w - cs2) */
275
1.97k
        vector_sub(&w, &cs2, r0);
276
1.97k
        vector_low_bits(r0, gamma2, r0);
277
278
        /*
279
         * Leaking that the signature is rejected is fine as the next attempt at a
280
         * signature will be (indistinguishable from) independent of this one.
281
         */
282
1.97k
        z_max = vector_max(&sig.z);
283
1.97k
        r0_max = vector_max_signed(r0);
284
1.97k
        if (value_barrier_32(constant_time_ge(z_max, gamma1 - params->beta)
285
1.97k
                | constant_time_ge(r0_max, gamma2 - params->beta)))
286
1.54k
            continue;
287
288
424
        vector_mult_scalar(&t0_ntt, c_ntt, ct0);
289
424
        vector_ntt_inverse(ct0);
290
424
        vector_make_hint(ct0, &cs2, &w, gamma2, &sig.hint);
291
292
424
        ct0_max = vector_max(ct0);
293
424
        h_ones = (uint32_t)vector_count_ones(&sig.hint);
294
        /* Same reasoning applies to the leak as above */
295
424
        if (value_barrier_32(constant_time_ge(ct0_max, gamma2)
296
424
                | constant_time_lt(params->omega, h_ones)))
297
6
            continue;
298
418
        ret = ossl_ml_dsa_sig_encode(&sig, params, out_sig);
299
418
        break;
300
424
    }
301
418
err:
302
418
    EVP_MD_CTX_free(md_ctx);
303
418
    OPENSSL_clear_free(alloc, alloc_len);
304
418
    OPENSSL_cleanse(rho_prime, sizeof(rho_prime));
305
418
    OPENSSL_cleanse(c_tilde, sizeof(c_tilde));
306
418
    return ret;
307
418
}
308
309
/*
310
 * @brief FIPS 204, Algorithm 8, ML-DSA.Verify_internal().
311
 *
312
 * This algorithm is decomposed in 2 steps, a set of functions to compute mu
313
 * and then the actual verification function.
314
 *
315
 * @param pub: The public ML-DSA key
316
 * @param mu: The pre-computed mu hash
317
 * @param mu_len: The length of the mu buffer
318
 * @param sig_enc: The encoded signature to be verified
319
 * @param sig_enc_len: the encoded csignature length
320
 * @returns 1 on success, 0 on error
321
 */
322
static int ml_dsa_verify_internal(const ML_DSA_KEY *pub,
323
    const uint8_t *mu, size_t mu_len,
324
    const uint8_t *sig_enc, size_t sig_enc_len)
325
221
{
326
221
    int ret = 0;
327
221
    uint8_t *alloc = NULL, *w1_encoded;
328
221
    POLY *p, *c_ntt;
329
221
    MATRIX a_ntt;
330
221
    VECTOR az_ntt, ct1_ntt, *z_ntt, *w1, *w_approx;
331
221
    ML_DSA_SIG sig;
332
221
    const ML_DSA_PARAMS *params = pub->params;
333
221
    uint32_t k = (uint32_t)pub->params->k;
334
221
    uint32_t l = (uint32_t)pub->params->l;
335
221
    uint32_t gamma2 = params->gamma2;
336
221
    size_t w1_encoded_len;
337
221
    size_t num_polys_sig = k + l;
338
221
    size_t num_polys_k = 2 * k;
339
221
    size_t num_polys_l = 1 * l;
340
221
    size_t num_polys_k_by_l = k * l;
341
221
    uint8_t c_tilde[ML_DSA_MAX_LAMBDA / 4];
342
221
    uint8_t c_tilde_sig[ML_DSA_MAX_LAMBDA / 4];
343
221
    EVP_MD_CTX *md_ctx = NULL;
344
221
    size_t c_tilde_len = params->bit_strength >> 2;
345
221
    uint32_t z_max;
346
347
    /* FIPS 204 compliance: Also validate signature length before decoding */
348
221
    if (mu_len != ML_DSA_MU_BYTES || sig_enc_len != params->sig_len) {
349
0
        ERR_raise(ERR_LIB_PROV, PROV_R_BAD_LENGTH);
350
0
        return 0;
351
0
    }
352
353
    /* Allocate space for all the POLYNOMIALS used by temporary VECTORS */
354
221
    w1_encoded_len = k * (gamma2 == ML_DSA_GAMMA2_Q_MINUS1_DIV88 ? 192 : 128);
355
221
    alloc = OPENSSL_malloc(w1_encoded_len
356
221
        + sizeof(*p) * (1 + num_polys_k + num_polys_l + num_polys_k_by_l + num_polys_sig));
357
221
    if (alloc == NULL)
358
0
        return 0;
359
221
    md_ctx = EVP_MD_CTX_new();
360
221
    if (md_ctx == NULL)
361
0
        goto err;
362
363
221
    w1_encoded = alloc;
364
    /* Init the temp vectors to point to the allocated polys blob */
365
221
    p = (POLY *)(w1_encoded + w1_encoded_len);
366
221
    c_ntt = p++;
367
221
    matrix_init(&a_ntt, p, k, l);
368
221
    p += num_polys_k_by_l;
369
221
    signature_init(&sig, p, k, p + k, l, c_tilde_sig, c_tilde_len);
370
221
    p += num_polys_sig;
371
221
    vector_init(&az_ntt, p, k);
372
221
    vector_init(&ct1_ntt, p + k, k);
373
374
221
    if (!ossl_ml_dsa_sig_decode(&sig, sig_enc, sig_enc_len, pub->params)
375
221
        || !matrix_expand_A(md_ctx, pub->shake128_md, pub->rho, &a_ntt))
376
0
        goto err;
377
378
    /* Compute verifiers challenge c_ntt = NTT(SampleInBall(c_tilde)) */
379
221
    if (!poly_sample_in_ball_ntt(c_ntt, c_tilde_sig, (int)c_tilde_len,
380
221
            md_ctx, pub->shake256_md, params->tau))
381
0
        goto err;
382
383
    /* ct1_ntt = NTT(c) * NTT(t1 * 2^d) */
384
221
    vector_scale_power2_round_ntt(&pub->t1, &ct1_ntt);
385
221
    vector_mult_scalar(&ct1_ntt, c_ntt, &ct1_ntt);
386
387
    /* compute z_max early in order to reuse sig.z */
388
221
    z_max = vector_max(&sig.z);
389
390
    /* w_approx = NTT_inverse(A * NTT(z) - ct1_ntt) */
391
221
    z_ntt = &sig.z;
392
221
    vector_ntt(z_ntt);
393
221
    matrix_mult_vector(&a_ntt, z_ntt, &az_ntt);
394
221
    w_approx = &az_ntt;
395
221
    vector_sub(&az_ntt, &ct1_ntt, w_approx);
396
221
    vector_ntt_inverse(w_approx);
397
398
    /* compute w1_encoded */
399
221
    w1 = w_approx;
400
221
    vector_use_hint(&sig.hint, w_approx, gamma2, w1);
401
221
    ossl_ml_dsa_w1_encode(w1, gamma2, w1_encoded, w1_encoded_len);
402
403
221
    if (!shake_xof_3(md_ctx, pub->shake256_md, mu, mu_len,
404
221
            w1_encoded, w1_encoded_len, NULL, 0, c_tilde, c_tilde_len))
405
0
        goto err;
406
407
221
    ret = (z_max < (uint32_t)(params->gamma1 - params->beta))
408
221
        && memcmp(c_tilde, sig.c_tilde, c_tilde_len) == 0;
409
221
err:
410
221
    OPENSSL_free(alloc);
411
221
    EVP_MD_CTX_free(md_ctx);
412
221
    return ret;
413
221
}
414
415
/**
416
 * See FIPS 204 Section 5.2 Algorithm 2 ML-DSA.Sign()
417
 *
418
 * @returns 1 on success, or 0 on error.
419
 */
420
int ossl_ml_dsa_sign(const ML_DSA_KEY *priv,
421
    int msg_is_mu, const uint8_t *msg, size_t msg_len,
422
    const uint8_t *context, size_t context_len,
423
    const uint8_t *rand, size_t rand_len, int encode,
424
    unsigned char *sig, size_t *sig_len, size_t sig_size)
425
1.36k
{
426
1.36k
    EVP_MD_CTX *md_ctx = NULL;
427
1.36k
    uint8_t mu[ML_DSA_MU_BYTES];
428
1.36k
    const uint8_t *mu_ptr = mu;
429
1.36k
    size_t mu_len = sizeof(mu);
430
1.36k
    int ret = 0;
431
432
1.36k
    if (ossl_ml_dsa_key_get_priv(priv) == NULL)
433
0
        return 0;
434
435
1.36k
    if (sig_len != NULL)
436
1.36k
        *sig_len = priv->params->sig_len;
437
438
1.36k
    if (sig == NULL)
439
681
        return (sig_len != NULL) ? 1 : 0;
440
441
681
    if (sig_size < priv->params->sig_len)
442
0
        return 0;
443
444
681
    if (msg_is_mu) {
445
0
        mu_ptr = msg;
446
0
        mu_len = msg_len;
447
681
    } else {
448
681
        md_ctx = ossl_ml_dsa_mu_init(priv, encode, context, context_len);
449
681
        if (md_ctx == NULL)
450
0
            return 0;
451
452
681
        if (!ossl_ml_dsa_mu_update(md_ctx, msg, msg_len))
453
0
            goto err;
454
455
681
        if (!ossl_ml_dsa_mu_finalize(md_ctx, mu, mu_len))
456
0
            goto err;
457
681
    }
458
459
681
    ret = ml_dsa_sign_internal(priv, mu_ptr, mu_len, rand, rand_len, sig);
460
461
681
err:
462
681
    EVP_MD_CTX_free(md_ctx);
463
681
    OPENSSL_cleanse(mu, sizeof(mu));
464
681
    return ret;
465
681
}
466
467
/**
468
 * See FIPS 203 Section 5.3 Algorithm 3 ML-DSA.Verify()
469
 * @returns 1 on success, or 0 on error.
470
 */
471
int ossl_ml_dsa_verify(const ML_DSA_KEY *pub,
472
    int msg_is_mu, const uint8_t *msg, size_t msg_len,
473
    const uint8_t *context, size_t context_len, int encode,
474
    const uint8_t *sig, size_t sig_len)
475
681
{
476
681
    EVP_MD_CTX *md_ctx = NULL;
477
681
    uint8_t mu[ML_DSA_MU_BYTES];
478
681
    const uint8_t *mu_ptr = mu;
479
681
    size_t mu_len = sizeof(mu);
480
681
    int ret = 0;
481
482
681
    if (ossl_ml_dsa_key_get_pub(pub) == NULL)
483
0
        return 0;
484
485
681
    if (msg_is_mu) {
486
0
        mu_ptr = msg;
487
0
        mu_len = msg_len;
488
681
    } else {
489
681
        md_ctx = ossl_ml_dsa_mu_init(pub, encode, context, context_len);
490
681
        if (md_ctx == NULL)
491
0
            return 0;
492
493
681
        if (!ossl_ml_dsa_mu_update(md_ctx, msg, msg_len))
494
0
            goto err;
495
496
681
        if (!ossl_ml_dsa_mu_finalize(md_ctx, mu, mu_len))
497
0
            goto err;
498
681
    }
499
500
681
    ret = ml_dsa_verify_internal(pub, mu_ptr, mu_len, sig, sig_len);
501
681
err:
502
681
    EVP_MD_CTX_free(md_ctx);
503
681
    OPENSSL_cleanse(mu, sizeof(mu));
504
681
    return ret;
505
681
}