Home | History | Annotate | Line # | Download | only in ml_dsa
      1 /*
      2  * Copyright 2024-2025 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/evp.h>
     11 
     12 static ossl_inline ossl_unused int
     13 shake_xof(EVP_MD_CTX *ctx, const EVP_MD *md, const uint8_t *in, size_t in_len,
     14     uint8_t *out, size_t out_len)
     15 {
     16     return (EVP_DigestInit_ex2(ctx, md, NULL) == 1
     17         && EVP_DigestUpdate(ctx, in, in_len) == 1
     18         && EVP_DigestSqueeze(ctx, out, out_len) == 1);
     19 }
     20 
     21 static ossl_inline ossl_unused int
     22 shake_xof_2(EVP_MD_CTX *ctx, const EVP_MD *md, const uint8_t *in1, size_t in1_len,
     23     const uint8_t *in2, size_t in2_len, uint8_t *out, size_t out_len)
     24 {
     25     return EVP_DigestInit_ex2(ctx, md, NULL)
     26         && EVP_DigestUpdate(ctx, in1, in1_len)
     27         && EVP_DigestUpdate(ctx, in2, in2_len)
     28         && EVP_DigestSqueeze(ctx, out, out_len);
     29 }
     30 
     31 static ossl_inline ossl_unused int
     32 shake_xof_3(EVP_MD_CTX *ctx, const EVP_MD *md, const uint8_t *in1, size_t in1_len,
     33     const uint8_t *in2, size_t in2_len,
     34     const uint8_t *in3, size_t in3_len, uint8_t *out, size_t out_len)
     35 {
     36     return EVP_DigestInit_ex2(ctx, md, NULL)
     37         && EVP_DigestUpdate(ctx, in1, in1_len)
     38         && EVP_DigestUpdate(ctx, in2, in2_len)
     39         && EVP_DigestUpdate(ctx, in3, in3_len)
     40         && EVP_DigestSqueeze(ctx, out, out_len);
     41 }
     42