A = helpers.getRandomInt(514) B = helpers.getRandomInt(514) C = HW.MultiPrecisionAdd(A, B, "subtract") print "A = ", hex(A) # 514-bits print "B = ", hex(B) # 514-bits print "A - B = ", hex(C) # 515-bits ##################################################### if operation == 3: print "Test Vector for Montgomery Multiplication\n" A = helpers.getRandomInt(512) B = helpers.getRandomInt(512) M = helpers.getModulus(512) C = HW.MontMul_512(A, B, M) D = (A * B * helpers.Modinv(2**512, M)) % M e = C - D print "A = ", hex(A) # 512-bits print "B = ", hex(B) # 512-bits print "M = ", hex(M) # 512-bits print "(A*B*R^-1) mod M = ", hex(C) # 512-bits print "(A*B*R^-1) mod M = ", hex(D) # 512-bits print "error = ", hex(e) ##################################################### if operation == 4:
import helpers import HW import SW import sys M = helpers.getModulus(1024) # A = helpers.getRandomInt(1024) % M # B = helpers.getRandomInt(1024) % M A = M - 1 B = M - 1 D = HW.MontMul_2bW(A, B, M) print "A = ", hex(A) # 1024-bits print "B = ", hex(B) # 1024-bits print "M = ", hex(M) # 1024-bits print "(A*B*R^-1) mod M = ", hex(D) # 1024-bits
A = helpers.getRandomInt(514) B = helpers.getRandomInt(514) C = HW.MultiPrecisionAdd(A, B, "subtract") print "A = ", hex(A) # 514-bits print "B = ", hex(B) # 514-bits print "A - B = ", hex(C) # 515-bits ##################################################### if operation == 3: print "Test Vector for Montgomery Multiplication\n" A = helpers.getRandomInt(512) B = helpers.getRandomInt(512) N = helpers.getModulus(512) # A = 0xa84ff2f71071936d568335f4e31da1c104c831dc18d7b9199f5d96b9df7315bd0fa8db7a6201cf9ae0842c7f6797a025684296de2089f536c18b7a583c7a9fc5 # B = 0xb9cf554dbc2f7d876274c0895b10c21a0322d9435a2cd1af43a483a61f7cfb92f984df1a0d9357bc796f8e582427a609d99348f8079de7731fc8a31b3eea6c6e # M = 0xef449a8c29c1266af559bdb8d0c42c042b9a46f619b28d7094369f2842ebe42175eb00442338301d1a509aef69043c1dee3bc1f3a06da74e54d094bc7e4ec49b C = HW.MontMul_512(A, B, M) D = (A * B * helpers.Modinv(2**512, M)) % M e = C - D print "A = ", hex(A) # 512-bits print "B = ", hex(B) # 512-bits print "M = ", hex(M) # 512-bits print "(A*B*R^-1) mod M = ", hex(C) # 512-bits print "(A*B*R^-1) mod M = ", hex(D) # 512-bits print "error = ", hex(e)