-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
217 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#include "icicle/curves/montgomery_conversion.h" | ||
#include "icicle/errors.h" | ||
#include "icicle/runtime.h" | ||
#include "icicle/utils/log.h" | ||
|
||
#include "icicle/curves/curve_config.h" | ||
|
||
using namespace curve_config; | ||
using namespace icicle; | ||
|
||
template <typename T> | ||
eIcicleError cpu_convert_mont( | ||
const Device& device, const T* input, size_t n, bool is_into, const ConvertMontgomeryConfig& config, T* output) | ||
{ | ||
for (size_t i = 0; i < n; ++i) { | ||
output[i] = is_into ? T::to_montgomery(input[i]) : T::from_montgomery(input[i]); | ||
} | ||
return eIcicleError::SUCCESS; | ||
} | ||
|
||
REGISTER_AFFINE_CONVERT_MONTGOMERY_BACKEND("CPU", cpu_convert_mont<affine_t>); | ||
REGISTER_PROJECTIVE_CONVERT_MONTGOMERY_BACKEND("CPU", cpu_convert_mont<projective_t>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
|
||
#include "icicle/errors.h" | ||
#include "icicle/runtime.h" | ||
#include "icicle/utils/utils.h" | ||
#include "icicle/config_extension.h" | ||
|
||
#include "icicle/curves/affine.h" | ||
#include "icicle/curves/projective.h" | ||
#include "icicle/fields/field.h" | ||
#include "icicle/curves/curve_config.h" | ||
|
||
using namespace curve_config; | ||
|
||
namespace icicle { | ||
|
||
/*************************** Frontend APIs ***************************/ | ||
|
||
struct ConvertMontgomeryConfig { | ||
icicleStreamHandle stream; /**< stream for async execution. */ | ||
bool is_input_on_device; | ||
bool is_output_on_device; | ||
bool is_async; | ||
|
||
ConfigExtension ext; /** backend specific extensions*/ | ||
}; | ||
|
||
static ConvertMontgomeryConfig default_convert_montgomery_config() | ||
{ | ||
ConvertMontgomeryConfig config = { | ||
nullptr, // stream | ||
false, // is_input_on_device | ||
false, // is_output_on_device | ||
false, // is_async | ||
}; | ||
return config; | ||
} | ||
|
||
template <typename T> | ||
eIcicleError | ||
points_convert_montgomery(const T* input, size_t n, bool is_into, const ConvertMontgomeryConfig& config, T* output); | ||
|
||
/*************************** Backend registration ***************************/ | ||
|
||
using AffineConvertMontImpl = std::function<eIcicleError( | ||
const Device& device, | ||
const affine_t* input, | ||
size_t n, | ||
bool is_into, | ||
const ConvertMontgomeryConfig& config, | ||
affine_t* output)>; | ||
|
||
void register_affine_convert_montgomery(const std::string& deviceType, AffineConvertMontImpl); | ||
|
||
#define REGISTER_AFFINE_CONVERT_MONTGOMERY_BACKEND(DEVICE_TYPE, FUNC) \ | ||
namespace { \ | ||
static bool UNIQUE(_reg_affine_convert_mont) = []() -> bool { \ | ||
register_affine_convert_montgomery(DEVICE_TYPE, FUNC); \ | ||
return true; \ | ||
}(); \ | ||
} | ||
|
||
using ProjectiveConvertMontImpl = std::function<eIcicleError( | ||
const Device& device, | ||
const projective_t* input, | ||
size_t n, | ||
bool is_into, | ||
const ConvertMontgomeryConfig& config, | ||
projective_t* output)>; | ||
|
||
void register_projective_convert_montgomery(const std::string& deviceType, ProjectiveConvertMontImpl); | ||
|
||
#define REGISTER_PROJECTIVE_CONVERT_MONTGOMERY_BACKEND(DEVICE_TYPE, FUNC) \ | ||
namespace { \ | ||
static bool UNIQUE(_reg_projective_convert_mont) = []() -> bool { \ | ||
register_projective_convert_montgomery(DEVICE_TYPE, FUNC); \ | ||
return true; \ | ||
}(); \ | ||
} | ||
|
||
}; // namespace icicle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "icicle/curves/montgomery_conversion.h" | ||
#include "icicle/dispatcher.h" | ||
#include "icicle/curves/curve_config.h" | ||
|
||
using namespace curve_config; | ||
|
||
namespace icicle { | ||
|
||
/*************************** AFFINE CONVERT MONTGOMERY ***************************/ | ||
ICICLE_DISPATCHER_INST(AffineConvertMont, affine_convert_montgomery, AffineConvertMontImpl); | ||
|
||
extern "C" eIcicleError CONCAT_EXPAND(CURVE, affine_convert_montgomery)( | ||
const affine_t* input, size_t n, bool is_into, const ConvertMontgomeryConfig& config, affine_t* output) | ||
{ | ||
return AffineConvertMont::execute(input, n, is_into, config, output); | ||
} | ||
|
||
template <> | ||
eIcicleError points_convert_montgomery( | ||
const affine_t* input, size_t n, bool is_into, const ConvertMontgomeryConfig& config, affine_t* output) | ||
{ | ||
return CONCAT_EXPAND(CURVE, affine_convert_montgomery)(input, n, is_into, config, output); | ||
} | ||
|
||
/*************************** PROJECTIVE CONVERT MONTGOMERY ***************************/ | ||
ICICLE_DISPATCHER_INST(ProjectiveConvertMont, projective_convert_montgomery, ProjectiveConvertMontImpl); | ||
|
||
extern "C" eIcicleError CONCAT_EXPAND(CURVE, projective_convert_montgomery)( | ||
const projective_t* input, size_t n, bool is_into, const ConvertMontgomeryConfig& config, projective_t* output) | ||
{ | ||
return ProjectiveConvertMont::execute(input, n, is_into, config, output); | ||
} | ||
|
||
template <> | ||
eIcicleError points_convert_montgomery( | ||
const projective_t* input, size_t n, bool is_into, const ConvertMontgomeryConfig& config, projective_t* output) | ||
{ | ||
return CONCAT_EXPAND(CURVE, projective_convert_montgomery)(input, n, is_into, config, output); | ||
} | ||
} // namespace icicle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters