ml_dsa_matrix.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. #include "ml_dsa_local.h"
  10. #include "ml_dsa_vector.h"
  11. #include "ml_dsa_matrix.h"
  12. /*
  13. * Matrix multiply of a k*l matrix of polynomials by a 1 * l vector of
  14. * polynomials to produce a 1 * k vector of polynomial results.
  15. * i.e. t = a * s
  16. *
  17. * @param a A k * l matrix of polynomials in NTT form
  18. * @param s A 1 * l vector of polynomials in NTT form
  19. * @param t 1 * k vector of polynomial results in NTT form
  20. */
  21. void ossl_ml_dsa_matrix_mult_vector(const MATRIX *a, const VECTOR *s,
  22. VECTOR *t)
  23. {
  24. size_t i, j;
  25. POLY *poly = a->m_poly;
  26. vector_zero(t);
  27. for (i = 0; i < a->k; i++) {
  28. for (j = 0; j < a->l; j++) {
  29. POLY product;
  30. ossl_ml_dsa_poly_ntt_mult(poly++, &s->poly[j], &product);
  31. poly_add(&product, &t->poly[i], &t->poly[i]);
  32. }
  33. }
  34. }