def stream_xsalsa20_test4(): """ """ m = "0000000000000000000000000000000000000000000000000000000000000000" m = m + "be075fc53c81f2d5cf141316ebeb0c7b5228c52a4c62cbd44b66849b64244ffc" m = m + "e5ecbaaf33bd751a1ac728d45e6c61296cdc3c01233561f41db66cce314adb31" m = m + "0e3be8250c46f06dceea3a7fa1348057e2f6556ad6b1318a024a838f21af1fde" m = m + "048977eb48f59ffd4924ca1c60902e52f0a089bc76897040e082f93776384864" m = m + "5e0705" r = "0000000000000000000000000000000000000000000000000000000000000000" r = r + "8e993b9f48681273c29650ba32fc76ce48332ea7164d96a4476fb8c531a1186a" r = r + "c0dfc17c98dce87b4da7f011ec48c97271d2c20f9b928fe2270d6fb863d51738" r = r + "b48eeee314a7cc8ab932164548e526ae90224368517acfeabd6bb3732bc0e9da" r = r + "99832b61ca01b6de56244a9e88d5f9b37973f622a43d14a6599b1f654cb45a74" r = r + "e355a5" k = "1b27556473e985d462cd51197a9a46c76009549eac6474f206c4ee0844f68389" n = "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37" c = nacl.crypto_stream_xor(fromhex(m), fromhex(n), fromhex(k)) if c[32:] != fromhex(r)[32:]: raise ValueError("unexpected result")
def stream_xsalsa20_test4(): """ """ m = "0000000000000000000000000000000000000000000000000000000000000000" m = m + "be075fc53c81f2d5cf141316ebeb0c7b5228c52a4c62cbd44b66849b64244ffc" m = m + "e5ecbaaf33bd751a1ac728d45e6c61296cdc3c01233561f41db66cce314adb31" m = m + "0e3be8250c46f06dceea3a7fa1348057e2f6556ad6b1318a024a838f21af1fde" m = m + "048977eb48f59ffd4924ca1c60902e52f0a089bc76897040e082f93776384864" m = m + "5e0705" r = "0000000000000000000000000000000000000000000000000000000000000000" r = r + "8e993b9f48681273c29650ba32fc76ce48332ea7164d96a4476fb8c531a1186a" r = r + "c0dfc17c98dce87b4da7f011ec48c97271d2c20f9b928fe2270d6fb863d51738" r = r + "b48eeee314a7cc8ab932164548e526ae90224368517acfeabd6bb3732bc0e9da" r = r + "99832b61ca01b6de56244a9e88d5f9b37973f622a43d14a6599b1f654cb45a74" r = r + "e355a5" k = "1b27556473e985d462cd51197a9a46c76009549eac6474f206c4ee0844f68389" n = "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37" c = nacl.crypto_stream_xor(fromhex(m), fromhex(n), fromhex(k)) if c[32:] != fromhex(r)[32:]: raise ValueError("unexpected result")
def scalarmult_curve25519_test1(): """ """ sk = "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a" r = "8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a" pk = nacl.crypto_scalarmult_base(fromhex(sk)) if pk != fromhex(r): raise ValueError("invalid crypto_scalarmult_base result")
def scalarmult_curve25519_test1(): """ """ sk = "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a" r = "8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a" pk = nacl.crypto_scalarmult_base(fromhex(sk)) if pk != fromhex(r): raise ValueError("invalid crypto_scalarmult_base result")
def scalarmult_curve25519_test2(): """ """ sk = "5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb" r = "de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f" pk = nacl.crypto_scalarmult_base(fromhex(sk)) if pk != fromhex(r): raise ValueError("invalid crypto_scalarmult_base result")
def scalarmult_curve25519_test2(): """ """ sk = "5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb" r = "de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f" pk = nacl.crypto_scalarmult_base(fromhex(sk)) if pk != fromhex(r): raise ValueError("invalid crypto_scalarmult_base result")
def scalarmult_curve25519_test3(): """ """ alicesk = "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a" bobpk = "de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f" r = "4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742" x = nacl.crypto_scalarmult(fromhex(alicesk), fromhex(bobpk)) if x != fromhex(r): raise ValueError("invalid crypto_scalarmult result")
def scalarmult_curve25519_test3(): """ """ alicesk = "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a" bobpk = "de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f" r = "4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742" x = nacl.crypto_scalarmult(fromhex(alicesk), fromhex(bobpk)) if x != fromhex(r): raise ValueError("invalid crypto_scalarmult result")
def stream_xsalsa20_test3(): """ """ r = "eea6a7251c1e72916d11c2cb214d3c252539121d8e234e652d651fa4c8cff880" k = "1b27556473e985d462cd51197a9a46c76009549eac6474f206c4ee0844f68389" n = "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37" c = nacl.crypto_stream(32, fromhex(n), fromhex(k)) if c != fromhex(r): raise ValueError("unexpected result")
def stream_xsalsa20_test3(): """ """ r = "eea6a7251c1e72916d11c2cb214d3c252539121d8e234e652d651fa4c8cff880" k = "1b27556473e985d462cd51197a9a46c76009549eac6474f206c4ee0844f68389" n = "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37" c = nacl.crypto_stream(32, fromhex(n), fromhex(k)) if c != fromhex(r): raise ValueError("unexpected result")
def onetimeauth_poly1305_test2(): """ """ k = "eea6a7251c1e72916d11c2cb214d3c252539121d8e234e652d651fa4c8cff880" m = "8e993b9f48681273c29650ba32fc76ce48332ea7164d96a4476fb8c531a1186a" m = m + "c0dfc17c98dce87b4da7f011ec48c97271d2c20f9b928fe2270d6fb863d51738" m = m + "b48eeee314a7cc8ab932164548e526ae90224368517acfeabd6bb3732bc0e9da" m = m + "99832b61ca01b6de56244a9e88d5f9b37973f622a43d14a6599b1f654cb45a74" m = m + "e355a5" a = "f3ffc7703f9400e52a7dfb4b3d3305d9" nacl.crypto_onetimeauth_verify(fromhex(a), fromhex(m), fromhex(k))
def onetimeauth_poly1305_test2(): """ """ k = "eea6a7251c1e72916d11c2cb214d3c252539121d8e234e652d651fa4c8cff880" m = "8e993b9f48681273c29650ba32fc76ce48332ea7164d96a4476fb8c531a1186a" m = m + "c0dfc17c98dce87b4da7f011ec48c97271d2c20f9b928fe2270d6fb863d51738" m = m + "b48eeee314a7cc8ab932164548e526ae90224368517acfeabd6bb3732bc0e9da" m = m + "99832b61ca01b6de56244a9e88d5f9b37973f622a43d14a6599b1f654cb45a74" m = m + "e355a5" a = "f3ffc7703f9400e52a7dfb4b3d3305d9" nacl.crypto_onetimeauth_verify(fromhex(a), fromhex(m), fromhex(k))
def stream_xsalsa20_test(): """ """ r = "2bd8e7db6877539e4f2b295ee415cd378ae214aa3beb3e08e911a5bd4a25e6ac" r = r + "16ca283c79c34c08c99f7bdb560111e8cac1ae65eea08ac384d7a591461ab6e3" k = "1b27556473e985d462cd51197a9a46c76009549eac6474f206c4ee0844f68389" n = "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37" c = nacl.crypto_stream(4194304, fromhex(n), fromhex(k)) h = nacl.crypto_hash(c) if h != fromhex(r): raise ValueError("unexpected result")
def stream_xsalsa20_test(): """ """ r = "2bd8e7db6877539e4f2b295ee415cd378ae214aa3beb3e08e911a5bd4a25e6ac" r = r + "16ca283c79c34c08c99f7bdb560111e8cac1ae65eea08ac384d7a591461ab6e3" k = "1b27556473e985d462cd51197a9a46c76009549eac6474f206c4ee0844f68389" n = "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37" c = nacl.crypto_stream(4194304, fromhex(n), fromhex(k)) h = nacl.crypto_hash(c) if h != fromhex(r): raise ValueError("unexpected result")
def secretbox_xsalsa20poly1305_test2(): """ """ n = "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37" k = "1b27556473e985d462cd51197a9a46c76009549eac6474f206c4ee0844f68389" m = "be075fc53c81f2d5cf141316ebeb0c7b5228c52a4c62cbd44b66849b64244ffc" m = m + "e5ecbaaf33bd751a1ac728d45e6c61296cdc3c01233561f41db66cce314adb31" m = m + "0e3be8250c46f06dceea3a7fa1348057e2f6556ad6b1318a024a838f21af1fde" m = m + "048977eb48f59ffd4924ca1c60902e52f0a089bc76897040e082f93776384864" m = m + "5e0705" c = "f3ffc7703f9400e52a7dfb4b3d3305d98e993b9f48681273c29650ba32fc76ce" c = c + "48332ea7164d96a4476fb8c531a1186ac0dfc17c98dce87b4da7f011ec48c972" c = c + "71d2c20f9b928fe2270d6fb863d51738b48eeee314a7cc8ab932164548e526ae" c = c + "90224368517acfeabd6bb3732bc0e9da99832b61ca01b6de56244a9e88d5f9b3" c = c + "7973f622a43d14a6599b1f654cb45a74e355a5" m1 = nacl.crypto_secretbox_open(fromhex(c), fromhex(n), fromhex(k)) if m1 != fromhex(m): raise ValueError("invalid secretbox")
def secretbox_xsalsa20poly1305_test2(): """ """ n = "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37" k = "1b27556473e985d462cd51197a9a46c76009549eac6474f206c4ee0844f68389" m = "be075fc53c81f2d5cf141316ebeb0c7b5228c52a4c62cbd44b66849b64244ffc" m = m + "e5ecbaaf33bd751a1ac728d45e6c61296cdc3c01233561f41db66cce314adb31" m = m + "0e3be8250c46f06dceea3a7fa1348057e2f6556ad6b1318a024a838f21af1fde" m = m + "048977eb48f59ffd4924ca1c60902e52f0a089bc76897040e082f93776384864" m = m + "5e0705" c = "f3ffc7703f9400e52a7dfb4b3d3305d98e993b9f48681273c29650ba32fc76ce" c = c + "48332ea7164d96a4476fb8c531a1186ac0dfc17c98dce87b4da7f011ec48c972" c = c + "71d2c20f9b928fe2270d6fb863d51738b48eeee314a7cc8ab932164548e526ae" c = c + "90224368517acfeabd6bb3732bc0e9da99832b61ca01b6de56244a9e88d5f9b3" c = c + "7973f622a43d14a6599b1f654cb45a74e355a5" m1 = nacl.crypto_secretbox_open(fromhex(c), fromhex(n), fromhex(k)) if m1 != fromhex(m): raise ValueError("invalid secretbox")
def sign_ed25519_test(): """ """ pk = "8f58d8bfb192d1d7e0c3998a8d5cb5effc922a0d7080e83be027ebf61495fd16" sk = "7834095954aaa92c523a413fb6fa6be1d70f39305ae17012597d32599b8b6b2f" sk = sk + "8f58d8bfb192d1d7e0c3998a8d5cb5effc922a0d7080e83be027ebf61495fd16" m = "61686f6a0a" sm = "ce1e15adc31747157d4460c17fb8ba45f36d0bbf51f9bb6bb9a1d24e448d9e8c" sm = sm + "366f7a8b5e2c69ba902e954619d8c18a47c56e4a289e8117ae9069717d846a01" sm = sm + "61686f6a0a" s = nacl.crypto_sign(fromhex(m), fromhex(sk)) if s != fromhex(sm): raise ValueError("invalid signature") t = nacl.crypto_sign_open(s, fromhex(pk)) if fromhex(m) != t: raise ValueError("crypto_sign_open does not match contents")
def sign_ed25519_test(): """ """ pk = "8f58d8bfb192d1d7e0c3998a8d5cb5effc922a0d7080e83be027ebf61495fd16" sk = "7834095954aaa92c523a413fb6fa6be1d70f39305ae17012597d32599b8b6b2f" sk = sk + "8f58d8bfb192d1d7e0c3998a8d5cb5effc922a0d7080e83be027ebf61495fd16" m = "61686f6a0a" sm = "ce1e15adc31747157d4460c17fb8ba45f36d0bbf51f9bb6bb9a1d24e448d9e8c" sm = sm + "366f7a8b5e2c69ba902e954619d8c18a47c56e4a289e8117ae9069717d846a01" sm = sm + "61686f6a0a" s = nacl.crypto_sign(fromhex(m), fromhex(sk)) if s != fromhex(sm): raise ValueError("invalid signature") t = nacl.crypto_sign_open(s, fromhex(pk)) if fromhex(m) != t: raise ValueError("crypto_sign_open does not match contents")
def keys(self): if self.path == "---null---/": return [] paths = list(os.listdir(self.path)) bytepaths = [] for item in paths: try: bytepaths.append(util.fromhex(item, 32)) except ValueError: pass # Likely not a real key, ignore it. return bytepaths
def hash_sha512_mc_test(): """ NIST SHAVS pseudorandomly generated messages (monte carlo) test """ r = "dc13a41114a59c0bedba376d1afed10fda5be9febd68e0acaa9454007c8284845213cd05945a29ac1149ab0eb6c4714998614b79d6ca00648c9aba6b2335f0b3" seed = [ 0x41, 0x15, 0x63, 0xc9, 0x97, 0x5d, 0xeb, 0x4f, 0xe8, 0x02, 0x76, 0x83, 0x0e, 0x83, 0x53, 0x04, 0x82, 0x8a, 0x5c, 0xd8, 0x7c, 0x79, 0x34, 0xa5, 0x5c, 0x45, 0xcc, 0x23, 0x49, 0x87, 0x2c, 0xd1, 0x18, 0xd0, 0x70, 0xe7, 0x6f, 0x3d, 0x10, 0x8c, 0x2a, 0x4c, 0x65, 0x4a, 0xfd, 0xee, 0x69, 0xbf, 0x5b, 0xde, 0xbf, 0x95, 0x97, 0x30, 0xf3, 0xb4, 0x4a, 0x2d, 0x02, 0xb5, 0xf4, 0x5e, 0x1d, 0x9a ] MD = list(range(0, 1003 * nacl.crypto_hash_BYTES)) for j in range(0, 100): for i in range(0, len(seed)): MD[0 * nacl.crypto_hash_BYTES + i] = seed[i] MD[1 * nacl.crypto_hash_BYTES + i] = seed[i] MD[2 * nacl.crypto_hash_BYTES + i] = seed[i] for i in range(3, 1003): a = (i - 3) * nacl.crypto_hash_BYTES; b = (i - 0) * nacl.crypto_hash_BYTES; data = _strbytes(MD[a:b]) h = nacl.crypto_hash(data) for k in range(0, nacl.crypto_hash_BYTES): if type(h[k]) == type(''): MD[i * nacl.crypto_hash_BYTES + k] = ord(h[k]) else: MD[i * nacl.crypto_hash_BYTES + k] = h[k] for i in range(0, len(seed)): seed[i] = MD[1002 * nacl.crypto_hash_BYTES + i] MD[j * nacl.crypto_hash_BYTES + i] = MD[1002 * nacl.crypto_hash_BYTES + i] if _strbytes(seed) != fromhex(r): raise ValueError("monte-carlo test failed")
def hash_sha512_mc_test(): """ NIST SHAVS pseudorandomly generated messages (monte carlo) test """ r = "dc13a41114a59c0bedba376d1afed10fda5be9febd68e0acaa9454007c8284845213cd05945a29ac1149ab0eb6c4714998614b79d6ca00648c9aba6b2335f0b3" seed = [ 0x41, 0x15, 0x63, 0xc9, 0x97, 0x5d, 0xeb, 0x4f, 0xe8, 0x02, 0x76, 0x83, 0x0e, 0x83, 0x53, 0x04, 0x82, 0x8a, 0x5c, 0xd8, 0x7c, 0x79, 0x34, 0xa5, 0x5c, 0x45, 0xcc, 0x23, 0x49, 0x87, 0x2c, 0xd1, 0x18, 0xd0, 0x70, 0xe7, 0x6f, 0x3d, 0x10, 0x8c, 0x2a, 0x4c, 0x65, 0x4a, 0xfd, 0xee, 0x69, 0xbf, 0x5b, 0xde, 0xbf, 0x95, 0x97, 0x30, 0xf3, 0xb4, 0x4a, 0x2d, 0x02, 0xb5, 0xf4, 0x5e, 0x1d, 0x9a ] MD = list(range(0, 1003 * nacl.crypto_hash_BYTES)) for j in range(0, 100): for i in range(0, len(seed)): MD[0 * nacl.crypto_hash_BYTES + i] = seed[i] MD[1 * nacl.crypto_hash_BYTES + i] = seed[i] MD[2 * nacl.crypto_hash_BYTES + i] = seed[i] for i in range(3, 1003): a = (i - 3) * nacl.crypto_hash_BYTES b = (i - 0) * nacl.crypto_hash_BYTES data = _strbytes(MD[a:b]) h = nacl.crypto_hash(data) for k in range(0, nacl.crypto_hash_BYTES): if type(h[k]) == type(''): MD[i * nacl.crypto_hash_BYTES + k] = ord(h[k]) else: MD[i * nacl.crypto_hash_BYTES + k] = h[k] for i in range(0, len(seed)): seed[i] = MD[1002 * nacl.crypto_hash_BYTES + i] MD[j * nacl.crypto_hash_BYTES + i] = MD[1002 * nacl.crypto_hash_BYTES + i] if _strbytes(seed) != fromhex(r): raise ValueError("monte-carlo test failed")
def trigger_fiq(self): self.write(0xaa, fromhex('aa000100')) self.write(0xaa, fromhex('aa000000'))
def select_arm7(self): self.write(0x8b, fromhex('8b000100'))
def nds_stop(self): self.write(0x8a, fromhex('8a000100'))
def nds_reset(self): self.write(0x8a, fromhex('8a000000'))
def full_reset(self): self.write(0x81, fromhex('81f2'))
def slot2_emulate_eject(self): self.write(0xad, fromhex('ad0000000500000001000000000000000000000000000000')) self.write(0xad, fromhex('ad0000000500000000000000000000000000000000000000'))
def slot2_off(self): self.write(0xad, fromhex('ad0000000200000000000000000000000000000000000000'))
def slot2_on(self): self.write(0xad, fromhex('ad0000000200000001000000000000000000000000000000')) self.write(0xad, fromhex('ad0000000400000000000000000000000000000000000000'))
def slot1_off(self): self.write(0xad, fromhex('ad0000000a00000000000000000000000000000000000000'))