def printKAT(banner, mpub, mpriv, input, salt, pre_hash, post_hash_len): global wf_small, wf_large h1 = Makwa(mpub.n, mpub.h, pre_hash, post_hash_len, wf_small).hash(input, salt) h2 = Makwa(mpriv.n, mpriv.h, pre_hash, post_hash_len, wf_small).hash(input, salt) check(equals(h1, h2)) out_sm_str = mpub.encode_output(salt, pre_hash, post_hash_len, wf_small, h1) h3 = Makwa(mpub.n, mpub.h, pre_hash, post_hash_len, wf_large).hash(input, salt) h4 = Makwa(mpriv.n, mpriv.h, pre_hash, post_hash_len, wf_large).hash(input, salt) check(equals(h3, h4)) out_lg_str = mpub.encode_output(salt, pre_hash, post_hash_len, wf_large, h3) print(banner) print("input: " + bytes_to_str(input)) print("salt: " + bytes_to_str(salt)) if pre_hash: print("pre-hashing: true") else: print('pre-hashing: false') if post_hash_len == 0: print("post-hashing: false") else: print("post-hashing: " + str(post_hash_len)) print("bin" + str(wf_small) + ": " + bytes_to_str(h1)) print("bin" + str(wf_large) + ": " + bytes_to_str(h3)) print("str" + str(wf_small) + ": " + out_sm_str) print("str" + str(wf_large) + ": " + out_lg_str) print('') h.update(h1) h.update(h3) h.update(bytes(out_sm_str, "UTF-8")) h.update(bytes(out_lg_str, "UTF-8")) if (not pre_hash) and post_hash_len == 0: upi1 = unescrow(priv2048, h1, salt, mpriv.h, wf_small) check(equals(upi1, input)) upi2 = unescrow(priv2048, h1, salt, mpriv.h, wf_small) check(equals(upi2, input))
def printKDF(banner, hashFunction, input, outlen): output = Makwa(makeMakwaPrivateKey(priv2048).modulus, hashFunction).kdf(input, outlen) print(banner) print("input: " + bytes_to_str(input)) print("output: " + bytes_to_str(output)) print('') h.update(output)
def process(self): mod = decodePublic(pub2048) pkey = makeMakwaPrivateKey(priv2048) check(pkey.modulus == mod) mpub = Makwa(mod, sha256, False, 0, 1024) mpriv = Makwa(makeMakwaPrivateKey(priv2048).modulus, sha256, False, 0, 1024) for i in range(200): input = bytearray(i) for j in range(i): input[j] = (7 * i + 83 * j) % 256 printKDF("KDF/SHA-256", sha256, input, 100) printKDF("KDF/SHA-512", sha512, input, 100) pwd = "Gego beshwaji'aaken awe makwa; onzaam naniizaanizi." pi = bytes(pwd, "utf8") salt = bytearray.fromhex('C72703C22A96D9992F3DEA876497E392') ref = bytearray.fromhex('C9CEA0E6EF09393AB1710A08') mpub_to_hash = Makwa(mod, sha256, False, 12, 4096) check(equals(ref, mpub_to_hash.hash(pi, salt))) detailed = mpub.encode_output(salt, False, 12, 4096, ref) print("2048-bit modulus, SHA-256") print("input: " + bytes_to_str(pi)) print("salt: " + bytes_to_str(salt)) print("pre-hashing: false") print("post-hashing: 12") print("bin4096: " + bytes_to_str(ref)) print("str4096: " + detailed) print() h.update(ref) h.update(bytes(detailed, 'UTF-8')) printKAT1("2048-bit modulus, SHA-256", mpub, mpriv) mpub = Makwa(mod, sha512, False, 0, 1024) mpriv = Makwa(makeMakwaPrivateKey(priv2048).modulus, sha512, False, 0, 1024) printKAT1("2048-bit modulus, SHA-512", mpub, mpriv) print("KAT digest: " + bytes_to_str(h.digest()))
def main(): ret_x = encode(255, 5) # print(ret_x) # print(decode(ret_x)) # print(int('55' '22', 16)) PRIV2048 = bytes.fromhex( '55' '41' '4d' '31' '00' '80' 'ea' '43' 'd7' '9d' 'f0' 'b8' '74' '14' '0a' '55' 'ec' 'd1' '44' '73' '2e' 'af' '49' 'd9' 'c8' 'f0' 'e4' '37' '6f' '5d' '72' '97' '2a' '14' '66' '79' 'e3' '82' '44' 'f5' 'a9' '6e' 'f5' 'ce' '92' '8a' '54' '25' '12' '40' '47' '5f' 'd1' 'dd' '96' '8b' '9a' '77' 'ad' 'd1' '65' '50' '56' '4c' '1d' 'd2' '42' '40' '08' 'ea' '83' 'c2' '59' 'd5' '3b' '88' '61' 'c5' 'e9' '4f' '22' '8f' '03' 'c4' '98' 'dd' '3c' '8c' '69' '49' 'e3' '66' '02' 'fe' '74' '6d' '64' 'd5' '14' '89' 'c7' '6c' '74' 'db' 'c2' '44' '7e' '22' '2e' 'cf' '28' 'fa' '9b' 'd4' '4e' '81' '41' '07' '55' '87' '9e' '71' 'bd' 'f8' 'fb' '4a' '61' 'd8' 'ad' '3d' 'f4' '4f' 'fc' '9b' '00' '80' 'd4' '30' '28' 'ee' '37' '4f' 'eb' 'b9' '3b' '5d' 'f8' 'dc' '1c' '68' '37' '13' 'ab' '05' '10' 'af' '7e' 'eb' 'e6' '3d' '33' 'f9' '0a' 'f7' '63' 'fa' '22' '64' 'b6' '8b' '09' '21' '94' '90' 'a5' 'a5' '64' '4d' '63' '56' '85' '9c' '27' 'cd' 'f9' '76' '71' '12' '2e' '4d' '9a' '13' 'd9' '16' '09' '60' '9c' '46' '90' '14' 'da' 'e3' '0f' '9a' 'e6' 'bc' '93' '78' 'e7' '97' '47' '60' '1e' 'ee' 'a8' '18' '46' '98' '42' '72' '08' '9c' '08' '53' '49' '7f' 'c5' '3a' '51' 'd4' '5d' '37' 'f0' 'cb' '4e' '67' 'd8' 'b9' '59' '21' 'b7' 'd2' '93' 'd7' '55' 'b4' '9d' 'da' '55' 'b8' '15' '29' 'a7' '06' 'cd' '67' 'ee' '3b' 'fe' 'fe' 'c4' 'f3' 'f5' 'b3' ) PUB2048 = bytes.fromhex( '55' '41' '4d' '30' '01' '00' 'c2' '2c' '40' 'bb' 'd0' '56' 'bb' '21' '3a' 'ad' '7c' '83' '05' '19' '10' '1a' 'b9' '26' 'ae' '18' 'e3' 'e9' 'fc' '96' '99' 'c8' '06' 'e0' 'ae' '5c' '25' '94' '14' 'a0' '1a' 'c1' 'd5' '2e' '87' '3e' 'c0' '80' '46' 'a6' '8e' '34' '4c' '8d' '74' 'a5' '08' '95' '28' '42' 'ef' '0f' '03' 'f7' '1a' '6e' 'dc' '07' '7f' 'aa' '14' '89' '9a' '79' 'f8' '3c' '3a' 'e1' '36' 'f7' '74' 'fa' '6e' 'b8' '8f' '1d' '1a' 'ea' '5e' 'a0' '2f' 'c0' 'cc' 'af' '96' 'e2' 'ce' '86' 'f3' '49' '0f' '49' '93' 'b4' 'b5' '66' 'c0' '07' '96' '41' '47' '2d' 'ef' 'c1' '4b' 'ec' 'cf' '48' '98' '4a' '79' '46' 'f1' '44' '1e' 'a1' '44' 'ea' '4c' '80' '2a' '45' '75' '50' 'ba' '3d' 'f0' 'f1' '4c' '09' '0a' '75' 'fe' '9e' '6a' '77' 'cf' '0b' 'e9' '8b' '71' 'd5' '62' '51' 'a8' '69' '43' 'e7' '19' 'd2' '78' '65' 'a4' '89' '56' '6c' '1d' 'c5' '7f' 'cd' 'ef' 'ac' 'a6' 'ab' '04' '3f' '8e' '13' 'f6' 'c0' 'be' '7b' '39' 'c9' '2d' 'a8' '6e' '1d' '87' '47' '7a' '18' '9e' '73' 'ce' '8e' '31' '1d' '3d' '51' '36' '1f' '8b' '00' '24' '9f' 'b3' 'd8' '43' '56' '07' 'b1' '4a' '1e' '70' '17' '0f' '9a' 'f3' '67' '84' '11' '0a' '3f' '2e' '67' '42' '8f' 'c1' '8f' 'b0' '13' 'b3' '0f' 'e6' '78' '2a' 'ec' 'b4' '42' '8d' '7c' '8e' '35' '4a' '0f' 'bd' '06' '1b' '01' '91' '7c' '72' '7a' 'be' 'e0' 'fe' '3f' 'd3' 'ce' 'f7' '61' ) M256 = makeMakwa(PRIV2048, sha256, False, 0, 1024) M512 = makeMakwa(PRIV2048, sha512, False, 0, 1024) M256Pub = makeMakwa(PUB2048, sha256, False, 0, 4096) # Sample KDF test print('\nSample KDF test') print(bytes_to_str(M256.kdf(b'\x07', 100))) print(bytes_to_str(M512.kdf(b'\x07', 100))) # Sample password hashing test salt = bytes.fromhex( 'C7' '27' '03' 'C2' '2A' '96' 'D9' '99' '2F' '3D' 'EA' '87' '64' '97' 'E3' '92' ) ref = bytes.fromhex( 'C9' 'CE' 'A0' 'E6' 'EF' '09' '39' '3A' 'B1' '71' '0A' '08' ) salt0 = bytes.fromhex( 'b8' '2c' 'b4' '2e' '3a' '2d' 'fc' '2a' 'd6' '0b' '8b' '76' 'c6' '66' 'b0' '15' ) print(encode(2, 50)) print('\nSample password hashing test') password = "******" pwd_bytes = bytes(password, 'UTF-8') hashed = M256Pub.hash(pwd_bytes, salt) print("Salt= " + bytes_to_str(salt)) print("Ref= " + bytes_to_str(ref)) print("Hashed= " + bytes_to_str(hashed)) print(decodePublic(PUB2048) == makeMakwaPrivateKey(PRIV2048).modulus) hashed2 = makeMakwa(PRIV2048, sha256, False, 0, 4096).hash(pwd_bytes, salt0) print(unescrow(PRIV2048, hashed2, salt0, sha256, 4096)) mkw = makeMakwa(PRIV2048, sha256, False) out = mkw.encode_output(salt0, mkw.preHashing, mkw.t, mkw.w, hashed2) out2 = mkw.set_new_wf(out, 4192) out_ch = mkw.encode_output(salt0, mkw.preHashing, mkw.t, 4192, mkw.change_wf(None, hashed2, 96)) mkw2 = makeMakwa(PRIV2048, sha256, False, 0, 4192) out3 = mkw2.encode_output(salt0, mkw2.preHashing, mkw2.t, mkw2.w, mkw2.hash(pwd_bytes, salt0)) print("\nWF 4096:") print(out) print("\nWF 4192 (new makwa): ") print(out3) print("\nWF 4192 (set_new): ") print(out2) print("\nWF 4192 (change +96): ") print(out_ch) print("\nequality of all WF 4192:", out2 == out3 == out_ch)
'2e' '4d' '9a' '13' 'd9' '16' '09' '60' '9c' '46' '90' '14' 'da' 'e3' '0f' '9a' 'e6' 'bc' '93' '78' 'e7' '97' '47' '60' '1e' 'ee' 'a8' '18' '46' '98' '42' '72' '08' '9c' '08' '53' '49' '7f' 'c5' '3a' '51' 'd4' '5d' '37' 'f0' 'cb' '4e' '67' 'd8' 'b9' '59' '21' 'b7' 'd2' '93' 'd7' '55' 'b4' '9d' 'da' '55' 'b8' '15' '29' 'a7' '06' 'cd' '67' 'ee' '3b' 'fe' 'fe' 'c4' 'f3' 'f5' 'b3' ) md = generate(PRIV2048, 16, random_pairs) print(md.modulus) sk = makeMakwaPrivateKey(PRIV2048) mod = sk.modulus md_enc = md.export() print("Delegacja: ", bytes_to_str(md_enc)) md = makeDelegation(md_enc) print(md.modulus)
def main(): PRIV2048 = bytes.fromhex( '55' '41' '4d' '31' '00' '80' 'ea' '43' 'd7' '9d' 'f0' 'b8' '74' '14' '0a' '55' 'ec' 'd1' '44' '73' '2e' 'af' '49' 'd9' 'c8' 'f0' 'e4' '37' '6f' '5d' '72' '97' '2a' '14' '66' '79' 'e3' '82' '44' 'f5' 'a9' '6e' 'f5' 'ce' '92' '8a' '54' '25' '12' '40' '47' '5f' 'd1' 'dd' '96' '8b' '9a' '77' 'ad' 'd1' '65' '50' '56' '4c' '1d' 'd2' '42' '40' '08' 'ea' '83' 'c2' '59' 'd5' '3b' '88' '61' 'c5' 'e9' '4f' '22' '8f' '03' 'c4' '98' 'dd' '3c' '8c' '69' '49' 'e3' '66' '02' 'fe' '74' '6d' '64' 'd5' '14' '89' 'c7' '6c' '74' 'db' 'c2' '44' '7e' '22' '2e' 'cf' '28' 'fa' '9b' 'd4' '4e' '81' '41' '07' '55' '87' '9e' '71' 'bd' 'f8' 'fb' '4a' '61' 'd8' 'ad' '3d' 'f4' '4f' 'fc' '9b' '00' '80' 'd4' '30' '28' 'ee' '37' '4f' 'eb' 'b9' '3b' '5d' 'f8' 'dc' '1c' '68' '37' '13' 'ab' '05' '10' 'af' '7e' 'eb' 'e6' '3d' '33' 'f9' '0a' 'f7' '63' 'fa' '22' '64' 'b6' '8b' '09' '21' '94' '90' 'a5' 'a5' '64' '4d' '63' '56' '85' '9c' '27' 'cd' 'f9' '76' '71' '12' '2e' '4d' '9a' '13' 'd9' '16' '09' '60' '9c' '46' '90' '14' 'da' 'e3' '0f' '9a' 'e6' 'bc' '93' '78' 'e7' '97' '47' '60' '1e' 'ee' 'a8' '18' '46' '98' '42' '72' '08' '9c' '08' '53' '49' '7f' 'c5' '3a' '51' 'd4' '5d' '37' 'f0' 'cb' '4e' '67' 'd8' 'b9' '59' '21' 'b7' 'd2' '93' 'd7' '55' 'b4' '9d' 'da' '55' 'b8' '15' '29' 'a7' '06' 'cd' '67' 'ee' '3b' 'fe' 'fe' 'c4' 'f3' 'f5' 'b3' ) print('ModInverse(7,20): '+str(modInverse(7, 20))) mpriv = makeMakwaPrivateKey(PRIV2048) print('Modulus from priv: '+bytes_to_str(encode(mpriv.modulus))) print('Modulus from exported public: '+bytes_to_str(encode(decodePublic(mpriv.exportPublic())))) print('Exported public: '+bytes_to_str(mpriv.exportPublic())) print('Exported priv: '+bytes_to_str(mpriv.exportPrivate())) mpriv_gen = generatePrivateKey(2048) print('Generated private: '+bytes_to_str(mpriv_gen.exportPrivate()))