mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-05 12:51:04 -05:00
hash_to_p3 builds, links and can be called from rust code
Assertion failed: ((fe_add(y, w, x), !fe_isnonzero(y))), function ge_fromfe_frombytes_vartime, file depend/hash/crypto-ops.c, line 2656.
This commit is contained in:
parent
00648d2747
commit
64b97d42b7
@ -7,8 +7,8 @@ include_directories(monero-adaptor/depend/hash)
|
||||
|
||||
add_library(xmr_btc_swap_comit
|
||||
monero-adaptor/depend/hash/hash.c
|
||||
monero-adaptor/depend/hash/hash.h
|
||||
monero-adaptor/depend/hash/int-util.h
|
||||
monero-adaptor/depend/hash/include/hash.h
|
||||
monero-adaptor/depend/hash/include/int-util.h
|
||||
monero-adaptor/depend/hash/crypto-ops.c
|
||||
monero-adaptor/depend/hash/crypto-ops.h
|
||||
monero-adaptor/depend/hash/warnings.h)
|
||||
monero-adaptor/depend/hash/include/crypto-ops.h
|
||||
monero-adaptor/depend/hash/include/warnings.h)
|
||||
|
@ -8,7 +8,7 @@ fn main() {
|
||||
println!("cargo:rerun-if-changed=depend/hash");
|
||||
|
||||
let mut base_config = cc::Build::new();
|
||||
base_config.include("depend/hash");
|
||||
base_config.include("depend/hash/include");
|
||||
base_config.file("depend/hash/hash.c");
|
||||
base_config.file("depend/hash/crypto-ops.c");
|
||||
base_config.compile("hash");
|
||||
@ -18,22 +18,23 @@ fn main() {
|
||||
// The bindgen::Builder is the main entry point
|
||||
// to bindgen, and lets you build up options for
|
||||
// the resulting bindings.
|
||||
|
||||
let bindings = bindgen::Builder::default()
|
||||
// The input header we would like to generate
|
||||
// bindings for.
|
||||
.header("depend/hash/hash.h")
|
||||
// Tell cargo to invalidate the built crate whenever any of the
|
||||
// included header files changed.
|
||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
|
||||
// Finish the builder and generate the bindings.
|
||||
.generate()
|
||||
// Unwrap the Result and panic on failure.
|
||||
.expect("Unable to generate bindings");
|
||||
|
||||
// Write the bindings to the $OUT_DIR/bindings.rs file.
|
||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
bindings
|
||||
.write_to_file(out_path.join("bindings.rs"))
|
||||
.expect("Couldn't write bindings!");
|
||||
//
|
||||
// let bindings = bindgen::Builder::default()
|
||||
// // The input header we would like to generate
|
||||
// // bindings for.
|
||||
// .header("depend/hash/hash.h")
|
||||
// .header("depend/hash/crypto-ops.h")
|
||||
// // Tell cargo to invalidate the built crate whenever any of the
|
||||
// // included header files changed.
|
||||
// .parse_callbacks(Box::new(bindgen::CargoCallbacks))
|
||||
// // Finish the builder and generate the bindings.
|
||||
// .generate()
|
||||
// // Unwrap the Result and panic on failure.
|
||||
// .expect("Unable to generate bindings");
|
||||
//
|
||||
// // Write the bindings to the $OUT_DIR/bindings.rs file.
|
||||
// let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
// bindings
|
||||
// .write_to_file(out_path.join("bindings.rs"))
|
||||
// .expect("Couldn't write bindings!");
|
||||
}
|
||||
|
@ -31,13 +31,22 @@
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "warnings.h"
|
||||
#include "crypto-ops.h"
|
||||
#include "include/warnings.h"
|
||||
#include "include/crypto-ops.h"
|
||||
|
||||
DISABLE_VS_WARNINGS(4146 4244)
|
||||
|
||||
/* Predeclarations */
|
||||
|
||||
const fe fe_ma2;
|
||||
const fe fe_ma;
|
||||
const fe fe_fffb1;
|
||||
const fe fe_fffb2;
|
||||
const fe fe_fffb3;
|
||||
const fe fe_fffb4;
|
||||
const fe fe_sqrtm1;
|
||||
const fe fe_d;
|
||||
|
||||
static void fe_mul(fe, const fe, const fe);
|
||||
|
||||
static void fe_sq(fe, const fe);
|
||||
|
@ -1,11 +1,11 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "hash.h"
|
||||
#include "include/hash.h"
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "int-util.h"
|
||||
#include "crypto-ops.h"
|
||||
#include "include/int-util.h"
|
||||
#include "include/crypto-ops.h"
|
||||
|
||||
#ifndef ROTL64
|
||||
#define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y))))
|
||||
@ -146,207 +146,4 @@ void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen) {
|
||||
local_abort("Bad keccak use");
|
||||
}
|
||||
memcpy_swap64le(md, st, mdlen / sizeof(uint64_t));
|
||||
}
|
||||
|
||||
uint64_t load_3(const unsigned char *in) {
|
||||
uint64_t result;
|
||||
result = (uint64_t) in[0];
|
||||
result |= ((uint64_t) in[1]) << 8;
|
||||
result |= ((uint64_t) in[2]) << 16;
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64_t load_4(const unsigned char *in) {
|
||||
uint64_t result;
|
||||
result = (uint64_t) in[0];
|
||||
result |= ((uint64_t) in[1]) << 8;
|
||||
result |= ((uint64_t) in[2]) << 16;
|
||||
result |= ((uint64_t) in[3]) << 24;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void sc_reduce32(unsigned char *s) {
|
||||
int64_t s0 = 2097151 & load_3(s);
|
||||
int64_t s1 = 2097151 & (load_4(s + 2) >> 5);
|
||||
int64_t s2 = 2097151 & (load_3(s + 5) >> 2);
|
||||
int64_t s3 = 2097151 & (load_4(s + 7) >> 7);
|
||||
int64_t s4 = 2097151 & (load_4(s + 10) >> 4);
|
||||
int64_t s5 = 2097151 & (load_3(s + 13) >> 1);
|
||||
int64_t s6 = 2097151 & (load_4(s + 15) >> 6);
|
||||
int64_t s7 = 2097151 & (load_3(s + 18) >> 3);
|
||||
int64_t s8 = 2097151 & load_3(s + 21);
|
||||
int64_t s9 = 2097151 & (load_4(s + 23) >> 5);
|
||||
int64_t s10 = 2097151 & (load_3(s + 26) >> 2);
|
||||
int64_t s11 = (load_4(s + 28) >> 7);
|
||||
int64_t s12 = 0;
|
||||
int64_t carry0;
|
||||
int64_t carry1;
|
||||
int64_t carry2;
|
||||
int64_t carry3;
|
||||
int64_t carry4;
|
||||
int64_t carry5;
|
||||
int64_t carry6;
|
||||
int64_t carry7;
|
||||
int64_t carry8;
|
||||
int64_t carry9;
|
||||
int64_t carry10;
|
||||
int64_t carry11;
|
||||
|
||||
carry0 = (s0 + (1 << 20)) >> 21;
|
||||
s1 += carry0;
|
||||
s0 -= carry0 << 21;
|
||||
carry2 = (s2 + (1 << 20)) >> 21;
|
||||
s3 += carry2;
|
||||
s2 -= carry2 << 21;
|
||||
carry4 = (s4 + (1 << 20)) >> 21;
|
||||
s5 += carry4;
|
||||
s4 -= carry4 << 21;
|
||||
carry6 = (s6 + (1 << 20)) >> 21;
|
||||
s7 += carry6;
|
||||
s6 -= carry6 << 21;
|
||||
carry8 = (s8 + (1 << 20)) >> 21;
|
||||
s9 += carry8;
|
||||
s8 -= carry8 << 21;
|
||||
carry10 = (s10 + (1 << 20)) >> 21;
|
||||
s11 += carry10;
|
||||
s10 -= carry10 << 21;
|
||||
|
||||
carry1 = (s1 + (1 << 20)) >> 21;
|
||||
s2 += carry1;
|
||||
s1 -= carry1 << 21;
|
||||
carry3 = (s3 + (1 << 20)) >> 21;
|
||||
s4 += carry3;
|
||||
s3 -= carry3 << 21;
|
||||
carry5 = (s5 + (1 << 20)) >> 21;
|
||||
s6 += carry5;
|
||||
s5 -= carry5 << 21;
|
||||
carry7 = (s7 + (1 << 20)) >> 21;
|
||||
s8 += carry7;
|
||||
s7 -= carry7 << 21;
|
||||
carry9 = (s9 + (1 << 20)) >> 21;
|
||||
s10 += carry9;
|
||||
s9 -= carry9 << 21;
|
||||
carry11 = (s11 + (1 << 20)) >> 21;
|
||||
s12 += carry11;
|
||||
s11 -= carry11 << 21;
|
||||
|
||||
s0 += s12 * 666643;
|
||||
s1 += s12 * 470296;
|
||||
s2 += s12 * 654183;
|
||||
s3 -= s12 * 997805;
|
||||
s4 += s12 * 136657;
|
||||
s5 -= s12 * 683901;
|
||||
s12 = 0;
|
||||
|
||||
carry0 = s0 >> 21;
|
||||
s1 += carry0;
|
||||
s0 -= carry0 << 21;
|
||||
carry1 = s1 >> 21;
|
||||
s2 += carry1;
|
||||
s1 -= carry1 << 21;
|
||||
carry2 = s2 >> 21;
|
||||
s3 += carry2;
|
||||
s2 -= carry2 << 21;
|
||||
carry3 = s3 >> 21;
|
||||
s4 += carry3;
|
||||
s3 -= carry3 << 21;
|
||||
carry4 = s4 >> 21;
|
||||
s5 += carry4;
|
||||
s4 -= carry4 << 21;
|
||||
carry5 = s5 >> 21;
|
||||
s6 += carry5;
|
||||
s5 -= carry5 << 21;
|
||||
carry6 = s6 >> 21;
|
||||
s7 += carry6;
|
||||
s6 -= carry6 << 21;
|
||||
carry7 = s7 >> 21;
|
||||
s8 += carry7;
|
||||
s7 -= carry7 << 21;
|
||||
carry8 = s8 >> 21;
|
||||
s9 += carry8;
|
||||
s8 -= carry8 << 21;
|
||||
carry9 = s9 >> 21;
|
||||
s10 += carry9;
|
||||
s9 -= carry9 << 21;
|
||||
carry10 = s10 >> 21;
|
||||
s11 += carry10;
|
||||
s10 -= carry10 << 21;
|
||||
carry11 = s11 >> 21;
|
||||
s12 += carry11;
|
||||
s11 -= carry11 << 21;
|
||||
|
||||
s0 += s12 * 666643;
|
||||
s1 += s12 * 470296;
|
||||
s2 += s12 * 654183;
|
||||
s3 -= s12 * 997805;
|
||||
s4 += s12 * 136657;
|
||||
s5 -= s12 * 683901;
|
||||
|
||||
carry0 = s0 >> 21;
|
||||
s1 += carry0;
|
||||
s0 -= carry0 << 21;
|
||||
carry1 = s1 >> 21;
|
||||
s2 += carry1;
|
||||
s1 -= carry1 << 21;
|
||||
carry2 = s2 >> 21;
|
||||
s3 += carry2;
|
||||
s2 -= carry2 << 21;
|
||||
carry3 = s3 >> 21;
|
||||
s4 += carry3;
|
||||
s3 -= carry3 << 21;
|
||||
carry4 = s4 >> 21;
|
||||
s5 += carry4;
|
||||
s4 -= carry4 << 21;
|
||||
carry5 = s5 >> 21;
|
||||
s6 += carry5;
|
||||
s5 -= carry5 << 21;
|
||||
carry6 = s6 >> 21;
|
||||
s7 += carry6;
|
||||
s6 -= carry6 << 21;
|
||||
carry7 = s7 >> 21;
|
||||
s8 += carry7;
|
||||
s7 -= carry7 << 21;
|
||||
carry8 = s8 >> 21;
|
||||
s9 += carry8;
|
||||
s8 -= carry8 << 21;
|
||||
carry9 = s9 >> 21;
|
||||
s10 += carry9;
|
||||
s9 -= carry9 << 21;
|
||||
carry10 = s10 >> 21;
|
||||
s11 += carry10;
|
||||
s10 -= carry10 << 21;
|
||||
|
||||
s[0] = s0 >> 0;
|
||||
s[1] = s0 >> 8;
|
||||
s[2] = (s0 >> 16) | (s1 << 5);
|
||||
s[3] = s1 >> 3;
|
||||
s[4] = s1 >> 11;
|
||||
s[5] = (s1 >> 19) | (s2 << 2);
|
||||
s[6] = s2 >> 6;
|
||||
s[7] = (s2 >> 14) | (s3 << 7);
|
||||
s[8] = s3 >> 1;
|
||||
s[9] = s3 >> 9;
|
||||
s[10] = (s3 >> 17) | (s4 << 4);
|
||||
s[11] = s4 >> 4;
|
||||
s[12] = s4 >> 12;
|
||||
s[13] = (s4 >> 20) | (s5 << 1);
|
||||
s[14] = s5 >> 7;
|
||||
s[15] = (s5 >> 15) | (s6 << 6);
|
||||
s[16] = s6 >> 2;
|
||||
s[17] = s6 >> 10;
|
||||
s[18] = (s6 >> 18) | (s7 << 3);
|
||||
s[19] = s7 >> 5;
|
||||
s[20] = s7 >> 13;
|
||||
s[21] = s8 >> 0;
|
||||
s[22] = s8 >> 8;
|
||||
s[23] = (s8 >> 16) | (s9 << 5);
|
||||
s[24] = s9 >> 3;
|
||||
s[25] = s9 >> 11;
|
||||
s[26] = (s9 >> 19) | (s10 << 2);
|
||||
s[27] = s10 >> 6;
|
||||
s[28] = (s10 >> 14) | (s11 << 7);
|
||||
s[29] = s11 >> 1;
|
||||
s[30] = s11 >> 9;
|
||||
s[31] = s11 >> 17;
|
||||
}
|
||||
}
|
@ -89,9 +89,6 @@ void ge_double_scalarmult_base_vartime_p3(ge_p3 *, const unsigned char *, const
|
||||
|
||||
/* From ge_frombytes.c, modified */
|
||||
|
||||
extern const fe fe_sqrtm1;
|
||||
extern const fe fe_d;
|
||||
|
||||
int ge_frombytes_vartime(ge_p3 *, const unsigned char *);
|
||||
|
||||
/* From ge_p1p1_to_p2.c */
|
||||
@ -154,12 +151,6 @@ void ge_double_scalarmult_precomp_vartime2_p3(ge_p3 *, const unsigned char *, co
|
||||
|
||||
void ge_mul8(ge_p1p1 *, const ge_p2 *);
|
||||
|
||||
extern const fe fe_ma2;
|
||||
extern const fe fe_ma;
|
||||
extern const fe fe_fffb1;
|
||||
extern const fe fe_fffb2;
|
||||
extern const fe fe_fffb3;
|
||||
extern const fe fe_fffb4;
|
||||
extern const ge_p3 ge_p3_identity;
|
||||
extern const ge_p3 ge_p3_H;
|
||||
|
Loading…
Reference in New Issue
Block a user