Commit 3641d9c1 authored by Johan Pascal's avatar Johan Pascal

Merge branch 'master' into bc

# Conflicts:
#	CMakeLists.txt
#	src/per_field/f_generic.tmpl.c
parents 8191fb2f 760a61ed
############################################################################
# CMakeLists.txt
#
# Released under the MIT License. See LICENSE.txt for license information.
#
############################################################################
cmake_minimum_required(VERSION 3.0)
project(DECAF VERSION 1.0 LANGUAGES C CXX)
set(DECAF_SO_VERSION "0")
find_package( PythonInterp 2.7 REQUIRED )
option(ENABLE_SHARED "Build shared library." ON)
option(ENABLE_STATIC "Build static library." ON)
option(ENABLE_STRICT "Build with strict compile options." YES)
option(ENABLE_TESTS "Enable compilation of tests." OFF)
option(GENERATED_SOURCE_PATH "Where the generated source code is stored, default in the building tree" OFF)
if (GENERATED_SOURCE_PATH)
set(GSOURCE_PATH ${GENERATED_SOURCE_PATH})
else()
set(GSOURCE_PATH ${PROJECT_BINARY_DIR}/src/GENERATED)
endif()
message("Generated source code in ${GSOURCE_PATH}")
if(NOT CPACK_GENERATOR AND NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
endif()
include(GNUInstallDirs)
include(CheckSymbolExists)
include(CMakePushCheckState)
include_directories(
${GSOURCE_PATH}/include/
src/include/
src/
${CMAKE_CURRENT_BINARY_DIR}
)
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
set(STRICT_OPTIONS_CXX )
if(MSVC)
if(ENABLE_STRICT)
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} /WX")
endif()
else()
set(STRICT_OPTIONS_CXX "${STRICT_OPTIONS_CXX} -std=c++11 -O2")
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Wall -Wuninitialized -Wno-deprecated-declarations -Wno-missing-field-initializers")
set(STRICT_OPTIONS_C "${STRICT_OPTIONS_C} -std=c99 -O2 -Wstrict-prototypes -Wno-error=strict-prototypes -fvisibility=hidden")
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Qunused-arguments -Wno-array-bounds")
endif()
if(APPLE)
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Wno-error=unknown-warning-option -Qunused-arguments -Wno-tautological-compare -Wno-unused-function -Wno-array-bounds")
endif()
if(ENABLE_STRICT)
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Werror -Wextra -Wno-unused-parameter -fno-strict-aliasing")
endif()
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STRICT_OPTIONS_C} ${STRICT_OPTIONS_CPP}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STRICT_OPTIONS_CXX} ${STRICT_OPTIONS_CPP}")
add_subdirectory(src)
if(ENABLE_TESTS)
enable_testing()
add_subdirectory(test)
endif()
include(CMakePackageConfigHelpers)
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/DecafTargets.cmake"
)
configure_file(cmake/DecafConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake"
@ONLY
)
set(ConfigPackageLocation share/decaf/cmake)
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE DecafTargets.cmake
DESTINATION ${ConfigPackageLocation}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake"
DESTINATION ${ConfigPackageLocation}
)
# Doxygen
find_package(Doxygen)
if (DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS generatedCode
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif()
# CPack settings
set(CPACK_PACKAGE_NAME "decaf")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_SOURCE_IGNORE_FILES
"^${CMAKE_BINARY_DIR}"
"/\\\\..+"
)
include(CPack)
############################################################################
# CMakeLists.txt
#
# Released under the MIT License. See LICENSE.txt for license information.
#
############################################################################
cmake_minimum_required(VERSION 3.0)
project(DECAF VERSION 1.0 LANGUAGES C CXX)
set(DECAF_SO_VERSION "0")
find_package( PythonInterp 2.7 REQUIRED )
option(ENABLE_SHARED "Build shared library." ON)
option(ENABLE_STATIC "Build static library." ON)
option(ENABLE_STRICT "Build with strict compile options." YES)
option(ENABLE_TESTS "Enable compilation of tests." OFF)
option(GENERATED_SOURCE_PATH "Where the generated source code is stored, default in the building tree" OFF)
if (GENERATED_SOURCE_PATH)
set(GSOURCE_PATH ${GENERATED_SOURCE_PATH})
else()
set(GSOURCE_PATH ${PROJECT_BINARY_DIR}/src/GENERATED)
endif()
message("Generated source code will be in ${GSOURCE_PATH}")
if(NOT CPACK_GENERATOR AND NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
endif()
include(GNUInstallDirs)
include(CheckSymbolExists)
include(CMakePushCheckState)
include_directories(
${GSOURCE_PATH}/include/
src/include/
src/
${CMAKE_CURRENT_BINARY_DIR}
)
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
set(STRICT_OPTIONS_CXX )
if(MSVC)
if(ENABLE_STRICT)
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} /WX")
endif()
else()
set(STRICT_OPTIONS_CXX "${STRICT_OPTIONS_CXX} -std=c++11 -O2")
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Wall -Wuninitialized -Wno-deprecated-declarations -Wno-missing-field-initializers ")
set(STRICT_OPTIONS_C "${STRICT_OPTIONS_C} -std=c99 -O2 -Wstrict-prototypes -Wno-error=strict-prototypes -fvisibility=hidden ")
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Qunused-arguments -Wno-array-bounds ")
endif()
if(APPLE)
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Wno-error=unknown-warning-option -Qunused-arguments -Wno-tautological-compare -Wno-unused-function -Wno-array-bounds ")
set(STRICT_OPTIONS_CXX "${STRICT_OPTIONS_CXX} -stdlib=libc++ ")
endif()
if(ENABLE_STRICT)
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Werror -Wextra -Wno-unused-parameter -fno-strict-aliasing ")
endif()
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STRICT_OPTIONS_C} ${STRICT_OPTIONS_CPP}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STRICT_OPTIONS_CXX} ${STRICT_OPTIONS_CPP}")
add_subdirectory(src)
if(ENABLE_TESTS)
enable_testing()
add_subdirectory(test)
endif()
include(CMakePackageConfigHelpers)
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/DecafTargets.cmake"
)
configure_file(cmake/DecafConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake"
@ONLY
)
set(ConfigPackageLocation share/decaf/cmake)
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE DecafTargets.cmake
DESTINATION ${ConfigPackageLocation}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake"
DESTINATION ${ConfigPackageLocation}
)
# Doxygen
find_package(Doxygen)
if (DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS generatedCode
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif()
# CPack settings
set(CPACK_PACKAGE_NAME "decaf")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_SOURCE_IGNORE_FILES
"^${CMAKE_BINARY_DIR}"
"/\\\\..+"
)
include(CPack)
......@@ -4,6 +4,7 @@ from curve_data import field_data,curve_data,ser,msqrt,ceil_log2
import os
import argparse
import re
import errno
parser = argparse.ArgumentParser(description='Generate Decaf headers and other such files.')
parser.add_argument('-o', required = True, help = "Output")
......@@ -56,16 +57,16 @@ author = "Mike Hamburg" # FUTURE
for name in args.files:
_,_,name_suffix = name.rpartition(".")
template0 = open(name,"r").read()
data = per_map[args.per][args.item]
template = template0
outname = args.o
guard = args.guard
if guard is None: guard = outname
header_guard = "__" + guard.replace(".","_").replace("/","_").upper() + "__"
# Extract doxygenation
m = re.match(r"^\s*/\*\*([^*]|\*[^/])+\*/[ \t]*\n",template)
if m:
......@@ -73,12 +74,12 @@ for name in args.files:
doc = re.sub("\\s*\*/","",doc)
template = template[m.end():]
else: doc = ""
ns_doc = dedent(doc).strip().rstrip()
ns_doc = redoc(guard, fillin(ns_doc,data), author)
ns_code = fillin(template,data)
ret = ns_doc + "\n"
if outname.endswith(".h") or outname.endswith(".hxx"):
ns_code = dedent("""\n
#ifndef %(header_guard)s
......@@ -87,11 +88,11 @@ for name in args.files:
#endif /* %(header_guard)s */
""") % { "header_guard" : header_guard, "code": ns_code }
ret += ns_code[1:-1]
if not os.path.exists(os.path.dirname(outname)):
try:
os.makedirs(os.path.dirname(outname))
except OSError as e:
if e.errno != errno.EEXIST:
raise
with open(outname,"w") as f:
f.write(ret + "\n")
\ No newline at end of file
......@@ -233,7 +233,7 @@ void API_NS(deisogenize) (
void API_NS(point_encode)( unsigned char ser[SER_BYTES], const point_t p ) {
gf s,ie1,ie2;
API_NS(deisogenize)(s,ie1,ie2,p,0,0,0);
gf_serialize(ser,s,1);
gf_serialize(ser,s);
}
decaf_error_t API_NS(point_decode) (
......@@ -244,7 +244,7 @@ decaf_error_t API_NS(point_decode) (
gf s, s2, num, tmp;
gf_s *tmp2=s2, *ynum=p->z, *isr=p->x, *den=p->t;
mask_t succ = gf_deserialize(s, ser, 1, 0);
mask_t succ = gf_deserialize(s, ser, 0);
succ &= bool_to_mask(allow_identity) | ~gf_eq(s, ZERO);
succ &= ~gf_lobit(s);
......@@ -840,7 +840,7 @@ void API_NS(point_debugging_pscale) (
) {
gf gfac,tmp;
/* NB this means you'll never pscale by negative numbers for p521 */
ignore_result(gf_deserialize(gfac,factor,0,0));
ignore_result(gf_deserialize(gfac,factor,0));
gf_cond_sel(gfac,gfac,ONE,gf_eq(gfac,ZERO));
gf_mul(tmp,p->x,gfac);
gf_copy(q->x,tmp);
......@@ -1135,7 +1135,7 @@ void API_NS(point_mul_by_ratio_and_encode_like_eddsa) (
/* Encode */
enc[DECAF_EDDSA_$(gf_shortname)_PRIVATE_BYTES-1] = 0;
gf_serialize(enc, x, 1);
gf_serialize(enc, x);
enc[DECAF_EDDSA_$(gf_shortname)_PRIVATE_BYTES-1] |= 0x80 & gf_lobit(t);
decaf_bzero(x,sizeof(x));
......@@ -1156,7 +1156,7 @@ decaf_error_t API_NS(point_decode_like_eddsa_and_mul_by_ratio) (
mask_t low = ~word_is_zero(enc2[DECAF_EDDSA_$(gf_shortname)_PRIVATE_BYTES-1] & 0x80);
enc2[DECAF_EDDSA_$(gf_shortname)_PRIVATE_BYTES-1] &= ~0x80;
mask_t succ = gf_deserialize(p->y, enc2, 1, 0);
mask_t succ = gf_deserialize(p->y, enc2, 0);
#if $(gf_bits % 8) == 0
succ &= word_is_zero(enc2[DECAF_EDDSA_$(gf_shortname)_PRIVATE_BYTES-1]);
#endif
......@@ -1256,7 +1256,7 @@ decaf_error_t decaf_x$(gf_shortname) (
const uint8_t scalar[X_PRIVATE_BYTES]
) {
gf x1, x2, z2, x3, z3, t1, t2;
ignore_result(gf_deserialize(x1,base,1,0));
ignore_result(gf_deserialize(x1,base,0));
gf_copy(x2,ONE);
gf_copy(z2,ZERO);
gf_copy(x3,x1);
......@@ -1307,7 +1307,7 @@ decaf_error_t decaf_x$(gf_shortname) (
gf_cond_swap(z2,z3,swap);
gf_invert(z2,z2,0);
gf_mul(x1,x2,z2);
gf_serialize(out,x1,1);
gf_serialize(out,x1);
mask_t nz = ~gf_eq(x1,ZERO);
decaf_bzero(x1,sizeof(x1));
......@@ -1328,7 +1328,7 @@ void decaf_ed$(gf_shortname)_convert_public_key_to_x$(gf_shortname) (
) {
gf y;
const uint8_t mask = (uint8_t)(0xFE<<($((gf_bits-1)%8)));
ignore_result(gf_deserialize(y, ed, 1, mask));
ignore_result(gf_deserialize(y, ed, mask));
{
gf n,d;
......@@ -1339,7 +1339,7 @@ void decaf_ed$(gf_shortname)_convert_public_key_to_x$(gf_shortname) (
gf_sub(d, ONE, y); /* d = 1-y */
gf_invert(d, d, 0); /* d = 1/(1-y) */
gf_mul(y, n, d); /* u = (y+1)/(1-y) */
gf_serialize(x,y,1);
gf_serialize(x,y);
#else /* EDDSA_USE_SIGMA_ISOGENY */
/* u = y^2 * (1-dy^2) / (1-y^2) */
gf_sqr(n,y); /* y^2*/
......@@ -1349,7 +1349,7 @@ void decaf_ed$(gf_shortname)_convert_public_key_to_x$(gf_shortname) (
gf_mulw(d,n,EDWARDS_D); /* dy^2*/
gf_sub(d, ONE, d); /* 1-dy^2*/
gf_mul(n, y, d); /* y^2 * (1-dy^2) / (1-y^2) */
gf_serialize(x,n,1);
gf_serialize(x,n);
#endif /* EDDSA_USE_SIGMA_ISOGENY */
decaf_bzero(y,sizeof(y));
......@@ -1381,7 +1381,7 @@ void API_NS(point_mul_by_ratio_and_encode_like_x$(gf_shortname)) (
#if IMAGINE_TWIST
gf_sub(q->y,ZERO,q->y);
#endif
gf_serialize(out,q->y,1);
gf_serialize(out,q->y);
API_NS(point_destroy(q));
}
......
......@@ -26,12 +26,12 @@ void API_NS(precompute_wnafs) (
const API_NS(point_t) base
);
static void field_print(const gf f) {
unsigned char ser[X_SER_BYTES];
gf_serialize(ser,f,1);
unsigned char ser[SER_BYTES];
gf_serialize(ser,f);
int b=0, i, comma=0;
unsigned long long limb = 0;
printf("{FIELD_LITERAL(");
for (i=0; i<X_SER_BYTES; i++) {
for (i=0; i<SER_BYTES; i++) {
limb |= ((uint64_t)ser[i])<<b;
b += 8;
if (b >= GF_LIT_LIMB_BITS || i == SER_BYTES-1) {
......
......@@ -31,7 +31,7 @@ void API_NS(point_from_hash_nonuniform) (
) {
gf r0,r,a,b,c,N,e;
const uint8_t mask = (uint8_t)(0xFE<<($((gf_bits-1)%8)));
ignore_result(gf_deserialize(r0,ser,0,mask));
ignore_result(gf_deserialize(r0,ser,mask));
gf_strong_reduce(r0);
gf_sqr(a,r0);
gf_mul_qnr(r,a);
......@@ -165,11 +165,7 @@ API_NS(invert_elligator_nonuniform) (
// succ &= ~(is_identity & sgn_ed_T); /* NB: there are no preimages of rotated identity. */
// #endif
#if $(gf_bits) == 8*SER_BYTES + 1 /* p521 */
gf_serialize(recovered_hash,b,0);
#else
gf_serialize(recovered_hash,b,1);
#endif
gf_serialize(recovered_hash,b);
#if $(gf_bits%8)
#if COFACTOR==8
recovered_hash[SER_BYTES-1] ^= (hint>>4)<<$(gf_bits%8);
......
......@@ -8,8 +8,7 @@
#define __DECAF_$(gf_shortname)_GF_DEFINED__ 1
#define NLIMBS ($(gf_impl_bits//8)/sizeof(word_t))
#define X_SER_BYTES $(((gf_bits-1)//8 + 1))
#define SER_BYTES $(((gf_bits-2)//8 + 1))
#define SER_BYTES $(((gf_bits-1)//8 + 1))
typedef struct gf_$(gf_shortname)_s {
word_t limb[NLIMBS];
} __attribute__((aligned(32))) gf_$(gf_shortname)_s, gf_$(gf_shortname)_t[1];
......@@ -22,7 +21,6 @@ typedef struct gf_$(gf_shortname)_s {
#define gf gf_$(gf_shortname)_t
#define gf_s gf_$(gf_shortname)_s
#define gf_eq gf_$(gf_shortname)_eq
#define gf_hibit gf_$(gf_shortname)_hibit
#define gf_lobit gf_$(gf_shortname)_lobit
#define gf_copy gf_$(gf_shortname)_copy
#define gf_add gf_$(gf_shortname)_add
......@@ -40,7 +38,7 @@ typedef struct gf_$(gf_shortname)_s {
#define gf_deserialize gf_$(gf_shortname)_deserialize
/* RFC 7748 support */
#define X_PUBLIC_BYTES X_SER_BYTES
#define X_PUBLIC_BYTES SER_BYTES
#define X_PRIVATE_BYTES X_PUBLIC_BYTES
#define X_PRIVATE_BITS $(gf_bits)
......@@ -68,10 +66,9 @@ void gf_sqr (gf_s *__restrict__ out, const gf a);
mask_t gf_isr(gf a, const gf x); /** a^2 x = 1, QNR, or 0 if x=0. Return true if successful */
mask_t gf_eq (const gf x, const gf y);
mask_t gf_lobit (const gf x);
mask_t gf_hibit (const gf x);
void gf_serialize (uint8_t *serial, const gf x,int with_highbit);
mask_t gf_deserialize (gf x, const uint8_t serial[SER_BYTES],int with_hibit,uint8_t hi_nmask);
void gf_serialize (uint8_t *serial, const gf x);
mask_t gf_deserialize (gf x, const uint8_t serial[SER_BYTES],uint8_t hi_nmask);
#ifdef __cplusplus
......
......@@ -13,15 +13,14 @@ static const gf MODULUS = {FIELD_LITERAL(
#endif
/** Serialize to wire format. */
void gf_serialize (uint8_t serial[SER_BYTES], const gf x, int with_hibit) {
void gf_serialize (uint8_t serial[SER_BYTES], const gf x) {
gf red;
gf_copy(red, x);
gf_strong_reduce(red);
if (!with_hibit) { assert(gf_hibit(red) == 0); }
unsigned int j=0, fill=0;
dword_t buffer = 0;
UNROLL for (unsigned int i=0; i<(unsigned int)(with_hibit ? X_SER_BYTES : SER_BYTES); i++) {
UNROLL for (unsigned int i=0; i<SER_BYTES; i++) {
if (fill < 8 && j < NLIMBS) {
buffer |= ((dword_t)red->limb[LIMBPERM(j)]) << fill;
fill += LIMB_PLACE_VALUE(LIMBPERM(j));
......@@ -33,14 +32,6 @@ void gf_serialize (uint8_t serial[SER_BYTES], const gf x, int with_hibit) {
}
}
/** Return high bit of x = low bit of 2x mod p */
mask_t gf_hibit(const gf x) {
gf y;
gf_add(y,x,x);
gf_strong_reduce(y);
return (y->limb[0]&1)?DECAF_MASK_ALL_SET:DECAF_MASK_ALL_UNSET;
}
/** Return high bit of x = low bit of 2x mod p */
mask_t gf_lobit(const gf x) {
gf y;
......@@ -50,15 +41,14 @@ mask_t gf_lobit(const gf x) {
}
/** Deserialize from wire format; return -1 on success and 0 on failure. */
mask_t gf_deserialize (gf x, const uint8_t serial[SER_BYTES], int with_hibit, uint8_t hi_nmask) {
mask_t gf_deserialize (gf x, const uint8_t serial[SER_BYTES], uint8_t hi_nmask) {
unsigned int j=0, fill=0;
dword_t buffer = 0;
dsword_t scarry = 0;
const unsigned int nbytes = with_hibit ? X_SER_BYTES : SER_BYTES;
UNROLL for (unsigned int i=0; i<NLIMBS; i++) {
UNROLL while (fill < (unsigned int)(LIMB_PLACE_VALUE(LIMBPERM(i))) && j < nbytes) {
UNROLL while (fill < (unsigned int)(LIMB_PLACE_VALUE(LIMBPERM(i))) && j < SER_BYTES) {
uint8_t sj = serial[j];
if (j==nbytes-1) sj &= ~hi_nmask;
if (j==SER_BYTES-1) sj &= ~hi_nmask;
buffer |= ((dword_t)sj) << fill;
fill += 8;
j++;
......@@ -68,8 +58,7 @@ mask_t gf_deserialize (gf x, const uint8_t serial[SER_BYTES], int with_hibit, ui
buffer >>= LIMB_PLACE_VALUE(LIMBPERM(i));
scarry = (scarry + x->limb[LIMBPERM(i)] - MODULUS->limb[LIMBPERM(i)]) >> (8*sizeof(word_t));
}
mask_t succ = with_hibit ? DECAF_MASK_ALL_SET : ~gf_hibit(x);
return succ & word_is_zero((word_t)buffer) & ~word_is_zero((word_t)scarry);
return word_is_zero((word_t)buffer) & ~word_is_zero((word_t)scarry);
}
/** Reduce to canonical form. */
......
......@@ -132,7 +132,8 @@ decaf_succeed_if(decaf_bool_t x) {
/** Return DECAF_TRUE iff x == DECAF_SUCCESS */
static DECAF_INLINE decaf_bool_t
decaf_successful(decaf_error_t e) {
decaf_dword_t w = ((decaf_word_t)e) ^ ((decaf_word_t)DECAF_SUCCESS);
decaf_word_t succ = DECAF_SUCCESS;
decaf_dword_t w = ((decaf_word_t)e) ^ succ;
return (w-1)>>DECAF_WORD_BITS;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment