Move implementation specific comment
This comment is about how the functions are implemented, not about their
public interface, so it doesn't belong in the header file.
It applies to everything in constant_time.c so moved there.
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
diff --git a/library/constant_time.c b/library/constant_time.c
index e0eadac..98fdbd7 100644
--- a/library/constant_time.c
+++ b/library/constant_time.c
@@ -17,6 +17,11 @@
* limitations under the License.
*/
+ /*
+ * The following functiona are implemented without using comparison operators, as those
+ * might be translated to branches by some compilers on some platforms.
+ */
+
#include "common.h"
#include "constant_time.h"
#include "mbedtls/error.h"
diff --git a/library/constant_time.h b/library/constant_time.h
index 336a151..4810c92 100644
--- a/library/constant_time.h
+++ b/library/constant_time.h
@@ -38,9 +38,6 @@
* This function can be used to write constant-time code by replacing branches
* with bit operations using masks.
*
- * This function is implemented without using comparison operators, as those
- * might be translated to branches by some compilers on some platforms.
- *
* \param a Pointer to the first buffer.
* \param b Pointer to the second buffer.
* \param n The number of bytes to compare in the buffer.
@@ -59,9 +56,6 @@
* This function can be used to write constant-time code by replacing branches
* with bit operations using masks.
*
- * This function is implemented without using comparison operators, as those
- * might be translated to branches by some compilers on some platforms.
- *
* \param value The value to analyze.
*
* \return Zero if \p value is zero, otherwise all-bits-one.
@@ -75,9 +69,6 @@
* This function can be used to write constant-time code by replacing branches
* with bit operations using masks.
*
- * This function is implemented without using comparison operators, as those
- * might be translated to branches by some compilers on some platforms.
- *
* \param value The value to analyze.
*
* \return Zero if \p value is zero, otherwise all-bits-one.
@@ -93,9 +84,6 @@
* This function can be used to write constant-time code by replacing branches
* with bit operations using masks.
*
- * This function is implemented without using comparison operators, as those
- * might be translated to branches by some compilers on some platforms.
- *
* \param value The value to analyze.
*
* \return Zero if \p value is zero, otherwise all-bits-one.
@@ -111,9 +99,6 @@
* This function can be used to write constant-time code by replacing branches
* with bit operations using masks.
*
- * This function is implemented without using comparison operators, as those
- * might be translated to branches by some compilers on some platforms.
- *
* \param x The first value to analyze.
* \param y The second value to analyze.
*
@@ -129,9 +114,6 @@
* This is equivalent to \p x == \p y, but is likely to be compiled
* to code using bitwise operation rather than a branch.
*
- * This function is implemented without using comparison operators, as those
- * might be translated to branches by some compilers on some platforms.
- *
* \param x The first value to analyze.
* \param y The second value to analyze.
*
@@ -146,9 +128,6 @@
* This is equivalent to \p x > \p y, but is likely to be compiled
* to code using bitwise operation rather than a branch.
*
- * This function is implemented without using comparison operators, as those
- * might be translated to branches by some compilers on some platforms.
- *
* \param x The first value to analyze.
* \param y The second value to analyze.
*
@@ -164,9 +143,6 @@
* This is equivalent to \p x < \p y, but is likely to be compiled
* to code using bitwise operation rather than a branch.
*
- * This function is implemented without using comparison operators, as those
- * might be translated to branches by some compilers on some platforms.
- *
* \param x The first value to analyze.
* \param y The second value to analyze.
*
@@ -182,9 +158,6 @@
* This is equivalent to `condition ? if1 : if0`, but is likely to be compiled
* to code using bitwise operation rather than a branch.
*
- * This function is implemented without using comparison operators, as those
- * might be translated to branches by some compilers on some platforms.
- *
* \param condition Condition to test.
* \param if1 Value to use if \p condition is nonzero.
* \param if0 Value to use if \p condition is zero.
@@ -200,9 +173,6 @@
* This is equivalent to `condition ? if1 : if0`, but is likely to be compiled
* to code using bitwise operation rather than a branch.
*
- * This function is implemented without using comparison operators, as those
- * might be translated to branches by some compilers on some platforms.
- *
* \param condition Condition to test.
* \param if1 Value to use if \p condition is nonzero.
* \param if0 Value to use if \p condition is zero.
@@ -218,8 +188,6 @@
* This is functionally equivalent to `condition ? if1 : if0` but uses only bit
* operations in order to avoid branches.
*
- * This function is implemented without using comparison operators, as those
- * might be translated to branches by some compilers on some platforms.
*
* \param condition Condition to test.
* \param if1 The first sign; must be either +1 or -1.
@@ -237,9 +205,6 @@
* This is equivalent to `if ( condition ) dest = src`, but is likely
* to be compiled to code using bitwise operation rather than a branch.
*
- * This function is implemented without using comparison operators, as those
- * might be translated to branches by some compilers on some platforms.
- *
* \param n \p dest and \p src must be arrays of limbs of size n.
* \param dest The MPI to conditionally assign to. This must point
* to an initialized MPI.
@@ -280,9 +245,6 @@
* This is equivalent to `if ( c1 == c2 ) memcpy(dst, src, len)`, but is likely
* to be compiled to code using bitwise operation rather than a branch.
*
- * This function is implemented without using comparison operators, as those
- * might be translated to branches by some compilers on some platforms.
- *
* \param dest The pointer to conditionally copy to.
* \param src The pointer to copy from.
* \param len The number of bytes to copy.