1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* SPDX-License-Identifier: MIT
*
* Rivide Post-Quantum Cryptography Library
* Copyright (C) 2026 Moh. Ananda Firmansyah Putra
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/
/**
* @file dsa_rounding.c
* @brief ML-DSA rounding functions: Power2Round, Decompose, MakeHint, UseHint.
*
* Implements high/low coefficient decomposition and hint generation algorithms
* specified in NIST FIPS 204.
*/
/**
* @brief Power2Round: decompose t into (t1, t0) where t = t1 * 2^d + t0.
*
* @param[in] a Coefficient in [0, q-1].
* @param[out] a0 Pointer to store low bits t0 in [-(2^(d-1)), 2^(d-1)].
* @return High bits t1 = (t - t0) / 2^d.
*/
int32_t
/**
* @brief Decompose: decompose a into (a1, a0) where a = a1 * 2*gamma2 + a0.
*
* @param[in] a Coefficient in [0, q-1].
* @param[out] a0 Pointer to store low part in (-gamma2, gamma2].
* @param[in] gamma2 Decomposition parameter ((q-1)/32 or (q-1)/88).
* @return High part a1.
*/
int32_t
/**
* @brief Compute the hint bit for one coefficient.
*
* @param[in] a0 Low part from Decompose.
* @param[in] a1 High part from Decompose.
* @param[in] gamma2 Decomposition parameter.
* @return 1 if a hint bit is required, or 0 otherwise.
*/
unsigned int
/**
* @brief Apply the hint bit to recover the correct high bits.
*
* @param[in] a Original coefficient.
* @param[in] hint Hint bit (0 or 1).
* @param[in] gamma2 Decomposition parameter.
* @return Corrected high bits a1.
*/
int32_t