Bitcoin Forum
June 29, 2024, 06:17:31 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: how to modulo two uint64_t array?  (Read 126 times)
Dr88 (OP)
Newbie
*
Offline Offline

Activity: 15
Merit: 0


View Profile
October 18, 2023, 09:22:25 PM
 #1

hi how to mod this two array in c
   //a=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179
const uint64_t  a[4] =  {0x59f2815b16f81798, 0x029bfcdb2dce28d9, 0x55a06295ce870b07, 0x79be667ef9dcbbac};
  // b=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8

const uint64_t  b[4] =  {0x9c47d08ffb10d4b8, 0xfd17b448a6855419, 0x5da4fbfc0e1108a8, 0x483ada7726a3c465};

// result = a%b;
uint64_t  result[4];
NotATether
Legendary
*
Offline Offline

Activity: 1652
Merit: 6920


In memory of o_e_l_e_o


View Profile WWW
October 19, 2023, 09:18:34 AM
Last edit: October 19, 2023, 11:00:31 AM by NotATether
 #2

Use the GMP library which allows for arbitrary-precision integers. It's much easier than trying to modulo multiple uint64_t parts - although you kinda miss out on performance if your end goal is to run it on CUDA.

You can even import these numbers in hexadecimal base - as well as any other base.

I'm going to assume your numbers are in big-endian, because manually flipping the bytes is too tedious for me.

Code:
const char* a = "59f2815b16f81798029bfcdb2dce28d955a06295ce870b0779be667ef9dcbbac";
const char* b = "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8";
char result[256];

mpz_t ma, mb, mresult;
mpz_init(ma);
mpz_init(mb);
mpz_init(mresult);
mpz_set_str(ma, a, 16);
mpz_set_str(mb, b, 16);
mpz_fdiv_r(mresult, ma, mb); // <--- modulus

mpz_get_str(result, 16, mresult); // returns a hex string without a prefix

// ...

mpz_clear(ma);
mpz_clear(mb);
mpz_clear(mresult);

EDIT: forgot to add bases to mpz_set_str

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
digaran
Copper Member
Hero Member
*****
Offline Offline

Activity: 1330
Merit: 899

🖤😏


View Profile
October 19, 2023, 10:54:19 PM
Last edit: October 20, 2023, 06:09:41 AM by digaran
 #3

Generator point on OP is invalid,  the last digit of //a = is missing, and NotATether, can you tell me why you used the correct y but mixed the x? So if your code is used the result would be unrelated to secp256k1.

What I like to know, what is the purpose of using Gx mod Gy?

Edit, thanks for the reply, I thought there is something new regarding the change of G in your script that I didn't know of.

🖤😏
NotATether
Legendary
*
Offline Offline

Activity: 1652
Merit: 6920


In memory of o_e_l_e_o


View Profile WWW
October 20, 2023, 06:02:15 AM
 #4

Generator point on OP is invalid,  the last digit of //a = is missing, and NotATether, can you tell me why you used the correct y but mixed the x? So if your code is used the result would be unrelated to secp256k1.

What I like to know, what is the purpose of using Gx mod Gy?

I just copied OP's pseudocode and changed it to use GMP - I had no idea that this was the generator point, but you can easily fix that.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!