C/C++ How can I implement this in C++ or VB.net?

AI Thread Summary
The discussion centers around translating the Ong-Schnorr signature scheme into C++ or VB.net, with a focus on understanding the mathematical concepts involved, particularly the calculation of the inverse random integer k. The Ong-Schnorr-Shamir signature scheme requires selecting a large integer n and a random integer k that is relatively prime to n. The public key is derived from h, calculated as h = -k^-2 mod n, while k serves as the private key. To sign a message M, a random number r is generated, and two signature components, S1 and S2, are computed using modular arithmetic. The verification process involves confirming that S1^2 + h * S2^2 equals M mod n. The conversation also touches on finite field mathematics, providing examples of operations modulo small integers and discussing how to compute inverses in finite fields. Participants offer insights into generating random numbers in C++ and suggest further reading on finite field operations to aid in the translation process.
bhardjono
Messages
2
Reaction score
0
Please help - I am helping a student who is trying to translate Ong-Schnorr to C++ or VB.net language. My major was electronics so I am not sure how to interpret inverse random integer k. Any one ? or suggest me a reference to read on - much thanks, newbie

Ong-Schnorr-Shamir (from Briuce's Applied Cryptography p.418 chp 20.5)
This signature scheme uses polynomials modulo n [1219,1220]. Choose a large integer n (you need not know the factorization of n). Then choose a random integer, k, such that k and n are relatively prime. Calculate h such that
h = –k^-2 mod n = -(k^-1)^2 mod n
The public key is h and n; k is the private key.
To sign a message, M, first generate a random number, r, such that r and n are relatively prime. Then calculate:

S1 = 1/2 * (M/r + r) mod n
S2 = k/2 * (M/r – r) mod n
The pair, S1 and S2, is the signature.
To verify a signature, confirm that
S1^2 + h * S2^2 identical to M (mod n)
 
Technology news on Phys.org
bhardjono said:
Please help - I am helping a student who is trying to translate Ong-Schnorr to C++ or VB.net language. My major was electronics so I am not sure how to interpret inverse random integer k. Any one ? or suggest me a reference to read on - much thanks, newbie

Ong-Schnorr-Shamir (from Briuce's Applied Cryptography p.418 chp 20.5)
This signature scheme uses polynomials modulo n [1219,1220]. Choose a large integer n (you need not know the factorization of n). Then choose a random integer, k, such that k and n are relatively prime. Calculate h such that
h = –k^-2 mod n = -(k^-1)^2 mod n
The public key is h and n; k is the private key.
To sign a message, M, first generate a random number, r, such that r and n are relatively prime. Then calculate:

S1 = 1/2 * (M/r + r) mod n
S2 = k/2 * (M/r – r) mod n
The pair, S1 and S2, is the signature.
To verify a signature, confirm that
S1^2 + h * S2^2 identical to M (mod n)
3 mod 10 = 3
4 mod 10 = 4
10 mod 3 = 1
10 mod 4 = 2

in Schnorr
h= -k^(-2) mod n
h= -(k^(-1))^2 mod n
Hence for 2 primes
9 mod 2 = 1
(3)^2 mod 2 = 1
Therefore k^(-1) = 3 Is this right please your opinion please - thanks in advance
 
I'm not entirely clear what your question is, but if it's how to get a (sorta) random number in C... The stdlib has: int rand ( void ); which you can seed with srand(). A man page is here:
http://www.cplusplus.com/reference/clibrary/cstdlib/rand/
 
I don't know about encryption, but know a bit about finite field math and don't understand your examples. Using 5 as n, you get these tables for finite field math modulo 5:

Code:
add                   subtract (left - top)

   0  1  2  3  4         0  1  2  3  4
  --------------        --------------
0| 0  1  2  3  4      0| 0  4  3  2  1
1| 1  2  3  4  0      1| 1  0  4  3  2
2| 2  3  4  0  1      2| 2  1  0  4  3
3| 3  4  0  1  2      3| 3  2  2  0  4
4| 4  0  1  2  3      4| 4  3  2  1  0

multiply              divide (left / top)

   0  1  2  3  4         0  1  2  3  4
  --------------        --------------
0| 0  0  0  0  0      0| x  0  0  0  0
1| 0  1  2  3  4      1| x  1  3  2  4
2| 0  2  4  1  3      2| x  2  1  4  3
3| 0  3  1  4  2      3| x  3  4  1  2
4| 0  4  3  2  1      4| x  4  2  3  1

All non-zero numbers can be considered to be a power of 2. Multiply and divide can be peformed by taking the logs of finite field numbers and adding or subracting modulo 4 (n-1), the exponentiating the result. This doesn't work for all finite fields, in this case, 2 is a "primitive" for a finite field modulo 5.

20 = 1
21 = 2
22 = 4
23 = 3

In the general case of a finite field number to determine (-1/k)2 , you first find i = ( (0 - k) mod n). Then you need to do a table lookup, or implement an algorithm to solve for j where ((i x j) mod n) = 1, then 1/i = j. (1/i)2 would be ((j2) mod n).
 
Last edited:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top