From f46500ce45dbce12ee4431e5becb759ac7f26098 Mon Sep 17 00:00:00 2001 From: otsmr Date: Sat, 29 Aug 2026 14:59:01 +0200 Subject: [PATCH] remove unused dependencies --- adaptive_number/LICENSE | 11 - adaptive_number/lib/adaptive_number.dart | 6 - adaptive_number/lib/src/int.dart | 120 - adaptive_number/lib/src/int64.dart | 121 - adaptive_number/lib/src/number.dart | 78 - adaptive_number/lib/src/stub.dart | 4 - adaptive_number/pubspec.yaml | 17 - ed25519_edwards/LICENSE | 201 - ed25519_edwards/lib/ed25519_edwards.dart | 204 - ed25519_edwards/lib/src/const.dart | 10162 ---------------- ed25519_edwards/lib/src/edwards25519.dart | 2127 ---- ed25519_edwards/lib/src/numbers.dart | 18 - ed25519_edwards/lib/src/util.dart | 16 - ed25519_edwards/pubspec.yaml | 18 - libsignal_protocol_dart/LICENSE | 674 - .../lib/libsignal_protocol_dart.dart | 52 - libsignal_protocol_dart/lib/src/cbc.dart | 40 - .../lib/src/decryption_callback.dart | 3 - .../device_consistency_code_generator.dart | 41 - .../device_consistency_commitment.dart | 37 - .../devices/device_consistency_signature.dart | 12 - .../lib/src/duplicate_message_exception.dart | 7 - .../lib/src/ecc/curve.dart | 187 - .../lib/src/ecc/djb_ec_private_key.dart | 18 - .../lib/src/ecc/djb_ec_public_key.dart | 44 - .../lib/src/ecc/ec_key_pair.dart | 13 - .../lib/src/ecc/ec_private_key.dart | 6 - .../lib/src/ecc/ec_public_key.dart | 8 - .../lib/src/ecc/ed25519.dart | 117 - libsignal_protocol_dart/lib/src/entry.dart | 6 - libsignal_protocol_dart/lib/src/eq.dart | 4 - .../fingerprint/displayable_fingerprint.dart | 35 - .../lib/src/fingerprint/fingerprint.dart | 12 - .../fingerprint/fingerprint_generator.dart | 20 - .../fingerprint_parsing_exception.dart | 8 - ...ingerprint_version_mismatch_exception.dart | 8 - .../numeric_fingerprint_generator.dart | 79 - .../fingerprint/scannable_fingerprint.dart | 49 - .../lib/src/groups/group_cipher.dart | 98 - .../lib/src/groups/group_session_builder.dart | 48 - .../src/groups/ratchet/sender_chain_key.dart | 31 - .../groups/ratchet/sender_message_key.dart | 24 - .../lib/src/groups/sender_key_name.dart | 28 - .../state/in_memory_sender_key_store.dart | 29 - .../src/groups/state/sender_key_record.dart | 71 - .../src/groups/state/sender_key_state.dart | 107 - .../src/groups/state/sender_key_store.dart | 9 - .../lib/src/identity_key.dart | 33 - .../lib/src/identity_key_pair.dart | 32 - .../lib/src/invalid_key_exception.dart | 7 - .../lib/src/invalid_key_id_exception.dart | 7 - .../lib/src/invalid_mac_exception.dart | 7 - .../lib/src/invalid_message_exception.dart | 7 - .../lib/src/kdf/derived_message_secrets.dart | 29 - .../lib/src/kdf/derived_root_secrets.dart | 20 - libsignal_protocol_dart/lib/src/kdf/hkdf.dart | 81 - .../lib/src/kdf/hkdfv2.dart | 6 - .../lib/src/kdf/hkdfv3.dart | 6 - .../lib/src/legacy_message_exception.dart | 7 - .../lib/src/no_session_exception.dart | 7 - .../lib/src/protocol/ciphertext_message.dart | 16 - .../protocol/device_consistency_message.dart | 71 - .../src/protocol/pre_key_signal_message.dart | 101 - ...nder_key_distribution_message_wrapper.dart | 87 - .../lib/src/protocol/sender_key_message.dart | 108 - .../lib/src/protocol/signal_message.dart | 141 - .../lib/src/provisioning_cipher.dart | 109 - .../alice_signal_protocol_parameters.dart | 25 - .../bob_signal_protocol_parameters.dart | 37 - .../lib/src/ratchet/chain_key.dart | 46 - .../lib/src/ratchet/message_keys.dart | 18 - .../lib/src/ratchet/ratcheting_session.dart | 151 - .../lib/src/ratchet/root_key.dart | 33 - .../symmetric_signal_protocol_parameters.dart | 23 - .../lib/src/session_builder.dart | 156 - .../lib/src/session_cipher.dart | 290 - .../lib/src/signal_protocol_address.dart | 26 - .../src/state/fingerprint_protocol.pb.dart | 219 - .../state/fingerprint_protocol.pbenum.dart | 5 - .../state/fingerprint_protocol.pbjson.dart | 43 - .../state/fingerprint_protocol.pbserver.dart | 7 - .../lib/src/state/identity_key_store.dart | 20 - .../impl/in_memory_identity_key_store.dart | 51 - .../state/impl/in_memory_pre_key_store.dart | 32 - .../state/impl/in_memory_session_store.dart | 63 - .../impl/in_memory_signal_protocol_store.dart | 119 - .../impl/in_memory_signed_pre_key_store.dart | 43 - .../src/state/local_storage_protocol.pb.dart | 2256 ---- .../state/local_storage_protocol.pbenum.dart | 5 - .../state/local_storage_protocol.pbjson.dart | 348 - .../local_storage_protocol.pbserver.dart | 7 - .../lib/src/state/pre_key_bundle.dart | 45 - .../lib/src/state/pre_key_record.dart | 37 - .../lib/src/state/pre_key_store.dart | 12 - .../lib/src/state/session_record.dart | 86 - .../lib/src/state/session_state.dart | 399 - .../lib/src/state/session_store.dart | 18 - .../lib/src/state/signal_protocol_store.dart | 7 - .../lib/src/state/signed_pre_key_record.dart | 45 - .../lib/src/state/signed_pre_key_store.dart | 15 - .../src/state/whisper_text_protocol.pb.dart | 938 -- .../state/whisper_text_protocol.pbenum.dart | 5 - .../state/whisper_text_protocol.pbjson.dart | 96 - .../state/whisper_text_protocol.pbserver.dart | 7 - .../lib/src/untrusted_identity_exception.dart | 8 - .../lib/src/util/byte_util.dart | 86 - .../lib/src/util/identity_key_comparator.dart | 5 - .../lib/src/util/key_helper.dart | 69 - libsignal_protocol_dart/lib/src/util/log.dart | 8 - .../lib/src/util/medium.dart | 1 - libsignal_protocol_dart/pubspec.yaml | 28 - optional/LICENSE | 19 - optional/lib/optional.dart | 10 - optional/lib/optional_internal.dart | 98 - optional/lib/src/absent.dart | 78 - optional/lib/src/extension.dart | 125 - optional/lib/src/novaluepresent.dart | 7 - optional/lib/src/present.dart | 85 - optional/pubspec.yaml | 15 - pointycastle/LICENSE | 20 - .../stream_cipher_as_block_cipher.dart | 37 - pointycastle/lib/api.dart | 53 - pointycastle/lib/asn1.dart | 60 - pointycastle/lib/asn1/asn1_encoding_rule.dart | 16 - pointycastle/lib/asn1/asn1_object.dart | 142 - pointycastle/lib/asn1/asn1_parser.dart | 163 - pointycastle/lib/asn1/asn1_tags.dart | 134 - pointycastle/lib/asn1/asn1_utils.dart | 243 - pointycastle/lib/asn1/object_identifiers.dart | 34 - .../lib/asn1/object_identifiers_database.dart | 803 -- .../lib/asn1/pkcs/pkcs1/asn1_digest_info.dart | 42 - .../pkcs10/asn1_certification_request.dart | 52 - .../asn1_certification_request_info.dart | 66 - .../pkcs10/asn1_subject_public_key_info.dart | 48 - .../pkcs/pkcs12/asn1_authenticated_safe.dart | 31 - .../lib/asn1/pkcs/pkcs12/asn1_cert_bag.dart | 88 - .../lib/asn1/pkcs/pkcs12/asn1_key_bag.dart | 19 - .../lib/asn1/pkcs/pkcs12/asn1_mac_data.dart | 47 - .../lib/asn1/pkcs/pkcs12/asn1_pfx.dart | 52 - .../pkcs/pkcs12/asn1_pkcs12_attribute.dart | 58 - .../lib/asn1/pkcs/pkcs12/asn1_safe_bag.dart | 93 - .../asn1/pkcs/pkcs12/asn1_safe_contents.dart | 40 - .../asn1/pkcs/pkcs7/asn1_content_info.dart | 65 - .../pkcs7/asn1_encrypted_content_info.dart | 67 - .../asn1/pkcs/pkcs8/asn1_encrypted_data.dart | 38 - .../asn1_encrypted_private_key_info.dart | 3 - .../pkcs/pkcs8/asn1_private_key_info.dart | 108 - .../lib/asn1/primitives/asn1_bit_string.dart | 166 - .../lib/asn1/primitives/asn1_bmp_string.dart | 143 - .../lib/asn1/primitives/asn1_boolean.dart | 68 - .../lib/asn1/primitives/asn1_enumerated.dart | 18 - .../primitives/asn1_generalized_time.dart | 79 - .../lib/asn1/primitives/asn1_ia5_string.dart | 130 - .../lib/asn1/primitives/asn1_integer.dart | 72 - .../lib/asn1/primitives/asn1_null.dart | 53 - .../primitives/asn1_object_identifier.dart | 189 - .../asn1/primitives/asn1_octet_string.dart | 133 - .../primitives/asn1_printable_string.dart | 130 - .../lib/asn1/primitives/asn1_sequence.dart | 94 - .../lib/asn1/primitives/asn1_set.dart | 94 - .../asn1/primitives/asn1_teletext_string.dart | 130 - .../lib/asn1/primitives/asn1_utc_time.dart | 94 - .../lib/asn1/primitives/asn1_utf8_string.dart | 130 - ...upported_asn1_encoding_rule_exception.dart | 14 - .../asn1/unsupported_asn1_tag_exception.dart | 12 - ...supported_object_identifier_exception.dart | 12 - .../x501/asn1_attribute_type_and_value.dart | 59 - pointycastle/lib/asn1/x501/asn1_name.dart | 26 - pointycastle/lib/asn1/x501/asn1_rdn.dart | 21 - .../asn1/x509/asn1_algorithm_identifier.dart | 49 - pointycastle/lib/asymmetric/api.dart | 158 - pointycastle/lib/asymmetric/ec_elgamal.dart | 80 - pointycastle/lib/asymmetric/oaep.dart | 527 - pointycastle/lib/asymmetric/pkcs1.dart | 173 - pointycastle/lib/asymmetric/rsa.dart | 163 - pointycastle/lib/block/aes.dart | 1551 --- pointycastle/lib/block/aes_fast.dart | 3000 ----- pointycastle/lib/block/blowfish.dart | 466 - pointycastle/lib/block/camellia.dart | 698 -- pointycastle/lib/block/des_base.dart | 860 -- pointycastle/lib/block/desede_engine.dart | 108 - pointycastle/lib/block/modes/cbc.dart | 113 - pointycastle/lib/block/modes/ccm.dart | 344 - pointycastle/lib/block/modes/cfb.dart | 175 - pointycastle/lib/block/modes/ctr.dart | 22 - pointycastle/lib/block/modes/ecb.dart | 43 - pointycastle/lib/block/modes/gcm.dart | 226 - pointycastle/lib/block/modes/gctr.dart | 144 - pointycastle/lib/block/modes/ige.dart | 117 - pointycastle/lib/block/modes/ofb.dart | 104 - pointycastle/lib/block/modes/sic.dart | 23 - pointycastle/lib/block/rc2_engine.dart | 498 - pointycastle/lib/block/twofish.dart | 694 -- pointycastle/lib/digests/blake2b.dart | 306 - pointycastle/lib/digests/cshake.dart | 114 - pointycastle/lib/digests/keccak.dart | 49 - pointycastle/lib/digests/md2.dart | 397 - pointycastle/lib/digests/md4.dart | 128 - pointycastle/lib/digests/md5.dart | 153 - pointycastle/lib/digests/ripemd128.dart | 232 - pointycastle/lib/digests/ripemd160.dart | 415 - pointycastle/lib/digests/ripemd256.dart | 256 - pointycastle/lib/digests/ripemd320.dart | 456 - pointycastle/lib/digests/sha1.dart | 145 - pointycastle/lib/digests/sha224.dart | 203 - pointycastle/lib/digests/sha256.dart | 203 - pointycastle/lib/digests/sha3.dart | 50 - pointycastle/lib/digests/sha384.dart | 57 - pointycastle/lib/digests/sha512.dart | 59 - pointycastle/lib/digests/sha512t.dart | 157 - pointycastle/lib/digests/shake.dart | 92 - pointycastle/lib/digests/sm3.dart | 130 - pointycastle/lib/digests/tiger.dart | 1321 -- pointycastle/lib/digests/whirlpool.dart | 2297 ---- pointycastle/lib/digests/xof_utils.dart | 37 - pointycastle/lib/ecc/api.dart | 236 - .../lib/ecc/curves/brainpoolp160r1.dart | 33 - .../lib/ecc/curves/brainpoolp160t1.dart | 33 - .../lib/ecc/curves/brainpoolp192r1.dart | 37 - .../lib/ecc/curves/brainpoolp192t1.dart | 37 - .../lib/ecc/curves/brainpoolp224r1.dart | 41 - .../lib/ecc/curves/brainpoolp224t1.dart | 41 - .../lib/ecc/curves/brainpoolp256r1.dart | 41 - .../lib/ecc/curves/brainpoolp256t1.dart | 41 - .../lib/ecc/curves/brainpoolp320r1.dart | 41 - .../lib/ecc/curves/brainpoolp320t1.dart | 41 - .../lib/ecc/curves/brainpoolp384r1.dart | 41 - .../lib/ecc/curves/brainpoolp384t1.dart | 41 - .../lib/ecc/curves/brainpoolp512r1.dart | 41 - .../lib/ecc/curves/brainpoolp512t1.dart | 41 - .../curves/gostr3410_2001_cryptopro_a.dart | 42 - .../curves/gostr3410_2001_cryptopro_b.dart | 44 - .../curves/gostr3410_2001_cryptopro_c.dart | 42 - .../curves/gostr3410_2001_cryptopro_xcha.dart | 43 - .../curves/gostr3410_2001_cryptopro_xchb.dart | 43 - pointycastle/lib/ecc/curves/prime192v1.dart | 37 - pointycastle/lib/ecc/curves/prime192v2.dart | 37 - pointycastle/lib/ecc/curves/prime192v3.dart | 37 - pointycastle/lib/ecc/curves/prime239v1.dart | 42 - pointycastle/lib/ecc/curves/prime239v2.dart | 42 - pointycastle/lib/ecc/curves/prime239v3.dart | 42 - pointycastle/lib/ecc/curves/prime256v1.dart | 41 - pointycastle/lib/ecc/curves/secp112r1.dart | 34 - pointycastle/lib/ecc/curves/secp112r2.dart | 34 - pointycastle/lib/ecc/curves/secp128r1.dart | 34 - pointycastle/lib/ecc/curves/secp128r2.dart | 34 - pointycastle/lib/ecc/curves/secp160k1.dart | 33 - pointycastle/lib/ecc/curves/secp160r1.dart | 34 - pointycastle/lib/ecc/curves/secp160r2.dart | 34 - pointycastle/lib/ecc/curves/secp192k1.dart | 35 - pointycastle/lib/ecc/curves/secp192r1.dart | 38 - pointycastle/lib/ecc/curves/secp224k1.dart | 37 - pointycastle/lib/ecc/curves/secp224r1.dart | 42 - pointycastle/lib/ecc/curves/secp256k1.dart | 37 - pointycastle/lib/ecc/curves/secp256r1.dart | 41 - pointycastle/lib/ecc/curves/secp384r1.dart | 41 - pointycastle/lib/ecc/curves/secp521r1.dart | 41 - pointycastle/lib/ecc/ecc_base.dart | 280 - pointycastle/lib/ecc/ecc_fp.dart | 587 - pointycastle/lib/ecc/ecdh.dart | 70 - pointycastle/lib/export.dart | 154 - pointycastle/lib/impl.dart | 13 - pointycastle/lib/key_derivators/api.dart | 126 - pointycastle/lib/key_derivators/argon2.dart | 2 - .../argon2_native_int_impl.dart | 658 - .../argon2_register64_impl.dart | 695 -- .../lib/key_derivators/concat_kdf.dart | 62 - pointycastle/lib/key_derivators/ecdh_kdf.dart | 37 - pointycastle/lib/key_derivators/hkdf.dart | 185 - pointycastle/lib/key_derivators/pbkdf2.dart | 102 - .../pkcs12_parameter_generator.dart | 148 - .../pkcs5s1_parameter_generator.dart | 75 - pointycastle/lib/key_derivators/scrypt.dart | 207 - pointycastle/lib/key_generators/api.dart | 27 - .../lib/key_generators/ec_key_generator.dart | 50 - .../lib/key_generators/rsa_key_generator.dart | 339 - .../lib/macs/cbc_block_cipher_mac.dart | 214 - pointycastle/lib/macs/cmac.dart | 287 - pointycastle/lib/macs/hmac.dart | 120 - pointycastle/lib/macs/poly1305.dart | 323 - .../padded_block_cipher_impl.dart | 121 - pointycastle/lib/paddings/iso7816d4.dart | 57 - pointycastle/lib/paddings/pkcs7.dart | 53 - pointycastle/lib/pointycastle.dart | 15 - .../random/auto_seed_block_ctr_random.dart | 105 - pointycastle/lib/random/block_ctr_random.dart | 69 - pointycastle/lib/random/fortuna_random.dart | 59 - pointycastle/lib/signers/ecdsa_signer.dart | 402 - pointycastle/lib/signers/pss_signer.dart | 269 - pointycastle/lib/signers/rsa_signer.dart | 197 - .../lib/src/api/aead_block_cipher.dart | 26 - pointycastle/lib/src/api/aead_cipher.dart | 30 - pointycastle/lib/src/api/aead_parameters.dart | 17 - pointycastle/lib/src/api/algorithm.dart | 9 - .../lib/src/api/asymmetric_block_cipher.dart | 35 - pointycastle/lib/src/api/asymmetric_key.dart | 6 - .../lib/src/api/asymmetric_key_pair.dart | 22 - .../lib/src/api/asymmetric_key_parameter.dart | 11 - pointycastle/lib/src/api/block_cipher.dart | 39 - .../lib/src/api/cipher_parameters.dart | 6 - pointycastle/lib/src/api/des_parameters.dart | 7 - .../lib/src/api/desede_parameters.dart | 7 - pointycastle/lib/src/api/digest.dart | 34 - pointycastle/lib/src/api/key_derivator.dart | 25 - pointycastle/lib/src/api/key_generator.dart | 19 - .../lib/src/api/key_generator_parameters.dart | 10 - pointycastle/lib/src/api/key_parameter.dart | 15 - pointycastle/lib/src/api/mac.dart | 35 - .../lib/src/api/padded_block_cipher.dart | 48 - .../api/padded_block_cipher_parameters.dart | 16 - pointycastle/lib/src/api/padding.dart | 32 - .../lib/src/api/parameters_with_iv.dart | 13 - .../lib/src/api/parameters_with_random.dart | 14 - .../lib/src/api/parameters_with_salt.dart | 13 - .../parameters_with_salt_configuration.dart | 15 - .../lib/src/api/pbe_parameters_generator.dart | 23 - pointycastle/lib/src/api/private_key.dart | 6 - .../lib/src/api/private_key_parameter.dart | 9 - pointycastle/lib/src/api/public_key.dart | 6 - .../lib/src/api/public_key_parameter.dart | 9 - pointycastle/lib/src/api/rc2_parameters.dart | 13 - .../src/api/registry_factory_exception.dart | 24 - pointycastle/lib/src/api/secure_random.dart | 34 - pointycastle/lib/src/api/signature.dart | 6 - pointycastle/lib/src/api/signer.dart | 25 - pointycastle/lib/src/api/srp_client.dart | 35 - pointycastle/lib/src/api/srp_server.dart | 37 - pointycastle/lib/src/api/stream_cipher.dart | 32 - pointycastle/lib/src/api/xof.dart | 11 - pointycastle/lib/src/ct.dart | 16 - .../src/ec_standard_curve_constructor.dart | 20 - .../lib/src/impl/base_aead_block_cipher.dart | 223 - .../lib/src/impl/base_aead_cipher.dart | 11 - .../impl/base_asymmetric_block_cipher.dart | 15 - .../lib/src/impl/base_block_cipher.dart | 15 - pointycastle/lib/src/impl/base_digest.dart | 16 - .../lib/src/impl/base_key_derivator.dart | 15 - pointycastle/lib/src/impl/base_mac.dart | 16 - pointycastle/lib/src/impl/base_padding.dart | 19 - .../lib/src/impl/base_stream_cipher.dart | 15 - pointycastle/lib/src/impl/entropy.dart | 7 - pointycastle/lib/src/impl/keccak_engine.dart | 396 - .../lib/src/impl/long_sha2_family_digest.dart | 443 - .../lib/src/impl/md4_family_digest.dart | 190 - .../lib/src/impl/secure_random_base.dart | 60 - .../lib/src/platform_check/abstract.dart | 36 - .../lib/src/platform_check/native.dart | 45 - .../lib/src/platform_check/node_crypto.dart | 17 - .../src/platform_check/platform_check.dart | 37 - pointycastle/lib/src/platform_check/web.dart | 65 - pointycastle/lib/src/registration.dart | 44 - .../lib/src/registry/registration.dart | 171 - pointycastle/lib/src/registry/registry.dart | 165 - pointycastle/lib/src/ufixnum.dart | 562 - pointycastle/lib/src/utils.dart | 336 - pointycastle/lib/srp/srp6_client.dart | 104 - pointycastle/lib/srp/srp6_server.dart | 101 - .../lib/srp/srp6_standard_groups.dart | 176 - pointycastle/lib/srp/srp6_util.dart | 167 - .../lib/srp/srp6_verifier_generator.dart | 32 - pointycastle/lib/stream/chacha20.dart | 314 - pointycastle/lib/stream/chacha20poly1305.dart | 503 - pointycastle/lib/stream/chacha7539.dart | 315 - pointycastle/lib/stream/ctr.dart | 23 - pointycastle/lib/stream/eax.dart | 311 - pointycastle/lib/stream/rc4_engine.dart | 114 - pointycastle/lib/stream/salsa20.dart | 195 - pointycastle/lib/stream/sic.dart | 99 - pointycastle/pubspec.yaml | 21 - x25519/LICENSE | 201 - x25519/lib/src/curve25519.dart | 944 -- x25519/lib/src/numbers.dart | 11 - x25519/lib/x25519.dart | 180 - x25519/pubspec.yaml | 17 - 374 files changed, 59859 deletions(-) delete mode 100644 adaptive_number/LICENSE delete mode 100644 adaptive_number/lib/adaptive_number.dart delete mode 100644 adaptive_number/lib/src/int.dart delete mode 100644 adaptive_number/lib/src/int64.dart delete mode 100644 adaptive_number/lib/src/number.dart delete mode 100644 adaptive_number/lib/src/stub.dart delete mode 100644 adaptive_number/pubspec.yaml delete mode 100644 ed25519_edwards/LICENSE delete mode 100644 ed25519_edwards/lib/ed25519_edwards.dart delete mode 100644 ed25519_edwards/lib/src/const.dart delete mode 100644 ed25519_edwards/lib/src/edwards25519.dart delete mode 100644 ed25519_edwards/lib/src/numbers.dart delete mode 100644 ed25519_edwards/lib/src/util.dart delete mode 100644 ed25519_edwards/pubspec.yaml delete mode 100644 libsignal_protocol_dart/LICENSE delete mode 100644 libsignal_protocol_dart/lib/libsignal_protocol_dart.dart delete mode 100644 libsignal_protocol_dart/lib/src/cbc.dart delete mode 100644 libsignal_protocol_dart/lib/src/decryption_callback.dart delete mode 100644 libsignal_protocol_dart/lib/src/devices/device_consistency_code_generator.dart delete mode 100644 libsignal_protocol_dart/lib/src/devices/device_consistency_commitment.dart delete mode 100644 libsignal_protocol_dart/lib/src/devices/device_consistency_signature.dart delete mode 100644 libsignal_protocol_dart/lib/src/duplicate_message_exception.dart delete mode 100644 libsignal_protocol_dart/lib/src/ecc/curve.dart delete mode 100644 libsignal_protocol_dart/lib/src/ecc/djb_ec_private_key.dart delete mode 100644 libsignal_protocol_dart/lib/src/ecc/djb_ec_public_key.dart delete mode 100644 libsignal_protocol_dart/lib/src/ecc/ec_key_pair.dart delete mode 100644 libsignal_protocol_dart/lib/src/ecc/ec_private_key.dart delete mode 100644 libsignal_protocol_dart/lib/src/ecc/ec_public_key.dart delete mode 100644 libsignal_protocol_dart/lib/src/ecc/ed25519.dart delete mode 100644 libsignal_protocol_dart/lib/src/entry.dart delete mode 100644 libsignal_protocol_dart/lib/src/eq.dart delete mode 100644 libsignal_protocol_dart/lib/src/fingerprint/displayable_fingerprint.dart delete mode 100644 libsignal_protocol_dart/lib/src/fingerprint/fingerprint.dart delete mode 100644 libsignal_protocol_dart/lib/src/fingerprint/fingerprint_generator.dart delete mode 100644 libsignal_protocol_dart/lib/src/fingerprint/fingerprint_parsing_exception.dart delete mode 100644 libsignal_protocol_dart/lib/src/fingerprint/fingerprint_version_mismatch_exception.dart delete mode 100644 libsignal_protocol_dart/lib/src/fingerprint/numeric_fingerprint_generator.dart delete mode 100644 libsignal_protocol_dart/lib/src/fingerprint/scannable_fingerprint.dart delete mode 100644 libsignal_protocol_dart/lib/src/groups/group_cipher.dart delete mode 100644 libsignal_protocol_dart/lib/src/groups/group_session_builder.dart delete mode 100644 libsignal_protocol_dart/lib/src/groups/ratchet/sender_chain_key.dart delete mode 100644 libsignal_protocol_dart/lib/src/groups/ratchet/sender_message_key.dart delete mode 100644 libsignal_protocol_dart/lib/src/groups/sender_key_name.dart delete mode 100644 libsignal_protocol_dart/lib/src/groups/state/in_memory_sender_key_store.dart delete mode 100644 libsignal_protocol_dart/lib/src/groups/state/sender_key_record.dart delete mode 100644 libsignal_protocol_dart/lib/src/groups/state/sender_key_state.dart delete mode 100644 libsignal_protocol_dart/lib/src/groups/state/sender_key_store.dart delete mode 100644 libsignal_protocol_dart/lib/src/identity_key.dart delete mode 100644 libsignal_protocol_dart/lib/src/identity_key_pair.dart delete mode 100644 libsignal_protocol_dart/lib/src/invalid_key_exception.dart delete mode 100644 libsignal_protocol_dart/lib/src/invalid_key_id_exception.dart delete mode 100644 libsignal_protocol_dart/lib/src/invalid_mac_exception.dart delete mode 100644 libsignal_protocol_dart/lib/src/invalid_message_exception.dart delete mode 100644 libsignal_protocol_dart/lib/src/kdf/derived_message_secrets.dart delete mode 100644 libsignal_protocol_dart/lib/src/kdf/derived_root_secrets.dart delete mode 100644 libsignal_protocol_dart/lib/src/kdf/hkdf.dart delete mode 100644 libsignal_protocol_dart/lib/src/kdf/hkdfv2.dart delete mode 100644 libsignal_protocol_dart/lib/src/kdf/hkdfv3.dart delete mode 100644 libsignal_protocol_dart/lib/src/legacy_message_exception.dart delete mode 100644 libsignal_protocol_dart/lib/src/no_session_exception.dart delete mode 100644 libsignal_protocol_dart/lib/src/protocol/ciphertext_message.dart delete mode 100644 libsignal_protocol_dart/lib/src/protocol/device_consistency_message.dart delete mode 100644 libsignal_protocol_dart/lib/src/protocol/pre_key_signal_message.dart delete mode 100644 libsignal_protocol_dart/lib/src/protocol/sender_key_distribution_message_wrapper.dart delete mode 100644 libsignal_protocol_dart/lib/src/protocol/sender_key_message.dart delete mode 100644 libsignal_protocol_dart/lib/src/protocol/signal_message.dart delete mode 100644 libsignal_protocol_dart/lib/src/provisioning_cipher.dart delete mode 100644 libsignal_protocol_dart/lib/src/ratchet/alice_signal_protocol_parameters.dart delete mode 100644 libsignal_protocol_dart/lib/src/ratchet/bob_signal_protocol_parameters.dart delete mode 100644 libsignal_protocol_dart/lib/src/ratchet/chain_key.dart delete mode 100644 libsignal_protocol_dart/lib/src/ratchet/message_keys.dart delete mode 100644 libsignal_protocol_dart/lib/src/ratchet/ratcheting_session.dart delete mode 100644 libsignal_protocol_dart/lib/src/ratchet/root_key.dart delete mode 100644 libsignal_protocol_dart/lib/src/ratchet/symmetric_signal_protocol_parameters.dart delete mode 100644 libsignal_protocol_dart/lib/src/session_builder.dart delete mode 100644 libsignal_protocol_dart/lib/src/session_cipher.dart delete mode 100644 libsignal_protocol_dart/lib/src/signal_protocol_address.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pb.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pbenum.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pbjson.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pbserver.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/identity_key_store.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/impl/in_memory_identity_key_store.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/impl/in_memory_pre_key_store.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/impl/in_memory_session_store.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/impl/in_memory_signal_protocol_store.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/impl/in_memory_signed_pre_key_store.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/local_storage_protocol.pb.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/local_storage_protocol.pbenum.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/local_storage_protocol.pbjson.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/local_storage_protocol.pbserver.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/pre_key_bundle.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/pre_key_record.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/pre_key_store.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/session_record.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/session_state.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/session_store.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/signal_protocol_store.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/signed_pre_key_record.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/signed_pre_key_store.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pb.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pbenum.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pbjson.dart delete mode 100644 libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pbserver.dart delete mode 100644 libsignal_protocol_dart/lib/src/untrusted_identity_exception.dart delete mode 100644 libsignal_protocol_dart/lib/src/util/byte_util.dart delete mode 100644 libsignal_protocol_dart/lib/src/util/identity_key_comparator.dart delete mode 100644 libsignal_protocol_dart/lib/src/util/key_helper.dart delete mode 100644 libsignal_protocol_dart/lib/src/util/log.dart delete mode 100644 libsignal_protocol_dart/lib/src/util/medium.dart delete mode 100644 libsignal_protocol_dart/pubspec.yaml delete mode 100644 optional/LICENSE delete mode 100644 optional/lib/optional.dart delete mode 100644 optional/lib/optional_internal.dart delete mode 100644 optional/lib/src/absent.dart delete mode 100644 optional/lib/src/extension.dart delete mode 100644 optional/lib/src/novaluepresent.dart delete mode 100644 optional/lib/src/present.dart delete mode 100644 optional/pubspec.yaml delete mode 100644 pointycastle/LICENSE delete mode 100644 pointycastle/lib/adapters/stream_cipher_as_block_cipher.dart delete mode 100644 pointycastle/lib/api.dart delete mode 100644 pointycastle/lib/asn1.dart delete mode 100644 pointycastle/lib/asn1/asn1_encoding_rule.dart delete mode 100644 pointycastle/lib/asn1/asn1_object.dart delete mode 100644 pointycastle/lib/asn1/asn1_parser.dart delete mode 100644 pointycastle/lib/asn1/asn1_tags.dart delete mode 100644 pointycastle/lib/asn1/asn1_utils.dart delete mode 100644 pointycastle/lib/asn1/object_identifiers.dart delete mode 100644 pointycastle/lib/asn1/object_identifiers_database.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs1/asn1_digest_info.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs10/asn1_certification_request.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs10/asn1_certification_request_info.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs10/asn1_subject_public_key_info.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs12/asn1_authenticated_safe.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs12/asn1_cert_bag.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs12/asn1_key_bag.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs12/asn1_mac_data.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs12/asn1_pfx.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs12/asn1_pkcs12_attribute.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs12/asn1_safe_bag.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs12/asn1_safe_contents.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs7/asn1_content_info.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs7/asn1_encrypted_content_info.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs8/asn1_encrypted_data.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs8/asn1_encrypted_private_key_info.dart delete mode 100644 pointycastle/lib/asn1/pkcs/pkcs8/asn1_private_key_info.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_bit_string.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_bmp_string.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_boolean.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_enumerated.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_generalized_time.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_ia5_string.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_integer.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_null.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_object_identifier.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_octet_string.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_printable_string.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_sequence.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_set.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_teletext_string.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_utc_time.dart delete mode 100644 pointycastle/lib/asn1/primitives/asn1_utf8_string.dart delete mode 100644 pointycastle/lib/asn1/unsupported_asn1_encoding_rule_exception.dart delete mode 100644 pointycastle/lib/asn1/unsupported_asn1_tag_exception.dart delete mode 100644 pointycastle/lib/asn1/unsupported_object_identifier_exception.dart delete mode 100644 pointycastle/lib/asn1/x501/asn1_attribute_type_and_value.dart delete mode 100644 pointycastle/lib/asn1/x501/asn1_name.dart delete mode 100644 pointycastle/lib/asn1/x501/asn1_rdn.dart delete mode 100644 pointycastle/lib/asn1/x509/asn1_algorithm_identifier.dart delete mode 100644 pointycastle/lib/asymmetric/api.dart delete mode 100644 pointycastle/lib/asymmetric/ec_elgamal.dart delete mode 100644 pointycastle/lib/asymmetric/oaep.dart delete mode 100644 pointycastle/lib/asymmetric/pkcs1.dart delete mode 100644 pointycastle/lib/asymmetric/rsa.dart delete mode 100644 pointycastle/lib/block/aes.dart delete mode 100644 pointycastle/lib/block/aes_fast.dart delete mode 100644 pointycastle/lib/block/blowfish.dart delete mode 100644 pointycastle/lib/block/camellia.dart delete mode 100644 pointycastle/lib/block/des_base.dart delete mode 100644 pointycastle/lib/block/desede_engine.dart delete mode 100644 pointycastle/lib/block/modes/cbc.dart delete mode 100644 pointycastle/lib/block/modes/ccm.dart delete mode 100644 pointycastle/lib/block/modes/cfb.dart delete mode 100644 pointycastle/lib/block/modes/ctr.dart delete mode 100644 pointycastle/lib/block/modes/ecb.dart delete mode 100644 pointycastle/lib/block/modes/gcm.dart delete mode 100644 pointycastle/lib/block/modes/gctr.dart delete mode 100644 pointycastle/lib/block/modes/ige.dart delete mode 100644 pointycastle/lib/block/modes/ofb.dart delete mode 100644 pointycastle/lib/block/modes/sic.dart delete mode 100644 pointycastle/lib/block/rc2_engine.dart delete mode 100644 pointycastle/lib/block/twofish.dart delete mode 100644 pointycastle/lib/digests/blake2b.dart delete mode 100644 pointycastle/lib/digests/cshake.dart delete mode 100644 pointycastle/lib/digests/keccak.dart delete mode 100644 pointycastle/lib/digests/md2.dart delete mode 100644 pointycastle/lib/digests/md4.dart delete mode 100644 pointycastle/lib/digests/md5.dart delete mode 100644 pointycastle/lib/digests/ripemd128.dart delete mode 100644 pointycastle/lib/digests/ripemd160.dart delete mode 100644 pointycastle/lib/digests/ripemd256.dart delete mode 100644 pointycastle/lib/digests/ripemd320.dart delete mode 100644 pointycastle/lib/digests/sha1.dart delete mode 100644 pointycastle/lib/digests/sha224.dart delete mode 100644 pointycastle/lib/digests/sha256.dart delete mode 100644 pointycastle/lib/digests/sha3.dart delete mode 100644 pointycastle/lib/digests/sha384.dart delete mode 100644 pointycastle/lib/digests/sha512.dart delete mode 100644 pointycastle/lib/digests/sha512t.dart delete mode 100644 pointycastle/lib/digests/shake.dart delete mode 100644 pointycastle/lib/digests/sm3.dart delete mode 100644 pointycastle/lib/digests/tiger.dart delete mode 100644 pointycastle/lib/digests/whirlpool.dart delete mode 100644 pointycastle/lib/digests/xof_utils.dart delete mode 100644 pointycastle/lib/ecc/api.dart delete mode 100644 pointycastle/lib/ecc/curves/brainpoolp160r1.dart delete mode 100644 pointycastle/lib/ecc/curves/brainpoolp160t1.dart delete mode 100644 pointycastle/lib/ecc/curves/brainpoolp192r1.dart delete mode 100644 pointycastle/lib/ecc/curves/brainpoolp192t1.dart delete mode 100644 pointycastle/lib/ecc/curves/brainpoolp224r1.dart delete mode 100644 pointycastle/lib/ecc/curves/brainpoolp224t1.dart delete mode 100644 pointycastle/lib/ecc/curves/brainpoolp256r1.dart delete mode 100644 pointycastle/lib/ecc/curves/brainpoolp256t1.dart delete mode 100644 pointycastle/lib/ecc/curves/brainpoolp320r1.dart delete mode 100644 pointycastle/lib/ecc/curves/brainpoolp320t1.dart delete mode 100644 pointycastle/lib/ecc/curves/brainpoolp384r1.dart delete mode 100644 pointycastle/lib/ecc/curves/brainpoolp384t1.dart delete mode 100644 pointycastle/lib/ecc/curves/brainpoolp512r1.dart delete mode 100644 pointycastle/lib/ecc/curves/brainpoolp512t1.dart delete mode 100644 pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_a.dart delete mode 100644 pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_b.dart delete mode 100644 pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_c.dart delete mode 100644 pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_xcha.dart delete mode 100644 pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_xchb.dart delete mode 100644 pointycastle/lib/ecc/curves/prime192v1.dart delete mode 100644 pointycastle/lib/ecc/curves/prime192v2.dart delete mode 100644 pointycastle/lib/ecc/curves/prime192v3.dart delete mode 100644 pointycastle/lib/ecc/curves/prime239v1.dart delete mode 100644 pointycastle/lib/ecc/curves/prime239v2.dart delete mode 100644 pointycastle/lib/ecc/curves/prime239v3.dart delete mode 100644 pointycastle/lib/ecc/curves/prime256v1.dart delete mode 100644 pointycastle/lib/ecc/curves/secp112r1.dart delete mode 100644 pointycastle/lib/ecc/curves/secp112r2.dart delete mode 100644 pointycastle/lib/ecc/curves/secp128r1.dart delete mode 100644 pointycastle/lib/ecc/curves/secp128r2.dart delete mode 100644 pointycastle/lib/ecc/curves/secp160k1.dart delete mode 100644 pointycastle/lib/ecc/curves/secp160r1.dart delete mode 100644 pointycastle/lib/ecc/curves/secp160r2.dart delete mode 100644 pointycastle/lib/ecc/curves/secp192k1.dart delete mode 100644 pointycastle/lib/ecc/curves/secp192r1.dart delete mode 100644 pointycastle/lib/ecc/curves/secp224k1.dart delete mode 100644 pointycastle/lib/ecc/curves/secp224r1.dart delete mode 100644 pointycastle/lib/ecc/curves/secp256k1.dart delete mode 100644 pointycastle/lib/ecc/curves/secp256r1.dart delete mode 100644 pointycastle/lib/ecc/curves/secp384r1.dart delete mode 100644 pointycastle/lib/ecc/curves/secp521r1.dart delete mode 100644 pointycastle/lib/ecc/ecc_base.dart delete mode 100644 pointycastle/lib/ecc/ecc_fp.dart delete mode 100644 pointycastle/lib/ecc/ecdh.dart delete mode 100644 pointycastle/lib/export.dart delete mode 100644 pointycastle/lib/impl.dart delete mode 100644 pointycastle/lib/key_derivators/api.dart delete mode 100644 pointycastle/lib/key_derivators/argon2.dart delete mode 100644 pointycastle/lib/key_derivators/argon2_native_int_impl.dart delete mode 100644 pointycastle/lib/key_derivators/argon2_register64_impl.dart delete mode 100644 pointycastle/lib/key_derivators/concat_kdf.dart delete mode 100644 pointycastle/lib/key_derivators/ecdh_kdf.dart delete mode 100644 pointycastle/lib/key_derivators/hkdf.dart delete mode 100644 pointycastle/lib/key_derivators/pbkdf2.dart delete mode 100644 pointycastle/lib/key_derivators/pkcs12_parameter_generator.dart delete mode 100644 pointycastle/lib/key_derivators/pkcs5s1_parameter_generator.dart delete mode 100644 pointycastle/lib/key_derivators/scrypt.dart delete mode 100644 pointycastle/lib/key_generators/api.dart delete mode 100644 pointycastle/lib/key_generators/ec_key_generator.dart delete mode 100644 pointycastle/lib/key_generators/rsa_key_generator.dart delete mode 100644 pointycastle/lib/macs/cbc_block_cipher_mac.dart delete mode 100644 pointycastle/lib/macs/cmac.dart delete mode 100644 pointycastle/lib/macs/hmac.dart delete mode 100644 pointycastle/lib/macs/poly1305.dart delete mode 100644 pointycastle/lib/padded_block_cipher/padded_block_cipher_impl.dart delete mode 100644 pointycastle/lib/paddings/iso7816d4.dart delete mode 100644 pointycastle/lib/paddings/pkcs7.dart delete mode 100644 pointycastle/lib/pointycastle.dart delete mode 100644 pointycastle/lib/random/auto_seed_block_ctr_random.dart delete mode 100644 pointycastle/lib/random/block_ctr_random.dart delete mode 100644 pointycastle/lib/random/fortuna_random.dart delete mode 100644 pointycastle/lib/signers/ecdsa_signer.dart delete mode 100644 pointycastle/lib/signers/pss_signer.dart delete mode 100644 pointycastle/lib/signers/rsa_signer.dart delete mode 100644 pointycastle/lib/src/api/aead_block_cipher.dart delete mode 100644 pointycastle/lib/src/api/aead_cipher.dart delete mode 100644 pointycastle/lib/src/api/aead_parameters.dart delete mode 100644 pointycastle/lib/src/api/algorithm.dart delete mode 100644 pointycastle/lib/src/api/asymmetric_block_cipher.dart delete mode 100644 pointycastle/lib/src/api/asymmetric_key.dart delete mode 100644 pointycastle/lib/src/api/asymmetric_key_pair.dart delete mode 100644 pointycastle/lib/src/api/asymmetric_key_parameter.dart delete mode 100644 pointycastle/lib/src/api/block_cipher.dart delete mode 100644 pointycastle/lib/src/api/cipher_parameters.dart delete mode 100644 pointycastle/lib/src/api/des_parameters.dart delete mode 100644 pointycastle/lib/src/api/desede_parameters.dart delete mode 100644 pointycastle/lib/src/api/digest.dart delete mode 100644 pointycastle/lib/src/api/key_derivator.dart delete mode 100644 pointycastle/lib/src/api/key_generator.dart delete mode 100644 pointycastle/lib/src/api/key_generator_parameters.dart delete mode 100644 pointycastle/lib/src/api/key_parameter.dart delete mode 100644 pointycastle/lib/src/api/mac.dart delete mode 100644 pointycastle/lib/src/api/padded_block_cipher.dart delete mode 100644 pointycastle/lib/src/api/padded_block_cipher_parameters.dart delete mode 100644 pointycastle/lib/src/api/padding.dart delete mode 100644 pointycastle/lib/src/api/parameters_with_iv.dart delete mode 100644 pointycastle/lib/src/api/parameters_with_random.dart delete mode 100644 pointycastle/lib/src/api/parameters_with_salt.dart delete mode 100644 pointycastle/lib/src/api/parameters_with_salt_configuration.dart delete mode 100644 pointycastle/lib/src/api/pbe_parameters_generator.dart delete mode 100644 pointycastle/lib/src/api/private_key.dart delete mode 100644 pointycastle/lib/src/api/private_key_parameter.dart delete mode 100644 pointycastle/lib/src/api/public_key.dart delete mode 100644 pointycastle/lib/src/api/public_key_parameter.dart delete mode 100644 pointycastle/lib/src/api/rc2_parameters.dart delete mode 100644 pointycastle/lib/src/api/registry_factory_exception.dart delete mode 100644 pointycastle/lib/src/api/secure_random.dart delete mode 100644 pointycastle/lib/src/api/signature.dart delete mode 100644 pointycastle/lib/src/api/signer.dart delete mode 100644 pointycastle/lib/src/api/srp_client.dart delete mode 100644 pointycastle/lib/src/api/srp_server.dart delete mode 100644 pointycastle/lib/src/api/stream_cipher.dart delete mode 100644 pointycastle/lib/src/api/xof.dart delete mode 100644 pointycastle/lib/src/ct.dart delete mode 100644 pointycastle/lib/src/ec_standard_curve_constructor.dart delete mode 100644 pointycastle/lib/src/impl/base_aead_block_cipher.dart delete mode 100644 pointycastle/lib/src/impl/base_aead_cipher.dart delete mode 100644 pointycastle/lib/src/impl/base_asymmetric_block_cipher.dart delete mode 100644 pointycastle/lib/src/impl/base_block_cipher.dart delete mode 100644 pointycastle/lib/src/impl/base_digest.dart delete mode 100644 pointycastle/lib/src/impl/base_key_derivator.dart delete mode 100644 pointycastle/lib/src/impl/base_mac.dart delete mode 100644 pointycastle/lib/src/impl/base_padding.dart delete mode 100644 pointycastle/lib/src/impl/base_stream_cipher.dart delete mode 100644 pointycastle/lib/src/impl/entropy.dart delete mode 100644 pointycastle/lib/src/impl/keccak_engine.dart delete mode 100644 pointycastle/lib/src/impl/long_sha2_family_digest.dart delete mode 100644 pointycastle/lib/src/impl/md4_family_digest.dart delete mode 100644 pointycastle/lib/src/impl/secure_random_base.dart delete mode 100644 pointycastle/lib/src/platform_check/abstract.dart delete mode 100644 pointycastle/lib/src/platform_check/native.dart delete mode 100644 pointycastle/lib/src/platform_check/node_crypto.dart delete mode 100644 pointycastle/lib/src/platform_check/platform_check.dart delete mode 100644 pointycastle/lib/src/platform_check/web.dart delete mode 100644 pointycastle/lib/src/registration.dart delete mode 100644 pointycastle/lib/src/registry/registration.dart delete mode 100644 pointycastle/lib/src/registry/registry.dart delete mode 100644 pointycastle/lib/src/ufixnum.dart delete mode 100644 pointycastle/lib/src/utils.dart delete mode 100644 pointycastle/lib/srp/srp6_client.dart delete mode 100644 pointycastle/lib/srp/srp6_server.dart delete mode 100644 pointycastle/lib/srp/srp6_standard_groups.dart delete mode 100644 pointycastle/lib/srp/srp6_util.dart delete mode 100644 pointycastle/lib/srp/srp6_verifier_generator.dart delete mode 100644 pointycastle/lib/stream/chacha20.dart delete mode 100644 pointycastle/lib/stream/chacha20poly1305.dart delete mode 100644 pointycastle/lib/stream/chacha7539.dart delete mode 100644 pointycastle/lib/stream/ctr.dart delete mode 100644 pointycastle/lib/stream/eax.dart delete mode 100644 pointycastle/lib/stream/rc4_engine.dart delete mode 100644 pointycastle/lib/stream/salsa20.dart delete mode 100644 pointycastle/lib/stream/sic.dart delete mode 100644 pointycastle/pubspec.yaml delete mode 100644 x25519/LICENSE delete mode 100644 x25519/lib/src/curve25519.dart delete mode 100644 x25519/lib/src/numbers.dart delete mode 100644 x25519/lib/x25519.dart delete mode 100644 x25519/pubspec.yaml diff --git a/adaptive_number/LICENSE b/adaptive_number/LICENSE deleted file mode 100644 index b0e8b7e..0000000 --- a/adaptive_number/LICENSE +++ /dev/null @@ -1,11 +0,0 @@ -Copyright 2021 Philipp Sessler - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/adaptive_number/lib/adaptive_number.dart b/adaptive_number/lib/adaptive_number.dart deleted file mode 100644 index 6078d6a..0000000 --- a/adaptive_number/lib/adaptive_number.dart +++ /dev/null @@ -1,6 +0,0 @@ -/// Support for doing something awesome. -/// -/// More dartdocs go here. -library adaptive_number; - -export 'src/number.dart'; diff --git a/adaptive_number/lib/src/int.dart b/adaptive_number/lib/src/int.dart deleted file mode 100644 index 9798828..0000000 --- a/adaptive_number/lib/src/int.dart +++ /dev/null @@ -1,120 +0,0 @@ -import 'package:adaptive_number/src/number.dart'; - -class NumberInt implements Number { - final int _value; - - NumberInt(this._value); - - @override - NumberInt operator +(Number value) { - return NumberInt(_value + (value.val as int)); - } - - @override - NumberInt operator -(Number value) { - return NumberInt(_value - (value.val as int)); - } - - @override - NumberInt operator -() { - return NumberInt(-(val)); - } - - @override - NumberInt operator *(Number value) { - return NumberInt(_value * (value.val as int)); - } - - @override - NumberInt operator &(Number value) { - return NumberInt(_value & (value.val as int)); - } - - @override - NumberInt operator >>(int value) { - return NumberInt(_value >> value); - } - - @override - NumberInt operator <<(int value) { - return NumberInt(_value << value); - } - - @override - NumberInt operator ^(Number value) { - return NumberInt(_value ^ (value.val as int)); - } - - @override - NumberInt operator |(Number value) { - return NumberInt(_value | (value.val as int)); - } - - @override - bool operator <(Number value) { - return (intValue < value.intValue); - } - - @override - bool operator <=(Number value) { - return (intValue <= value.intValue); - } - - @override - bool operator >(Number value) { - return (intValue > value.intValue); - } - - @override - bool operator >=(Number value) { - return (intValue >= value.intValue); - } - - @override - NumberInt operator %(Number value) { - return NumberInt(_value % (value.val as int)); - } - - @override - Number operator ~/(Number value) { - return NumberInt(_value ~/ (value.val as int)); - } - - @override - int get val => _value; - - @override - int get intValue => _value; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is NumberInt && - runtimeType == other.runtimeType && - _value == other._value; - - @override - int get hashCode => _value.hashCode; - - @override - String toString() { - return _value.toString(); - } - - @override - String toRadixString(int radix) { - return _value.toRadixString(radix); - } - - @override - NumberInt abs() { - return NumberInt(_value.abs()); - } - - @override - int compareTo(Number other) { - return _value.compareTo(other.intValue); - } -} - -Number createNumber(int val) => NumberInt(val); diff --git a/adaptive_number/lib/src/int64.dart b/adaptive_number/lib/src/int64.dart deleted file mode 100644 index 39b39e3..0000000 --- a/adaptive_number/lib/src/int64.dart +++ /dev/null @@ -1,121 +0,0 @@ -import 'package:adaptive_number/src/number.dart'; -import 'package:fixnum/fixnum.dart'; - -class NumberInt64 implements Number { - final Int64 _value; - - NumberInt64(this._value); - - @override - NumberInt64 operator +(Number value) { - return NumberInt64(_value + (value.val as Int64)); - } - - @override - NumberInt64 operator -(Number value) { - return NumberInt64(_value - (value.val as Int64)); - } - - @override - NumberInt64 operator -() { - return NumberInt64(-(val)); - } - - @override - NumberInt64 operator *(Number value) { - return NumberInt64(_value * (value.val as Int64)); - } - - @override - NumberInt64 operator &(Number value) { - return NumberInt64(_value & (value.val as Int64)); - } - - @override - NumberInt64 operator >>(int value) { - return NumberInt64(_value >> value); - } - - @override - NumberInt64 operator <<(int value) { - return NumberInt64(_value << value); - } - - @override - NumberInt64 operator ^(Number value) { - return NumberInt64(_value ^ (value.val as Int64)); - } - - @override - NumberInt64 operator |(Number value) { - return NumberInt64(_value | (value.val as Int64)); - } - - @override - bool operator <(Number value) { - return (intValue < value.intValue); - } - - @override - bool operator <=(Number value) { - return (intValue <= value.intValue); - } - - @override - bool operator >(Number value) { - return (intValue > value.intValue); - } - - @override - bool operator >=(Number value) { - return (intValue >= value.intValue); - } - - @override - NumberInt64 operator %(Number value) { - return NumberInt64(_value % (value.val as Int64)); - } - - @override - Number operator ~/(Number value) { - return NumberInt64(_value ~/ (value.val as Int64)); - } - - @override - Int64 get val => _value; - - @override - int get intValue => _value.toInt(); - - @override - bool operator ==(Object other) => - identical(this, other) || - other is NumberInt64 && - runtimeType == other.runtimeType && - _value == other._value; - - @override - int get hashCode => _value.hashCode; - - @override - String toString() { - return _value.toString(); - } - - @override - String toRadixString(int radix) { - return _value.toRadixString(radix); - } - - @override - NumberInt64 abs() { - return NumberInt64(_value.abs()); - } - - @override - int compareTo(Number value) { - return _value.compareTo(value.val as Int64); - } -} - -Number createNumber(int val) => NumberInt64(Int64(val)); diff --git a/adaptive_number/lib/src/number.dart b/adaptive_number/lib/src/number.dart deleted file mode 100644 index df64950..0000000 --- a/adaptive_number/lib/src/number.dart +++ /dev/null @@ -1,78 +0,0 @@ -import 'package:adaptive_number/src/stub.dart' -// ignore: uri_does_not_exist - if (dart.library.io) 'package:adaptive_number/src/int.dart' -// ignore: uri_does_not_exist - if (dart.library.html) 'package:adaptive_number/src/int64.dart'; - -abstract class Number { - static Number zero = Number(0); - static Number one = Number(1); - static Number two = Number(2); - - factory Number(int val) => createNumber(val); - - dynamic get val; - - /// Returns the value as int (caution: May overflow on JS runtimes) - int get intValue; - - @override - int get hashCode; - - /// Addition operator. - Number operator +(Number value); - - /// Subtraction operator. - Number operator -(Number value); - - /// Negate operator. - Number operator -(); - - /// Multiplication operator. - Number operator *(Number value); - - /// Bitwise and operator. - Number operator &(Number value); - - /// Right bit-shift operator. - Number operator >>(int value); - - /// Left bit-shift operator. - Number operator <<(int value); - - /// Bitwise xor operator. - Number operator ^(Number value); - - /// Bitwise or operator. - Number operator |(Number value); - - /// Relational less than operator. - bool operator <(Number value); - - /// Relational less than or equal to operator. - bool operator <=(Number value); - - /// Relational greater than operator. - bool operator >(Number value); - - /// Relational greater than or equal to operator. - bool operator >=(Number value); - - /// Euclidean modulo operator. - Number operator %(Number value); - - /// Truncating division operator. - Number operator ~/(Number value); - - @override - String toString(); - - /// Returns a string representing the value of this integer in the given radix. - String toRadixString(int radix); - - /// Returns the absolute value of this integer. - Number abs(); - - // Compares this to `other` - int compareTo(Number other); -} diff --git a/adaptive_number/lib/src/stub.dart b/adaptive_number/lib/src/stub.dart deleted file mode 100644 index 1e4ce05..0000000 --- a/adaptive_number/lib/src/stub.dart +++ /dev/null @@ -1,4 +0,0 @@ -import 'package:adaptive_number/src/number.dart'; - -Number createNumber(int val) => throw UnsupportedError( - 'Cannot create a Number without package dart.library.io or dart.library.html being available'); diff --git a/adaptive_number/pubspec.yaml b/adaptive_number/pubspec.yaml deleted file mode 100644 index a408604..0000000 --- a/adaptive_number/pubspec.yaml +++ /dev/null @@ -1,17 +0,0 @@ -name: adaptive_number -version: 1.0.0 - -description: >- - Library providing an adaptive number implementation. On JS runtimes, a 64-bit signed fixed-width integer will be used and - for all other platforms the default Dart int data type. -homepage: https://github.com/lemoony/adaptive_number_dart - -environment: - sdk: '>=2.12.0 <3.0.0' - -dependencies: - fixnum: ^1.0.0 - -dev_dependencies: - pedantic: ^1.10.0 - test: ^1.16.0 diff --git a/ed25519_edwards/LICENSE b/ed25519_edwards/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/ed25519_edwards/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/ed25519_edwards/lib/ed25519_edwards.dart b/ed25519_edwards/lib/ed25519_edwards.dart deleted file mode 100644 index be808df..0000000 --- a/ed25519_edwards/lib/ed25519_edwards.dart +++ /dev/null @@ -1,204 +0,0 @@ -/// Package ed25519 implements the Ed25519 signature algorithm. See -/// https://ed25519.cr.yp.to/. -/// -/// These functions are also compatible with the “Ed25519” function defined in -/// RFC 8032. However, unlike RFC 8032's formulation, this package's private key -/// representation includes a public key suffix to make multiple signing -/// operations with the same key more efficient. This package refers to the RFC -/// 8032 private key as the “seed”. - -library edwards25519; - -import 'dart:typed_data'; -import 'package:convert/convert.dart'; -import 'package:collection/collection.dart'; -import 'package:crypto/crypto.dart'; -import 'package:ed25519_edwards/src/edwards25519.dart'; -import 'package:ed25519_edwards/src/util.dart'; - -/// PublicKeySize is the size, in bytes, of public keys as used in this package. -const PublicKeySize = 32; - -/// PrivateKeySize is the size, in bytes, of private keys as used in this package. -const PrivateKeySize = 64; - -/// SignatureSize is the size, in bytes, of signatures generated and verified by this package. -const SignatureSize = 64; - -/// SeedSize is the size, in bytes, of private key seeds. These are the private key representations used by RFC 8032. -const SeedSize = 32; - -/// PublicKey is the type of Ed25519 public keys. -class PublicKey { - List bytes; - - PublicKey(this.bytes); -} - -/// PrivateKey is the type of Ed25519 private keys. -class PrivateKey { - List bytes; - - PrivateKey(this.bytes); -} - -/// KeyPair is the type of Ed25519 public/private key pair. -class KeyPair { - final PrivateKey privateKey; - - final PublicKey publicKey; - - KeyPair(this.privateKey, this.publicKey); - - @override - int get hashCode => publicKey.hashCode; - - @override - bool operator ==(other) => - other is KeyPair && - publicKey == other.publicKey && - privateKey == other.privateKey; -} - -/// public returns the PublicKey corresponding to PrivateKey. -PublicKey public(PrivateKey privateKey) { - var publicKey = privateKey.bytes.sublist(32, 32 + PublicKeySize); - return PublicKey(publicKey); -} - -/// Seed returns the private key seed corresponding to priv. It is provided for -/// interoperability with RFC 8032. RFC 8032's private keys correspond to seeds -/// in this package. -Uint8List seed(PrivateKey privateKey) { - var seed = privateKey.bytes.sublist(0, SeedSize); - return seed as Uint8List; -} - -/// GenerateKey generates a public/private key pair using entropy from secure random. -KeyPair generateKey() { - var seed = Uint8List(32); - fillBytesWithSecureRandomNumbers(seed); - var privateKey = newKeyFromSeed(seed); - var publicKey = privateKey.bytes.sublist(32, PrivateKeySize); - return KeyPair(privateKey, PublicKey(publicKey)); -} - -/// NewKeyFromSeed calculates a private key from a seed. It will throw -/// ArgumentError if seed.length is not SeedSize. -/// This function is provided for interoperability with RFC 8032. -/// RFC 8032's private keys correspond to seeds in this package. -PrivateKey newKeyFromSeed(Uint8List seed) { - if (seed.length != SeedSize) { - throw ArgumentError('ed25519: bad seed length ${seed.length}'); - } - var h = sha512.convert(seed); - var digest = h.bytes.sublist(0, 32); - digest[0] &= 248; - digest[31] &= 127; - digest[31] |= 64; - - var A = ExtendedGroupElement(); - var hBytes = digest.sublist(0); - GeScalarMultBase(A, hBytes as Uint8List); - var publicKeyBytes = Uint8List(32); - A.ToBytes(publicKeyBytes); - - var privateKey = Uint8List(PrivateKeySize); - arrayCopy(seed, 0, privateKey, 0, 32); - arrayCopy(publicKeyBytes, 0, privateKey, 32, 32); - return PrivateKey(privateKey); -} - -/// Sign signs the message with privateKey and returns a signature. It will -/// throw ArumentError if privateKey.bytes.length is not PrivateKeySize. -Uint8List sign(PrivateKey privateKey, Uint8List message) { - if (privateKey.bytes.length != PrivateKeySize) { - throw ArgumentError( - 'ed25519: bad privateKey length ${privateKey.bytes.length}'); - } - var h = sha512.convert(privateKey.bytes.sublist(0, 32)); - var digest1 = h.bytes; - var expandedSecretKey = digest1.sublist(0, 32); - expandedSecretKey[0] &= 248; - expandedSecretKey[31] &= 63; - expandedSecretKey[31] |= 64; - - var output = AccumulatorSink(); - var input = sha512.startChunkedConversion(output); - input.add(digest1.sublist(32)); - input.add(message); - input.close(); - var messageDigest = output.events.single.bytes; - - var messageDigestReduced = Uint8List(32); - ScReduce(messageDigestReduced, messageDigest as Uint8List); - var R = ExtendedGroupElement(); - GeScalarMultBase(R, messageDigestReduced); - - var encodedR = Uint8List(32); - R.ToBytes(encodedR); - - output = AccumulatorSink(); - input = sha512.startChunkedConversion(output); - input.add(encodedR); - input.add(privateKey.bytes.sublist(32)); - input.add(message); - input.close(); - var hramDigest = output.events.single.bytes; - var hramDigestReduced = Uint8List(32); - ScReduce(hramDigestReduced, hramDigest as Uint8List); - - var s = Uint8List(32); - ScMulAdd(s, hramDigestReduced, expandedSecretKey as Uint8List, - messageDigestReduced); - - var signature = Uint8List(SignatureSize); - arrayCopy(encodedR, 0, signature, 0, 32); - arrayCopy(s, 0, signature, 32, 32); - - return signature; -} - -/// Verify reports whether sig is a valid signature of message by publicKey. It -/// will throw ArgumentError if publicKey.bytes.length is not PublicKeySize. -bool verify(PublicKey publicKey, Uint8List message, Uint8List sig) { - if (publicKey.bytes.length != PublicKeySize) { - throw ArgumentError( - 'ed25519: bad publicKey length ${publicKey.bytes.length}'); - } - if (sig.length != SignatureSize || sig[63] & 224 != 0) { - return false; - } - - var A = ExtendedGroupElement(); - var publicKeyBytes = Uint8List.fromList(publicKey.bytes); - if (!A.FromBytes(publicKeyBytes)) { - return false; - } - FeNeg(A.X, A.X); - FeNeg(A.T, A.T); - - var output = AccumulatorSink(); - var input = sha512.startChunkedConversion(output); - input.add(sig.sublist(0, 32)); - input.add(publicKeyBytes); - input.add(message); - input.close(); - var digest = output.events.single.bytes; - - var hReduced = Uint8List(32); - ScReduce(hReduced, digest as Uint8List); - - var R = ProjectiveGroupElement(); - var s = sig.sublist(32); - - if (!ScMinimal(s)) { - return false; - } - - GeDoubleScalarMultVartime(R, hReduced, A, s); - - var checkR = Uint8List(32); - R.ToBytes(checkR); - return ListEquality().equals(sig.sublist(0, 32), checkR); -} diff --git a/ed25519_edwards/lib/src/const.dart b/ed25519_edwards/lib/src/const.dart deleted file mode 100644 index b8405d8..0000000 --- a/ed25519_edwards/lib/src/const.dart +++ /dev/null @@ -1,10162 +0,0 @@ -import 'edwards25519.dart'; - -var d = FieldElement.fromList([ - -10913610, - 13857413, - -15372611, - 6949391, - 114729, - -8787816, - -6275908, - -3247719, - -18696448, - -12055116, -]); - -/// d2 is 2*d. -var d2 = FieldElement.fromList([ - -21827239, - -5839606, - -30745221, - 13898782, - 229458, - 15978800, - -12551817, - -6495438, - 29715968, - 9444199, -]); - -/// SqrtM1 is the square-root of -1 in the field. -var SqrtM1 = FieldElement.fromList([ - -32595792, - -7943725, - 9377950, - 3500415, - 12389472, - -272473, - -25146209, - -2005654, - 326686, - 11406482, -]); - -/// A is a constant in the Montgomery-form of curve25519. -var A = FieldElement.fromList([ - 486662, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, -]); - -/// bi contains precomputed multiples of the base-point. See the Ed25519 paper -/// for a discussion about how these values are used. -var bi = List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 25967493, - -14356035, - 29566456, - 3660896, - -12694345, - 4014787, - 27544626, - -11754271, - -6079156, - 2047605 - ]), - FieldElement.fromList([ - -12545711, - 934262, - -2722910, - 3049990, - -727428, - 9406986, - 12720692, - 5043384, - 19500929, - -15469378 - ]), - FieldElement.fromList([ - -8738181, - 4489570, - 9688441, - -14785194, - 10184609, - -12363380, - 29287919, - 11864899, - -24514362, - -4438546 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 15636291, - -9688557, - 24204773, - -7912398, - 616977, - -16685262, - 27787600, - -14772189, - 28944400, - -1550024 - ]), - FieldElement.fromList([ - 16568933, - 4717097, - -11556148, - -1102322, - 15682896, - -11807043, - 16354577, - -11775962, - 7689662, - 11199574 - ]), - FieldElement.fromList([ - 30464156, - -5976125, - -11779434, - -15670865, - 23220365, - 15915852, - 7512774, - 10017326, - -17749093, - -9920357 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 10861363, - 11473154, - 27284546, - 1981175, - -30064349, - 12577861, - 32867885, - 14515107, - -15438304, - 10819380 - ]), - FieldElement.fromList([ - 4708026, - 6336745, - 20377586, - 9066809, - -11272109, - 6594696, - -25653668, - 12483688, - -12668491, - 5581306 - ]), - FieldElement.fromList([ - 19563160, - 16186464, - -29386857, - 4097519, - 10237984, - -4348115, - 28542350, - 13850243, - -23678021, - -15815942 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 5153746, - 9909285, - 1723747, - -2777874, - 30523605, - 5516873, - 19480852, - 5230134, - -23952439, - -15175766 - ]), - FieldElement.fromList([ - -30269007, - -3463509, - 7665486, - 10083793, - 28475525, - 1649722, - 20654025, - 16520125, - 30598449, - 7715701 - ]), - FieldElement.fromList([ - 28881845, - 14381568, - 9657904, - 3680757, - -20181635, - 7843316, - -31400660, - 1370708, - 29794553, - -1409300 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -22518993, - -6692182, - 14201702, - -8745502, - -23510406, - 8844726, - 18474211, - -1361450, - -13062696, - 13821877 - ]), - FieldElement.fromList([ - -6455177, - -7839871, - 3374702, - -4740862, - -27098617, - -10571707, - 31655028, - -7212327, - 18853322, - -14220951 - ]), - FieldElement.fromList([ - 4566830, - -12963868, - -28974889, - -12240689, - -7602672, - -2830569, - -8514358, - -10431137, - 2207753, - -3209784 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -25154831, - -4185821, - 29681144, - 7868801, - -6854661, - -9423865, - -12437364, - -663000, - -31111463, - -16132436 - ]), - FieldElement.fromList([ - 25576264, - -2703214, - 7349804, - -11814844, - 16472782, - 9300885, - 3844789, - 15725684, - 171356, - 6466918 - ]), - FieldElement.fromList([ - 23103977, - 13316479, - 9739013, - -16149481, - 817875, - -15038942, - 8965339, - -14088058, - -30714912, - 16193877 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -33521811, - 3180713, - -2394130, - 14003687, - -16903474, - -16270840, - 17238398, - 4729455, - -18074513, - 9256800 - ]), - FieldElement.fromList([ - -25182317, - -4174131, - 32336398, - 5036987, - -21236817, - 11360617, - 22616405, - 9761698, - -19827198, - 630305 - ]), - FieldElement.fromList([ - -13720693, - 2639453, - -24237460, - -7406481, - 9494427, - -5774029, - -6554551, - -15960994, - -2449256, - -14291300 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -3151181, - -5046075, - 9282714, - 6866145, - -31907062, - -863023, - -18940575, - 15033784, - 25105118, - -7894876 - ]), - FieldElement.fromList([ - -24326370, - 15950226, - -31801215, - -14592823, - -11662737, - -5090925, - 1573892, - -2625887, - 2198790, - -15804619 - ]), - FieldElement.fromList([ - -3099351, - 10324967, - -2241613, - 7453183, - -5446979, - -2735503, - -13812022, - -16236442, - -32461234, - -12290683 - ]), - ) -]); - -/// base contains precomputed multiples of the base-point. See the Ed25519 paper -/// for a discussion about how these values are used. -var base = List.from([ - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 25967493, - -14356035, - 29566456, - 3660896, - -12694345, - 4014787, - 27544626, - -11754271, - -6079156, - 2047605 - ]), - FieldElement.fromList([ - -12545711, - 934262, - -2722910, - 3049990, - -727428, - 9406986, - 12720692, - 5043384, - 19500929, - -15469378 - ]), - FieldElement.fromList([ - -8738181, - 4489570, - 9688441, - -14785194, - 10184609, - -12363380, - 29287919, - 11864899, - -24514362, - -4438546 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -12815894, - -12976347, - -21581243, - 11784320, - -25355658, - -2750717, - -11717903, - -3814571, - -358445, - -10211303 - ]), - FieldElement.fromList([ - -21703237, - 6903825, - 27185491, - 6451973, - -29577724, - -9554005, - -15616551, - 11189268, - -26829678, - -5319081 - ]), - FieldElement.fromList([ - 26966642, - 11152617, - 32442495, - 15396054, - 14353839, - -12752335, - -3128826, - -9541118, - -15472047, - -4166697 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 15636291, - -9688557, - 24204773, - -7912398, - 616977, - -16685262, - 27787600, - -14772189, - 28944400, - -1550024 - ]), - FieldElement.fromList([ - 16568933, - 4717097, - -11556148, - -1102322, - 15682896, - -11807043, - 16354577, - -11775962, - 7689662, - 11199574 - ]), - FieldElement.fromList([ - 30464156, - -5976125, - -11779434, - -15670865, - 23220365, - 15915852, - 7512774, - 10017326, - -17749093, - -9920357 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -17036878, - 13921892, - 10945806, - -6033431, - 27105052, - -16084379, - -28926210, - 15006023, - 3284568, - -6276540 - ]), - FieldElement.fromList([ - 23599295, - -8306047, - -11193664, - -7687416, - 13236774, - 10506355, - 7464579, - 9656445, - 13059162, - 10374397 - ]), - FieldElement.fromList([ - 7798556, - 16710257, - 3033922, - 2874086, - 28997861, - 2835604, - 32406664, - -3839045, - -641708, - -101325 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 10861363, - 11473154, - 27284546, - 1981175, - -30064349, - 12577861, - 32867885, - 14515107, - -15438304, - 10819380 - ]), - FieldElement.fromList([ - 4708026, - 6336745, - 20377586, - 9066809, - -11272109, - 6594696, - -25653668, - 12483688, - -12668491, - 5581306 - ]), - FieldElement.fromList([ - 19563160, - 16186464, - -29386857, - 4097519, - 10237984, - -4348115, - 28542350, - 13850243, - -23678021, - -15815942 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -15371964, - -12862754, - 32573250, - 4720197, - -26436522, - 5875511, - -19188627, - -15224819, - -9818940, - -12085777 - ]), - FieldElement.fromList([ - -8549212, - 109983, - 15149363, - 2178705, - 22900618, - 4543417, - 3044240, - -15689887, - 1762328, - 14866737 - ]), - FieldElement.fromList([ - -18199695, - -15951423, - -10473290, - 1707278, - -17185920, - 3916101, - -28236412, - 3959421, - 27914454, - 4383652 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 5153746, - 9909285, - 1723747, - -2777874, - 30523605, - 5516873, - 19480852, - 5230134, - -23952439, - -15175766 - ]), - FieldElement.fromList([ - -30269007, - -3463509, - 7665486, - 10083793, - 28475525, - 1649722, - 20654025, - 16520125, - 30598449, - 7715701 - ]), - FieldElement.fromList([ - 28881845, - 14381568, - 9657904, - 3680757, - -20181635, - 7843316, - -31400660, - 1370708, - 29794553, - -1409300 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 14499471, - -2729599, - -33191113, - -4254652, - 28494862, - 14271267, - 30290735, - 10876454, - -33154098, - 2381726 - ]), - FieldElement.fromList([ - -7195431, - -2655363, - -14730155, - 462251, - -27724326, - 3941372, - -6236617, - 3696005, - -32300832, - 15351955 - ]), - FieldElement.fromList([ - 27431194, - 8222322, - 16448760, - -3907995, - -18707002, - 11938355, - -32961401, - -2970515, - 29551813, - 10109425 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -13657040, - -13155431, - -31283750, - 11777098, - 21447386, - 6519384, - -2378284, - -1627556, - 10092783, - -4764171 - ]), - FieldElement.fromList([ - 27939166, - 14210322, - 4677035, - 16277044, - -22964462, - -12398139, - -32508754, - 12005538, - -17810127, - 12803510 - ]), - FieldElement.fromList([ - 17228999, - -15661624, - -1233527, - 300140, - -1224870, - -11714777, - 30364213, - -9038194, - 18016357, - 4397660 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -10958843, - -7690207, - 4776341, - -14954238, - 27850028, - -15602212, - -26619106, - 14544525, - -17477504, - 982639 - ]), - FieldElement.fromList([ - 29253598, - 15796703, - -2863982, - -9908884, - 10057023, - 3163536, - 7332899, - -4120128, - -21047696, - 9934963 - ]), - FieldElement.fromList([ - 5793303, - 16271923, - -24131614, - -10116404, - 29188560, - 1206517, - -14747930, - 4559895, - -30123922, - -10897950 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -27643952, - -11493006, - 16282657, - -11036493, - 28414021, - -15012264, - 24191034, - 4541697, - -13338309, - 5500568 - ]), - FieldElement.fromList([ - 12650548, - -1497113, - 9052871, - 11355358, - -17680037, - -8400164, - -17430592, - 12264343, - 10874051, - 13524335 - ]), - FieldElement.fromList([ - 25556948, - -3045990, - 714651, - 2510400, - 23394682, - -10415330, - 33119038, - 5080568, - -22528059, - 5376628 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -26088264, - -4011052, - -17013699, - -3537628, - -6726793, - 1920897, - -22321305, - -9447443, - 4535768, - 1569007 - ]), - FieldElement.fromList([ - -2255422, - 14606630, - -21692440, - -8039818, - 28430649, - 8775819, - -30494562, - 3044290, - 31848280, - 12543772 - ]), - FieldElement.fromList([ - -22028579, - 2943893, - -31857513, - 6777306, - 13784462, - -4292203, - -27377195, - -2062731, - 7718482, - 14474653 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 2385315, - 2454213, - -22631320, - 46603, - -4437935, - -15680415, - 656965, - -7236665, - 24316168, - -5253567 - ]), - FieldElement.fromList([ - 13741529, - 10911568, - -33233417, - -8603737, - -20177830, - -1033297, - 33040651, - -13424532, - -20729456, - 8321686 - ]), - FieldElement.fromList([ - 21060490, - -2212744, - 15712757, - -4336099, - 1639040, - 10656336, - 23845965, - -11874838, - -9984458, - 608372 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -13672732, - -15087586, - -10889693, - -7557059, - -6036909, - 11305547, - 1123968, - -6780577, - 27229399, - 23887 - ]), - FieldElement.fromList([ - -23244140, - -294205, - -11744728, - 14712571, - -29465699, - -2029617, - 12797024, - -6440308, - -1633405, - 16678954 - ]), - FieldElement.fromList([ - -29500620, - 4770662, - -16054387, - 14001338, - 7830047, - 9564805, - -1508144, - -4795045, - -17169265, - 4904953 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 24059557, - 14617003, - 19037157, - -15039908, - 19766093, - -14906429, - 5169211, - 16191880, - 2128236, - -4326833 - ]), - FieldElement.fromList([ - -16981152, - 4124966, - -8540610, - -10653797, - 30336522, - -14105247, - -29806336, - 916033, - -6882542, - -2986532 - ]), - FieldElement.fromList([ - -22630907, - 12419372, - -7134229, - -7473371, - -16478904, - 16739175, - 285431, - 2763829, - 15736322, - 4143876 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 2379352, - 11839345, - -4110402, - -5988665, - 11274298, - 794957, - 212801, - -14594663, - 23527084, - -16458268 - ]), - FieldElement.fromList([ - 33431127, - -11130478, - -17838966, - -15626900, - 8909499, - 8376530, - -32625340, - 4087881, - -15188911, - -14416214 - ]), - FieldElement.fromList([ - 1767683, - 7197987, - -13205226, - -2022635, - -13091350, - 448826, - 5799055, - 4357868, - -4774191, - -16323038 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 6721966, - 13833823, - -23523388, - -1551314, - 26354293, - -11863321, - 23365147, - -3949732, - 7390890, - 2759800 - ]), - FieldElement.fromList([ - 4409041, - 2052381, - 23373853, - 10530217, - 7676779, - -12885954, - 21302353, - -4264057, - 1244380, - -12919645 - ]), - FieldElement.fromList([ - -4421239, - 7169619, - 4982368, - -2957590, - 30256825, - -2777540, - 14086413, - 9208236, - 15886429, - 16489664 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 1996075, - 10375649, - 14346367, - 13311202, - -6874135, - -16438411, - -13693198, - 398369, - -30606455, - -712933 - ]), - FieldElement.fromList([ - -25307465, - 9795880, - -2777414, - 14878809, - -33531835, - 14780363, - 13348553, - 12076947, - -30836462, - 5113182 - ]), - FieldElement.fromList([ - -17770784, - 11797796, - 31950843, - 13929123, - -25888302, - 12288344, - -30341101, - -7336386, - 13847711, - 5387222 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -18582163, - -3416217, - 17824843, - -2340966, - 22744343, - -10442611, - 8763061, - 3617786, - -19600662, - 10370991 - ]), - FieldElement.fromList([ - 20246567, - -14369378, - 22358229, - -543712, - 18507283, - -10413996, - 14554437, - -8746092, - 32232924, - 16763880 - ]), - FieldElement.fromList([ - 9648505, - 10094563, - 26416693, - 14745928, - -30374318, - -6472621, - 11094161, - 15689506, - 3140038, - -16510092 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -16160072, - 5472695, - 31895588, - 4744994, - 8823515, - 10365685, - -27224800, - 9448613, - -28774454, - 366295 - ]), - FieldElement.fromList([ - 19153450, - 11523972, - -11096490, - -6503142, - -24647631, - 5420647, - 28344573, - 8041113, - 719605, - 11671788 - ]), - FieldElement.fromList([ - 8678025, - 2694440, - -6808014, - 2517372, - 4964326, - 11152271, - -15432916, - -15266516, - 27000813, - -10195553 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -15157904, - 7134312, - 8639287, - -2814877, - -7235688, - 10421742, - 564065, - 5336097, - 6750977, - -14521026 - ]), - FieldElement.fromList([ - 11836410, - -3979488, - 26297894, - 16080799, - 23455045, - 15735944, - 1695823, - -8819122, - 8169720, - 16220347 - ]), - FieldElement.fromList([ - -18115838, - 8653647, - 17578566, - -6092619, - -8025777, - -16012763, - -11144307, - -2627664, - -5990708, - -14166033 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -23308498, - -10968312, - 15213228, - -10081214, - -30853605, - -11050004, - 27884329, - 2847284, - 2655861, - 1738395 - ]), - FieldElement.fromList([ - -27537433, - -14253021, - -25336301, - -8002780, - -9370762, - 8129821, - 21651608, - -3239336, - -19087449, - -11005278 - ]), - FieldElement.fromList([ - 1533110, - 3437855, - 23735889, - 459276, - 29970501, - 11335377, - 26030092, - 5821408, - 10478196, - 8544890 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 32173121, - -16129311, - 24896207, - 3921497, - 22579056, - -3410854, - 19270449, - 12217473, - 17789017, - -3395995 - ]), - FieldElement.fromList([ - -30552961, - -2228401, - -15578829, - -10147201, - 13243889, - 517024, - 15479401, - -3853233, - 30460520, - 1052596 - ]), - FieldElement.fromList([ - -11614875, - 13323618, - 32618793, - 8175907, - -15230173, - 12596687, - 27491595, - -4612359, - 3179268, - -9478891 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 31947069, - -14366651, - -4640583, - -15339921, - -15125977, - -6039709, - -14756777, - -16411740, - 19072640, - -9511060 - ]), - FieldElement.fromList([ - 11685058, - 11822410, - 3158003, - -13952594, - 33402194, - -4165066, - 5977896, - -5215017, - 473099, - 5040608 - ]), - FieldElement.fromList([ - -20290863, - 8198642, - -27410132, - 11602123, - 1290375, - -2799760, - 28326862, - 1721092, - -19558642, - -3131606 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 7881532, - 10687937, - 7578723, - 7738378, - -18951012, - -2553952, - 21820786, - 8076149, - -27868496, - 11538389 - ]), - FieldElement.fromList([ - -19935666, - 3899861, - 18283497, - -6801568, - -15728660, - -11249211, - 8754525, - 7446702, - -5676054, - 5797016 - ]), - FieldElement.fromList([ - -11295600, - -3793569, - -15782110, - -7964573, - 12708869, - -8456199, - 2014099, - -9050574, - -2369172, - -5877341 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -22472376, - -11568741, - -27682020, - 1146375, - 18956691, - 16640559, - 1192730, - -3714199, - 15123619, - 10811505 - ]), - FieldElement.fromList([ - 14352098, - -3419715, - -18942044, - 10822655, - 32750596, - 4699007, - -70363, - 15776356, - -28886779, - -11974553 - ]), - FieldElement.fromList([ - -28241164, - -8072475, - -4978962, - -5315317, - 29416931, - 1847569, - -20654173, - -16484855, - 4714547, - -9600655 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 15200332, - 8368572, - 19679101, - 15970074, - -31872674, - 1959451, - 24611599, - -4543832, - -11745876, - 12340220 - ]), - FieldElement.fromList([ - 12876937, - -10480056, - 33134381, - 6590940, - -6307776, - 14872440, - 9613953, - 8241152, - 15370987, - 9608631 - ]), - FieldElement.fromList([ - -4143277, - -12014408, - 8446281, - -391603, - 4407738, - 13629032, - -7724868, - 15866074, - -28210621, - -8814099 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 26660628, - -15677655, - 8393734, - 358047, - -7401291, - 992988, - -23904233, - 858697, - 20571223, - 8420556 - ]), - FieldElement.fromList([ - 14620715, - 13067227, - -15447274, - 8264467, - 14106269, - 15080814, - 33531827, - 12516406, - -21574435, - -12476749 - ]), - FieldElement.fromList([ - 236881, - 10476226, - 57258, - -14677024, - 6472998, - 2466984, - 17258519, - 7256740, - 8791136, - 15069930 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 1276410, - -9371918, - 22949635, - -16322807, - -23493039, - -5702186, - 14711875, - 4874229, - -30663140, - -2331391 - ]), - FieldElement.fromList([ - 5855666, - 4990204, - -13711848, - 7294284, - -7804282, - 1924647, - -1423175, - -7912378, - -33069337, - 9234253 - ]), - FieldElement.fromList([ - 20590503, - -9018988, - 31529744, - -7352666, - -2706834, - 10650548, - 31559055, - -11609587, - 18979186, - 13396066 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 24474287, - 4968103, - 22267082, - 4407354, - 24063882, - -8325180, - -18816887, - 13594782, - 33514650, - 7021958 - ]), - FieldElement.fromList([ - -11566906, - -6565505, - -21365085, - 15928892, - -26158305, - 4315421, - -25948728, - -3916677, - -21480480, - 12868082 - ]), - FieldElement.fromList([ - -28635013, - 13504661, - 19988037, - -2132761, - 21078225, - 6443208, - -21446107, - 2244500, - -12455797, - -8089383 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -30595528, - 13793479, - -5852820, - 319136, - -25723172, - -6263899, - 33086546, - 8957937, - -15233648, - 5540521 - ]), - FieldElement.fromList([ - -11630176, - -11503902, - -8119500, - -7643073, - 2620056, - 1022908, - -23710744, - -1568984, - -16128528, - -14962807 - ]), - FieldElement.fromList([ - 23152971, - 775386, - 27395463, - 14006635, - -9701118, - 4649512, - 1689819, - 892185, - -11513277, - -15205948 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 9770129, - 9586738, - 26496094, - 4324120, - 1556511, - -3550024, - 27453819, - 4763127, - -19179614, - 5867134 - ]), - FieldElement.fromList([ - -32765025, - 1927590, - 31726409, - -4753295, - 23962434, - -16019500, - 27846559, - 5931263, - -29749703, - -16108455 - ]), - FieldElement.fromList([ - 27461885, - -2977536, - 22380810, - 1815854, - -23033753, - -3031938, - 7283490, - -15148073, - -19526700, - 7734629 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -8010264, - -9590817, - -11120403, - 6196038, - 29344158, - -13430885, - 7585295, - -3176626, - 18549497, - 15302069 - ]), - FieldElement.fromList([ - -32658337, - -6171222, - -7672793, - -11051681, - 6258878, - 13504381, - 10458790, - -6418461, - -8872242, - 8424746 - ]), - FieldElement.fromList([ - 24687205, - 8613276, - -30667046, - -3233545, - 1863892, - -1830544, - 19206234, - 7134917, - -11284482, - -828919 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 11334899, - -9218022, - 8025293, - 12707519, - 17523892, - -10476071, - 10243738, - -14685461, - -5066034, - 16498837 - ]), - FieldElement.fromList([ - 8911542, - 6887158, - -9584260, - -6958590, - 11145641, - -9543680, - 17303925, - -14124238, - 6536641, - 10543906 - ]), - FieldElement.fromList([ - -28946384, - 15479763, - -17466835, - 568876, - -1497683, - 11223454, - -2669190, - -16625574, - -27235709, - 8876771 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -25742899, - -12566864, - -15649966, - -846607, - -33026686, - -796288, - -33481822, - 15824474, - -604426, - -9039817 - ]), - FieldElement.fromList([ - 10330056, - 70051, - 7957388, - -9002667, - 9764902, - 15609756, - 27698697, - -4890037, - 1657394, - 3084098 - ]), - FieldElement.fromList([ - 10477963, - -7470260, - 12119566, - -13250805, - 29016247, - -5365589, - 31280319, - 14396151, - -30233575, - 15272409 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -12288309, - 3169463, - 28813183, - 16658753, - 25116432, - -5630466, - -25173957, - -12636138, - -25014757, - 1950504 - ]), - FieldElement.fromList([ - -26180358, - 9489187, - 11053416, - -14746161, - -31053720, - 5825630, - -8384306, - -8767532, - 15341279, - 8373727 - ]), - FieldElement.fromList([ - 28685821, - 7759505, - -14378516, - -12002860, - -31971820, - 4079242, - 298136, - -10232602, - -2878207, - 15190420 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -32932876, - 13806336, - -14337485, - -15794431, - -24004620, - 10940928, - 8669718, - 2742393, - -26033313, - -6875003 - ]), - FieldElement.fromList([ - -1580388, - -11729417, - -25979658, - -11445023, - -17411874, - -10912854, - 9291594, - -16247779, - -12154742, - 6048605 - ]), - FieldElement.fromList([ - -30305315, - 14843444, - 1539301, - 11864366, - 20201677, - 1900163, - 13934231, - 5128323, - 11213262, - 9168384 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -26280513, - 11007847, - 19408960, - -940758, - -18592965, - -4328580, - -5088060, - -11105150, - 20470157, - -16398701 - ]), - FieldElement.fromList([ - -23136053, - 9282192, - 14855179, - -15390078, - -7362815, - -14408560, - -22783952, - 14461608, - 14042978, - 5230683 - ]), - FieldElement.fromList([ - 29969567, - -2741594, - -16711867, - -8552442, - 9175486, - -2468974, - 21556951, - 3506042, - -5933891, - -12449708 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -3144746, - 8744661, - 19704003, - 4581278, - -20430686, - 6830683, - -21284170, - 8971513, - -28539189, - 15326563 - ]), - FieldElement.fromList([ - -19464629, - 10110288, - -17262528, - -3503892, - -23500387, - 1355669, - -15523050, - 15300988, - -20514118, - 9168260 - ]), - FieldElement.fromList([ - -5353335, - 4488613, - -23803248, - 16314347, - 7780487, - -15638939, - -28948358, - 9601605, - 33087103, - -9011387 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -19443170, - -15512900, - -20797467, - -12445323, - -29824447, - 10229461, - -27444329, - -15000531, - -5996870, - 15664672 - ]), - FieldElement.fromList([ - 23294591, - -16632613, - -22650781, - -8470978, - 27844204, - 11461195, - 13099750, - -2460356, - 18151676, - 13417686 - ]), - FieldElement.fromList([ - -24722913, - -4176517, - -31150679, - 5988919, - -26858785, - 6685065, - 1661597, - -12551441, - 15271676, - -15452665 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 11433042, - -13228665, - 8239631, - -5279517, - -1985436, - -725718, - -18698764, - 2167544, - -6921301, - -13440182 - ]), - FieldElement.fromList([ - -31436171, - 15575146, - 30436815, - 12192228, - -22463353, - 9395379, - -9917708, - -8638997, - 12215110, - 12028277 - ]), - FieldElement.fromList([ - 14098400, - 6555944, - 23007258, - 5757252, - -15427832, - -12950502, - 30123440, - 4617780, - -16900089, - -655628 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -4026201, - -15240835, - 11893168, - 13718664, - -14809462, - 1847385, - -15819999, - 10154009, - 23973261, - -12684474 - ]), - FieldElement.fromList([ - -26531820, - -3695990, - -1908898, - 2534301, - -31870557, - -16550355, - 18341390, - -11419951, - 32013174, - -10103539 - ]), - FieldElement.fromList([ - -25479301, - 10876443, - -11771086, - -14625140, - -12369567, - 1838104, - 21911214, - 6354752, - 4425632, - -837822 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -10433389, - -14612966, - 22229858, - -3091047, - -13191166, - 776729, - -17415375, - -12020462, - 4725005, - 14044970 - ]), - FieldElement.fromList([ - 19268650, - -7304421, - 1555349, - 8692754, - -21474059, - -9910664, - 6347390, - -1411784, - -19522291, - -16109756 - ]), - FieldElement.fromList([ - -24864089, - 12986008, - -10898878, - -5558584, - -11312371, - -148526, - 19541418, - 8180106, - 9282262, - 10282508 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -26205082, - 4428547, - -8661196, - -13194263, - 4098402, - -14165257, - 15522535, - 8372215, - 5542595, - -10702683 - ]), - FieldElement.fromList([ - -10562541, - 14895633, - 26814552, - -16673850, - -17480754, - -2489360, - -2781891, - 6993761, - -18093885, - 10114655 - ]), - FieldElement.fromList([ - -20107055, - -929418, - 31422704, - 10427861, - -7110749, - 6150669, - -29091755, - -11529146, - 25953725, - -106158 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -4234397, - -8039292, - -9119125, - 3046000, - 2101609, - -12607294, - 19390020, - 6094296, - -3315279, - 12831125 - ]), - FieldElement.fromList([ - -15998678, - 7578152, - 5310217, - 14408357, - -33548620, - -224739, - 31575954, - 6326196, - 7381791, - -2421839 - ]), - FieldElement.fromList([ - -20902779, - 3296811, - 24736065, - -16328389, - 18374254, - 7318640, - 6295303, - 8082724, - -15362489, - 12339664 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 27724736, - 2291157, - 6088201, - -14184798, - 1792727, - 5857634, - 13848414, - 15768922, - 25091167, - 14856294 - ]), - FieldElement.fromList([ - -18866652, - 8331043, - 24373479, - 8541013, - -701998, - -9269457, - 12927300, - -12695493, - -22182473, - -9012899 - ]), - FieldElement.fromList([ - -11423429, - -5421590, - 11632845, - 3405020, - 30536730, - -11674039, - -27260765, - 13866390, - 30146206, - 9142070 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 3924129, - -15307516, - -13817122, - -10054960, - 12291820, - -668366, - -27702774, - 9326384, - -8237858, - 4171294 - ]), - FieldElement.fromList([ - -15921940, - 16037937, - 6713787, - 16606682, - -21612135, - 2790944, - 26396185, - 3731949, - 345228, - -5462949 - ]), - FieldElement.fromList([ - -21327538, - 13448259, - 25284571, - 1143661, - 20614966, - -8849387, - 2031539, - -12391231, - -16253183, - -13582083 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 31016211, - -16722429, - 26371392, - -14451233, - -5027349, - 14854137, - 17477601, - 3842657, - 28012650, - -16405420 - ]), - FieldElement.fromList([ - -5075835, - 9368966, - -8562079, - -4600902, - -15249953, - 6970560, - -9189873, - 16292057, - -8867157, - 3507940 - ]), - FieldElement.fromList([ - 29439664, - 3537914, - 23333589, - 6997794, - -17555561, - -11018068, - -15209202, - -15051267, - -9164929, - 6580396 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -12185861, - -7679788, - 16438269, - 10826160, - -8696817, - -6235611, - 17860444, - -9273846, - -2095802, - 9304567 - ]), - FieldElement.fromList([ - 20714564, - -4336911, - 29088195, - 7406487, - 11426967, - -5095705, - 14792667, - -14608617, - 5289421, - -477127 - ]), - FieldElement.fromList([ - -16665533, - -10650790, - -6160345, - -13305760, - 9192020, - -1802462, - 17271490, - 12349094, - 26939669, - -3752294 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -12889898, - 9373458, - 31595848, - 16374215, - 21471720, - 13221525, - -27283495, - -12348559, - -3698806, - 117887 - ]), - FieldElement.fromList([ - 22263325, - -6560050, - 3984570, - -11174646, - -15114008, - -566785, - 28311253, - 5358056, - -23319780, - 541964 - ]), - FieldElement.fromList([ - 16259219, - 3261970, - 2309254, - -15534474, - -16885711, - -4581916, - 24134070, - -16705829, - -13337066, - -13552195 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 9378160, - -13140186, - -22845982, - -12745264, - 28198281, - -7244098, - -2399684, - -717351, - 690426, - 14876244 - ]), - FieldElement.fromList([ - 24977353, - -314384, - -8223969, - -13465086, - 28432343, - -1176353, - -13068804, - -12297348, - -22380984, - 6618999 - ]), - FieldElement.fromList([ - -1538174, - 11685646, - 12944378, - 13682314, - -24389511, - -14413193, - 8044829, - -13817328, - 32239829, - -5652762 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -18603066, - 4762990, - -926250, - 8885304, - -28412480, - -3187315, - 9781647, - -10350059, - 32779359, - 5095274 - ]), - FieldElement.fromList([ - -33008130, - -5214506, - -32264887, - -3685216, - 9460461, - -9327423, - -24601656, - 14506724, - 21639561, - -2630236 - ]), - FieldElement.fromList([ - -16400943, - -13112215, - 25239338, - 15531969, - 3987758, - -4499318, - -1289502, - -6863535, - 17874574, - 558605 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -13600129, - 10240081, - 9171883, - 16131053, - -20869254, - 9599700, - 33499487, - 5080151, - 2085892, - 5119761 - ]), - FieldElement.fromList([ - -22205145, - -2519528, - -16381601, - 414691, - -25019550, - 2170430, - 30634760, - -8363614, - -31999993, - -5759884 - ]), - FieldElement.fromList([ - -6845704, - 15791202, - 8550074, - -1312654, - 29928809, - -12092256, - 27534430, - -7192145, - -22351378, - 12961482 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -24492060, - -9570771, - 10368194, - 11582341, - -23397293, - -2245287, - 16533930, - 8206996, - -30194652, - -5159638 - ]), - FieldElement.fromList([ - -11121496, - -3382234, - 2307366, - 6362031, - -135455, - 8868177, - -16835630, - 7031275, - 7589640, - 8945490 - ]), - FieldElement.fromList([ - -32152748, - 8917967, - 6661220, - -11677616, - -1192060, - -15793393, - 7251489, - -11182180, - 24099109, - -14456170 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 5019558, - -7907470, - 4244127, - -14714356, - -26933272, - 6453165, - -19118182, - -13289025, - -6231896, - -10280736 - ]), - FieldElement.fromList([ - 10853594, - 10721687, - 26480089, - 5861829, - -22995819, - 1972175, - -1866647, - -10557898, - -3363451, - -6441124 - ]), - FieldElement.fromList([ - -17002408, - 5906790, - 221599, - -6563147, - 7828208, - -13248918, - 24362661, - -2008168, - -13866408, - 7421392 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 8139927, - -6546497, - 32257646, - -5890546, - 30375719, - 1886181, - -21175108, - 15441252, - 28826358, - -4123029 - ]), - FieldElement.fromList([ - 6267086, - 9695052, - 7709135, - -16603597, - -32869068, - -1886135, - 14795160, - -7840124, - 13746021, - -1742048 - ]), - FieldElement.fromList([ - 28584902, - 7787108, - -6732942, - -15050729, - 22846041, - -7571236, - -3181936, - -363524, - 4771362, - -8419958 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 24949256, - 6376279, - -27466481, - -8174608, - -18646154, - -9930606, - 33543569, - -12141695, - 3569627, - 11342593 - ]), - FieldElement.fromList([ - 26514989, - 4740088, - 27912651, - 3697550, - 19331575, - -11472339, - 6809886, - 4608608, - 7325975, - -14801071 - ]), - FieldElement.fromList([ - -11618399, - -14554430, - -24321212, - 7655128, - -1369274, - 5214312, - -27400540, - 10258390, - -17646694, - -8186692 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 11431204, - 15823007, - 26570245, - 14329124, - 18029990, - 4796082, - -31446179, - 15580664, - 9280358, - -3973687 - ]), - FieldElement.fromList([ - -160783, - -10326257, - -22855316, - -4304997, - -20861367, - -13621002, - -32810901, - -11181622, - -15545091, - 4387441 - ]), - FieldElement.fromList([ - -20799378, - 12194512, - 3937617, - -5805892, - -27154820, - 9340370, - -24513992, - 8548137, - 20617071, - -7482001 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -938825, - -3930586, - -8714311, - 16124718, - 24603125, - -6225393, - -13775352, - -11875822, - 24345683, - 10325460 - ]), - FieldElement.fromList([ - -19855277, - -1568885, - -22202708, - 8714034, - 14007766, - 6928528, - 16318175, - -1010689, - 4766743, - 3552007 - ]), - FieldElement.fromList([ - -21751364, - -16730916, - 1351763, - -803421, - -4009670, - 3950935, - 3217514, - 14481909, - 10988822, - -3994762 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 15564307, - -14311570, - 3101243, - 5684148, - 30446780, - -8051356, - 12677127, - -6505343, - -8295852, - 13296005 - ]), - FieldElement.fromList([ - -9442290, - 6624296, - -30298964, - -11913677, - -4670981, - -2057379, - 31521204, - 9614054, - -30000824, - 12074674 - ]), - FieldElement.fromList([ - 4771191, - -135239, - 14290749, - -13089852, - 27992298, - 14998318, - -1413936, - -1556716, - 29832613, - -16391035 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 7064884, - -7541174, - -19161962, - -5067537, - -18891269, - -2912736, - 25825242, - 5293297, - -27122660, - 13101590 - ]), - FieldElement.fromList([ - -2298563, - 2439670, - -7466610, - 1719965, - -27267541, - -16328445, - 32512469, - -5317593, - -30356070, - -4190957 - ]), - FieldElement.fromList([ - -30006540, - 10162316, - -33180176, - 3981723, - -16482138, - -13070044, - 14413974, - 9515896, - 19568978, - 9628812 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 33053803, - 199357, - 15894591, - 1583059, - 27380243, - -4580435, - -17838894, - -6106839, - -6291786, - 3437740 - ]), - FieldElement.fromList([ - -18978877, - 3884493, - 19469877, - 12726490, - 15913552, - 13614290, - -22961733, - 70104, - 7463304, - 4176122 - ]), - FieldElement.fromList([ - -27124001, - 10659917, - 11482427, - -16070381, - 12771467, - -6635117, - -32719404, - -5322751, - 24216882, - 5944158 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 8894125, - 7450974, - -2664149, - -9765752, - -28080517, - -12389115, - 19345746, - 14680796, - 11632993, - 5847885 - ]), - FieldElement.fromList([ - 26942781, - -2315317, - 9129564, - -4906607, - 26024105, - 11769399, - -11518837, - 6367194, - -9727230, - 4782140 - ]), - FieldElement.fromList([ - 19916461, - -4828410, - -22910704, - -11414391, - 25606324, - -5972441, - 33253853, - 8220911, - 6358847, - -1873857 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 801428, - -2081702, - 16569428, - 11065167, - 29875704, - 96627, - 7908388, - -4480480, - -13538503, - 1387155 - ]), - FieldElement.fromList([ - 19646058, - 5720633, - -11416706, - 12814209, - 11607948, - 12749789, - 14147075, - 15156355, - -21866831, - 11835260 - ]), - FieldElement.fromList([ - 19299512, - 1155910, - 28703737, - 14890794, - 2925026, - 7269399, - 26121523, - 15467869, - -26560550, - 5052483 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -3017432, - 10058206, - 1980837, - 3964243, - 22160966, - 12322533, - -6431123, - -12618185, - 12228557, - -7003677 - ]), - FieldElement.fromList([ - 32944382, - 14922211, - -22844894, - 5188528, - 21913450, - -8719943, - 4001465, - 13238564, - -6114803, - 8653815 - ]), - FieldElement.fromList([ - 22865569, - -4652735, - 27603668, - -12545395, - 14348958, - 8234005, - 24808405, - 5719875, - 28483275, - 2841751 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -16420968, - -1113305, - -327719, - -12107856, - 21886282, - -15552774, - -1887966, - -315658, - 19932058, - -12739203 - ]), - FieldElement.fromList([ - -11656086, - 10087521, - -8864888, - -5536143, - -19278573, - -3055912, - 3999228, - 13239134, - -4777469, - -13910208 - ]), - FieldElement.fromList([ - 1382174, - -11694719, - 17266790, - 9194690, - -13324356, - 9720081, - 20403944, - 11284705, - -14013818, - 3093230 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 16650921, - -11037932, - -1064178, - 1570629, - -8329746, - 7352753, - -302424, - 16271225, - -24049421, - -6691850 - ]), - FieldElement.fromList([ - -21911077, - -5927941, - -4611316, - -5560156, - -31744103, - -10785293, - 24123614, - 15193618, - -21652117, - -16739389 - ]), - FieldElement.fromList([ - -9935934, - -4289447, - -25279823, - 4372842, - 2087473, - 10399484, - 31870908, - 14690798, - 17361620, - 11864968 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -11307610, - 6210372, - 13206574, - 5806320, - -29017692, - -13967200, - -12331205, - -7486601, - -25578460, - -16240689 - ]), - FieldElement.fromList([ - 14668462, - -12270235, - 26039039, - 15305210, - 25515617, - 4542480, - 10453892, - 6577524, - 9145645, - -6443880 - ]), - FieldElement.fromList([ - 5974874, - 3053895, - -9433049, - -10385191, - -31865124, - 3225009, - -7972642, - 3936128, - -5652273, - -3050304 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 30625386, - -4729400, - -25555961, - -12792866, - -20484575, - 7695099, - 17097188, - -16303496, - -27999779, - 1803632 - ]), - FieldElement.fromList([ - -3553091, - 9865099, - -5228566, - 4272701, - -5673832, - -16689700, - 14911344, - 12196514, - -21405489, - 7047412 - ]), - FieldElement.fromList([ - 20093277, - 9920966, - -11138194, - -5343857, - 13161587, - 12044805, - -32856851, - 4124601, - -32343828, - -10257566 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -20788824, - 14084654, - -13531713, - 7842147, - 19119038, - -13822605, - 4752377, - -8714640, - -21679658, - 2288038 - ]), - FieldElement.fromList([ - -26819236, - -3283715, - 29965059, - 3039786, - -14473765, - 2540457, - 29457502, - 14625692, - -24819617, - 12570232 - ]), - FieldElement.fromList([ - -1063558, - -11551823, - 16920318, - 12494842, - 1278292, - -5869109, - -21159943, - -3498680, - -11974704, - 4724943 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 17960970, - -11775534, - -4140968, - -9702530, - -8876562, - -1410617, - -12907383, - -8659932, - -29576300, - 1903856 - ]), - FieldElement.fromList([ - 23134274, - -14279132, - -10681997, - -1611936, - 20684485, - 15770816, - -12989750, - 3190296, - 26955097, - 14109738 - ]), - FieldElement.fromList([ - 15308788, - 5320727, - -30113809, - -14318877, - 22902008, - 7767164, - 29425325, - -11277562, - 31960942, - 11934971 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -27395711, - 8435796, - 4109644, - 12222639, - -24627868, - 14818669, - 20638173, - 4875028, - 10491392, - 1379718 - ]), - FieldElement.fromList([ - -13159415, - 9197841, - 3875503, - -8936108, - -1383712, - -5879801, - 33518459, - 16176658, - 21432314, - 12180697 - ]), - FieldElement.fromList([ - -11787308, - 11500838, - 13787581, - -13832590, - -22430679, - 10140205, - 1465425, - 12689540, - -10301319, - -13872883 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 5414091, - -15386041, - -21007664, - 9643570, - 12834970, - 1186149, - -2622916, - -1342231, - 26128231, - 6032912 - ]), - FieldElement.fromList([ - -26337395, - -13766162, - 32496025, - -13653919, - 17847801, - -12669156, - 3604025, - 8316894, - -25875034, - -10437358 - ]), - FieldElement.fromList([ - 3296484, - 6223048, - 24680646, - -12246460, - -23052020, - 5903205, - -8862297, - -4639164, - 12376617, - 3188849 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 29190488, - -14659046, - 27549113, - -1183516, - 3520066, - -10697301, - 32049515, - -7309113, - -16109234, - -9852307 - ]), - FieldElement.fromList([ - -14744486, - -9309156, - 735818, - -598978, - -20407687, - -5057904, - 25246078, - -15795669, - 18640741, - -960977 - ]), - FieldElement.fromList([ - -6928835, - -16430795, - 10361374, - 5642961, - 4910474, - 12345252, - -31638386, - -494430, - 10530747, - 1053335 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -29265967, - -14186805, - -13538216, - -12117373, - -19457059, - -10655384, - -31462369, - -2948985, - 24018831, - 15026644 - ]), - FieldElement.fromList([ - -22592535, - -3145277, - -2289276, - 5953843, - -13440189, - 9425631, - 25310643, - 13003497, - -2314791, - -15145616 - ]), - FieldElement.fromList([ - -27419985, - -603321, - -8043984, - -1669117, - -26092265, - 13987819, - -27297622, - 187899, - -23166419, - -2531735 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -21744398, - -13810475, - 1844840, - 5021428, - -10434399, - -15911473, - 9716667, - 16266922, - -5070217, - 726099 - ]), - FieldElement.fromList([ - 29370922, - -6053998, - 7334071, - -15342259, - 9385287, - 2247707, - -13661962, - -4839461, - 30007388, - -15823341 - ]), - FieldElement.fromList([ - -936379, - 16086691, - 23751945, - -543318, - -1167538, - -5189036, - 9137109, - 730663, - 9835848, - 4555336 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -23376435, - 1410446, - -22253753, - -12899614, - 30867635, - 15826977, - 17693930, - 544696, - -11985298, - 12422646 - ]), - FieldElement.fromList([ - 31117226, - -12215734, - -13502838, - 6561947, - -9876867, - -12757670, - -5118685, - -4096706, - 29120153, - 13924425 - ]), - FieldElement.fromList([ - -17400879, - -14233209, - 19675799, - -2734756, - -11006962, - -5858820, - -9383939, - -11317700, - 7240931, - -237388 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -31361739, - -11346780, - -15007447, - -5856218, - -22453340, - -12152771, - 1222336, - 4389483, - 3293637, - -15551743 - ]), - FieldElement.fromList([ - -16684801, - -14444245, - 11038544, - 11054958, - -13801175, - -3338533, - -24319580, - 7733547, - 12796905, - -6335822 - ]), - FieldElement.fromList([ - -8759414, - -10817836, - -25418864, - 10783769, - -30615557, - -9746811, - -28253339, - 3647836, - 3222231, - -11160462 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 18606113, - 1693100, - -25448386, - -15170272, - 4112353, - 10045021, - 23603893, - -2048234, - -7550776, - 2484985 - ]), - FieldElement.fromList([ - 9255317, - -3131197, - -12156162, - -1004256, - 13098013, - -9214866, - 16377220, - -2102812, - -19802075, - -3034702 - ]), - FieldElement.fromList([ - -22729289, - 7496160, - -5742199, - 11329249, - 19991973, - -3347502, - -31718148, - 9936966, - -30097688, - -10618797 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 21878590, - -5001297, - 4338336, - 13643897, - -3036865, - 13160960, - 19708896, - 5415497, - -7360503, - -4109293 - ]), - FieldElement.fromList([ - 27736861, - 10103576, - 12500508, - 8502413, - -3413016, - -9633558, - 10436918, - -1550276, - -23659143, - -8132100 - ]), - FieldElement.fromList([ - 19492550, - -12104365, - -29681976, - -852630, - -3208171, - 12403437, - 30066266, - 8367329, - 13243957, - 8709688 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 12015105, - 2801261, - 28198131, - 10151021, - 24818120, - -4743133, - -11194191, - -5645734, - 5150968, - 7274186 - ]), - FieldElement.fromList([ - 2831366, - -12492146, - 1478975, - 6122054, - 23825128, - -12733586, - 31097299, - 6083058, - 31021603, - -9793610 - ]), - FieldElement.fromList([ - -2529932, - -2229646, - 445613, - 10720828, - -13849527, - -11505937, - -23507731, - 16354465, - 15067285, - -14147707 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 7840942, - 14037873, - -33364863, - 15934016, - -728213, - -3642706, - 21403988, - 1057586, - -19379462, - -12403220 - ]), - FieldElement.fromList([ - 915865, - -16469274, - 15608285, - -8789130, - -24357026, - 6060030, - -17371319, - 8410997, - -7220461, - 16527025 - ]), - FieldElement.fromList([ - 32922597, - -556987, - 20336074, - -16184568, - 10903705, - -5384487, - 16957574, - 52992, - 23834301, - 6588044 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 32752030, - 11232950, - 3381995, - -8714866, - 22652988, - -10744103, - 17159699, - 16689107, - -20314580, - -1305992 - ]), - FieldElement.fromList([ - -4689649, - 9166776, - -25710296, - -10847306, - 11576752, - 12733943, - 7924251, - -2752281, - 1976123, - -7249027 - ]), - FieldElement.fromList([ - 21251222, - 16309901, - -2983015, - -6783122, - 30810597, - 12967303, - 156041, - -3371252, - 12331345, - -8237197 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 8651614, - -4477032, - -16085636, - -4996994, - 13002507, - 2950805, - 29054427, - -5106970, - 10008136, - -4667901 - ]), - FieldElement.fromList([ - 31486080, - 15114593, - -14261250, - 12951354, - 14369431, - -7387845, - 16347321, - -13662089, - 8684155, - -10532952 - ]), - FieldElement.fromList([ - 19443825, - 11385320, - 24468943, - -9659068, - -23919258, - 2187569, - -26263207, - -6086921, - 31316348, - 14219878 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -28594490, - 1193785, - 32245219, - 11392485, - 31092169, - 15722801, - 27146014, - 6992409, - 29126555, - 9207390 - ]), - FieldElement.fromList([ - 32382935, - 1110093, - 18477781, - 11028262, - -27411763, - -7548111, - -4980517, - 10843782, - -7957600, - -14435730 - ]), - FieldElement.fromList([ - 2814918, - 7836403, - 27519878, - -7868156, - -20894015, - -11553689, - -21494559, - 8550130, - 28346258, - 1994730 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -19578299, - 8085545, - -14000519, - -3948622, - 2785838, - -16231307, - -19516951, - 7174894, - 22628102, - 8115180 - ]), - FieldElement.fromList([ - -30405132, - 955511, - -11133838, - -15078069, - -32447087, - -13278079, - -25651578, - 3317160, - -9943017, - 930272 - ]), - FieldElement.fromList([ - -15303681, - -6833769, - 28856490, - 1357446, - 23421993, - 1057177, - 24091212, - -1388970, - -22765376, - -10650715 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -22751231, - -5303997, - -12907607, - -12768866, - -15811511, - -7797053, - -14839018, - -16554220, - -1867018, - 8398970 - ]), - FieldElement.fromList([ - -31969310, - 2106403, - -4736360, - 1362501, - 12813763, - 16200670, - 22981545, - -6291273, - 18009408, - -15772772 - ]), - FieldElement.fromList([ - -17220923, - -9545221, - -27784654, - 14166835, - 29815394, - 7444469, - 29551787, - -3727419, - 19288549, - 1325865 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 15100157, - -15835752, - -23923978, - -1005098, - -26450192, - 15509408, - 12376730, - -3479146, - 33166107, - -8042750 - ]), - FieldElement.fromList([ - 20909231, - 13023121, - -9209752, - 16251778, - -5778415, - -8094914, - 12412151, - 10018715, - 2213263, - -13878373 - ]), - FieldElement.fromList([ - 32529814, - -11074689, - 30361439, - -16689753, - -9135940, - 1513226, - 22922121, - 6382134, - -5766928, - 8371348 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 9923462, - 11271500, - 12616794, - 3544722, - -29998368, - -1721626, - 12891687, - -8193132, - -26442943, - 10486144 - ]), - FieldElement.fromList([ - -22597207, - -7012665, - 8587003, - -8257861, - 4084309, - -12970062, - 361726, - 2610596, - -23921530, - -11455195 - ]), - FieldElement.fromList([ - 5408411, - -1136691, - -4969122, - 10561668, - 24145918, - 14240566, - 31319731, - -4235541, - 19985175, - -3436086 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -13994457, - 16616821, - 14549246, - 3341099, - 32155958, - 13648976, - -17577068, - 8849297, - 65030, - 8370684 - ]), - FieldElement.fromList([ - -8320926, - -12049626, - 31204563, - 5839400, - -20627288, - -1057277, - -19442942, - 6922164, - 12743482, - -9800518 - ]), - FieldElement.fromList([ - -2361371, - 12678785, - 28815050, - 4759974, - -23893047, - 4884717, - 23783145, - 11038569, - 18800704, - 255233 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -5269658, - -1773886, - 13957886, - 7990715, - 23132995, - 728773, - 13393847, - 9066957, - 19258688, - -14753793 - ]), - FieldElement.fromList([ - -2936654, - -10827535, - -10432089, - 14516793, - -3640786, - 4372541, - -31934921, - 2209390, - -1524053, - 2055794 - ]), - FieldElement.fromList([ - 580882, - 16705327, - 5468415, - -2683018, - -30926419, - -14696000, - -7203346, - -8994389, - -30021019, - 7394435 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 23838809, - 1822728, - -15738443, - 15242727, - 8318092, - -3733104, - -21672180, - -3492205, - -4821741, - 14799921 - ]), - FieldElement.fromList([ - 13345610, - 9759151, - 3371034, - -16137791, - 16353039, - 8577942, - 31129804, - 13496856, - -9056018, - 7402518 - ]), - FieldElement.fromList([ - 2286874, - -4435931, - -20042458, - -2008336, - -13696227, - 5038122, - 11006906, - -15760352, - 8205061, - 1607563 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 14414086, - -8002132, - 3331830, - -3208217, - 22249151, - -5594188, - 18364661, - -2906958, - 30019587, - -9029278 - ]), - FieldElement.fromList([ - -27688051, - 1585953, - -10775053, - 931069, - -29120221, - -11002319, - -14410829, - 12029093, - 9944378, - 8024 - ]), - FieldElement.fromList([ - 4368715, - -3709630, - 29874200, - -15022983, - -20230386, - -11410704, - -16114594, - -999085, - -8142388, - 5640030 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 10299610, - 13746483, - 11661824, - 16234854, - 7630238, - 5998374, - 9809887, - -16694564, - 15219798, - -14327783 - ]), - FieldElement.fromList([ - 27425505, - -5719081, - 3055006, - 10660664, - 23458024, - 595578, - -15398605, - -1173195, - -18342183, - 9742717 - ]), - FieldElement.fromList([ - 6744077, - 2427284, - 26042789, - 2720740, - -847906, - 1118974, - 32324614, - 7406442, - 12420155, - 1994844 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 14012521, - -5024720, - -18384453, - -9578469, - -26485342, - -3936439, - -13033478, - -10909803, - 24319929, - -6446333 - ]), - FieldElement.fromList([ - 16412690, - -4507367, - 10772641, - 15929391, - -17068788, - -4658621, - 10555945, - -10484049, - -30102368, - -4739048 - ]), - FieldElement.fromList([ - 22397382, - -7767684, - -9293161, - -12792868, - 17166287, - -9755136, - -27333065, - 6199366, - 21880021, - -12250760 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -4283307, - 5368523, - -31117018, - 8163389, - -30323063, - 3209128, - 16557151, - 8890729, - 8840445, - 4957760 - ]), - FieldElement.fromList([ - -15447727, - 709327, - -6919446, - -10870178, - -29777922, - 6522332, - -21720181, - 12130072, - -14796503, - 5005757 - ]), - FieldElement.fromList([ - -2114751, - -14308128, - 23019042, - 15765735, - -25269683, - 6002752, - 10183197, - -13239326, - -16395286, - -2176112 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -19025756, - 1632005, - 13466291, - -7995100, - -23640451, - 16573537, - -32013908, - -3057104, - 22208662, - 2000468 - ]), - FieldElement.fromList([ - 3065073, - -1412761, - -25598674, - -361432, - -17683065, - -5703415, - -8164212, - 11248527, - -3691214, - -7414184 - ]), - FieldElement.fromList([ - 10379208, - -6045554, - 8877319, - 1473647, - -29291284, - -12507580, - 16690915, - 2553332, - -3132688, - 16400289 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 15716668, - 1254266, - -18472690, - 7446274, - -8448918, - 6344164, - -22097271, - -7285580, - 26894937, - 9132066 - ]), - FieldElement.fromList([ - 24158887, - 12938817, - 11085297, - -8177598, - -28063478, - -4457083, - -30576463, - 64452, - -6817084, - -2692882 - ]), - FieldElement.fromList([ - 13488534, - 7794716, - 22236231, - 5989356, - 25426474, - -12578208, - 2350710, - -3418511, - -4688006, - 2364226 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 16335052, - 9132434, - 25640582, - 6678888, - 1725628, - 8517937, - -11807024, - -11697457, - 15445875, - -7798101 - ]), - FieldElement.fromList([ - 29004207, - -7867081, - 28661402, - -640412, - -12794003, - -7943086, - 31863255, - -4135540, - -278050, - -15759279 - ]), - FieldElement.fromList([ - -6122061, - -14866665, - -28614905, - 14569919, - -10857999, - -3591829, - 10343412, - -6976290, - -29828287, - -10815811 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 27081650, - 3463984, - 14099042, - -4517604, - 1616303, - -6205604, - 29542636, - 15372179, - 17293797, - 960709 - ]), - FieldElement.fromList([ - 20263915, - 11434237, - -5765435, - 11236810, - 13505955, - -10857102, - -16111345, - 6493122, - -19384511, - 7639714 - ]), - FieldElement.fromList([ - -2830798, - -14839232, - 25403038, - -8215196, - -8317012, - -16173699, - 18006287, - -16043750, - 29994677, - -15808121 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 9769828, - 5202651, - -24157398, - -13631392, - -28051003, - -11561624, - -24613141, - -13860782, - -31184575, - 709464 - ]), - FieldElement.fromList([ - 12286395, - 13076066, - -21775189, - -1176622, - -25003198, - 4057652, - -32018128, - -8890874, - 16102007, - 13205847 - ]), - FieldElement.fromList([ - 13733362, - 5599946, - 10557076, - 3195751, - -5557991, - 8536970, - -25540170, - 8525972, - 10151379, - 10394400 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 4024660, - -16137551, - 22436262, - 12276534, - -9099015, - -2686099, - 19698229, - 11743039, - -33302334, - 8934414 - ]), - FieldElement.fromList([ - -15879800, - -4525240, - -8580747, - -2934061, - 14634845, - -698278, - -9449077, - 3137094, - -11536886, - 11721158 - ]), - FieldElement.fromList([ - 17555939, - -5013938, - 8268606, - 2331751, - -22738815, - 9761013, - 9319229, - 8835153, - -9205489, - -1280045 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -461409, - -7830014, - 20614118, - 16688288, - -7514766, - -4807119, - 22300304, - 505429, - 6108462, - -6183415 - ]), - FieldElement.fromList([ - -5070281, - 12367917, - -30663534, - 3234473, - 32617080, - -8422642, - 29880583, - -13483331, - -26898490, - -7867459 - ]), - FieldElement.fromList([ - -31975283, - 5726539, - 26934134, - 10237677, - -3173717, - -605053, - 24199304, - 3795095, - 7592688, - -14992079 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 21594432, - -14964228, - 17466408, - -4077222, - 32537084, - 2739898, - 6407723, - 12018833, - -28256052, - 4298412 - ]), - FieldElement.fromList([ - -20650503, - -11961496, - -27236275, - 570498, - 3767144, - -1717540, - 13891942, - -1569194, - 13717174, - 10805743 - ]), - FieldElement.fromList([ - -14676630, - -15644296, - 15287174, - 11927123, - 24177847, - -8175568, - -796431, - 14860609, - -26938930, - -5863836 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 12962541, - 5311799, - -10060768, - 11658280, - 18855286, - -7954201, - 13286263, - -12808704, - -4381056, - 9882022 - ]), - FieldElement.fromList([ - 18512079, - 11319350, - -20123124, - 15090309, - 18818594, - 5271736, - -22727904, - 3666879, - -23967430, - -3299429 - ]), - FieldElement.fromList([ - -6789020, - -3146043, - 16192429, - 13241070, - 15898607, - -14206114, - -10084880, - -6661110, - -2403099, - 5276065 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 30169808, - -5317648, - 26306206, - -11750859, - 27814964, - 7069267, - 7152851, - 3684982, - 1449224, - 13082861 - ]), - FieldElement.fromList([ - 10342826, - 3098505, - 2119311, - 193222, - 25702612, - 12233820, - 23697382, - 15056736, - -21016438, - -8202000 - ]), - FieldElement.fromList([ - -33150110, - 3261608, - 22745853, - 7948688, - 19370557, - -15177665, - -26171976, - 6482814, - -10300080, - -11060101 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 32869458, - -5408545, - 25609743, - 15678670, - -10687769, - -15471071, - 26112421, - 2521008, - -22664288, - 6904815 - ]), - FieldElement.fromList([ - 29506923, - 4457497, - 3377935, - -9796444, - -30510046, - 12935080, - 1561737, - 3841096, - -29003639, - -6657642 - ]), - FieldElement.fromList([ - 10340844, - -6630377, - -18656632, - -2278430, - 12621151, - -13339055, - 30878497, - -11824370, - -25584551, - 5181966 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 25940115, - -12658025, - 17324188, - -10307374, - -8671468, - 15029094, - 24396252, - -16450922, - -2322852, - -12388574 - ]), - FieldElement.fromList([ - -21765684, - 9916823, - -1300409, - 4079498, - -1028346, - 11909559, - 1782390, - 12641087, - 20603771, - -6561742 - ]), - FieldElement.fromList([ - -18882287, - -11673380, - 24849422, - 11501709, - 13161720, - -4768874, - 1925523, - 11914390, - 4662781, - 7820689 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 12241050, - -425982, - 8132691, - 9393934, - 32846760, - -1599620, - 29749456, - 12172924, - 16136752, - 15264020 - ]), - FieldElement.fromList([ - -10349955, - -14680563, - -8211979, - 2330220, - -17662549, - -14545780, - 10658213, - 6671822, - 19012087, - 3772772 - ]), - FieldElement.fromList([ - 3753511, - -3421066, - 10617074, - 2028709, - 14841030, - -6721664, - 28718732, - -15762884, - 20527771, - 12988982 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -14822485, - -5797269, - -3707987, - 12689773, - -898983, - -10914866, - -24183046, - -10564943, - 3299665, - -12424953 - ]), - FieldElement.fromList([ - -16777703, - -15253301, - -9642417, - 4978983, - 3308785, - 8755439, - 6943197, - 6461331, - -25583147, - 8991218 - ]), - FieldElement.fromList([ - -17226263, - 1816362, - -1673288, - -6086439, - 31783888, - -8175991, - -32948145, - 7417950, - -30242287, - 1507265 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 29692663, - 6829891, - -10498800, - 4334896, - 20945975, - -11906496, - -28887608, - 8209391, - 14606362, - -10647073 - ]), - FieldElement.fromList([ - -3481570, - 8707081, - 32188102, - 5672294, - 22096700, - 1711240, - -33020695, - 9761487, - 4170404, - -2085325 - ]), - FieldElement.fromList([ - -11587470, - 14855945, - -4127778, - -1531857, - -26649089, - 15084046, - 22186522, - 16002000, - -14276837, - -8400798 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -4811456, - 13761029, - -31703877, - -2483919, - -3312471, - 7869047, - -7113572, - -9620092, - 13240845, - 10965870 - ]), - FieldElement.fromList([ - -7742563, - -8256762, - -14768334, - -13656260, - -23232383, - 12387166, - 4498947, - 14147411, - 29514390, - 4302863 - ]), - FieldElement.fromList([ - -13413405, - -12407859, - 20757302, - -13801832, - 14785143, - 8976368, - -5061276, - -2144373, - 17846988, - -13971927 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -2244452, - -754728, - -4597030, - -1066309, - -6247172, - 1455299, - -21647728, - -9214789, - -5222701, - 12650267 - ]), - FieldElement.fromList([ - -9906797, - -16070310, - 21134160, - 12198166, - -27064575, - 708126, - 387813, - 13770293, - -19134326, - 10958663 - ]), - FieldElement.fromList([ - 22470984, - 12369526, - 23446014, - -5441109, - -21520802, - -9698723, - -11772496, - -11574455, - -25083830, - 4271862 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -25169565, - -10053642, - -19909332, - 15361595, - -5984358, - 2159192, - 75375, - -4278529, - -32526221, - 8469673 - ]), - FieldElement.fromList([ - 15854970, - 4148314, - -8893890, - 7259002, - 11666551, - 13824734, - -30531198, - 2697372, - 24154791, - -9460943 - ]), - FieldElement.fromList([ - 15446137, - -15806644, - 29759747, - 14019369, - 30811221, - -9610191, - -31582008, - 12840104, - 24913809, - 9815020 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -4709286, - -5614269, - -31841498, - -12288893, - -14443537, - 10799414, - -9103676, - 13438769, - 18735128, - 9466238 - ]), - FieldElement.fromList([ - 11933045, - 9281483, - 5081055, - -5183824, - -2628162, - -4905629, - -7727821, - -10896103, - -22728655, - 16199064 - ]), - FieldElement.fromList([ - 14576810, - 379472, - -26786533, - -8317236, - -29426508, - -10812974, - -102766, - 1876699, - 30801119, - 2164795 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 15995086, - 3199873, - 13672555, - 13712240, - -19378835, - -4647646, - -13081610, - -15496269, - -13492807, - 1268052 - ]), - FieldElement.fromList([ - -10290614, - -3659039, - -3286592, - 10948818, - 23037027, - 3794475, - -3470338, - -12600221, - -17055369, - 3565904 - ]), - FieldElement.fromList([ - 29210088, - -9419337, - -5919792, - -4952785, - 10834811, - -13327726, - -16512102, - -10820713, - -27162222, - -14030531 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -13161890, - 15508588, - 16663704, - -8156150, - -28349942, - 9019123, - -29183421, - -3769423, - 2244111, - -14001979 - ]), - FieldElement.fromList([ - -5152875, - -3800936, - -9306475, - -6071583, - 16243069, - 14684434, - -25673088, - -16180800, - 13491506, - 4641841 - ]), - FieldElement.fromList([ - 10813417, - 643330, - -19188515, - -728916, - 30292062, - -16600078, - 27548447, - -7721242, - 14476989, - -12767431 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 10292079, - 9984945, - 6481436, - 8279905, - -7251514, - 7032743, - 27282937, - -1644259, - -27912810, - 12651324 - ]), - FieldElement.fromList([ - -31185513, - -813383, - 22271204, - 11835308, - 10201545, - 15351028, - 17099662, - 3988035, - 21721536, - -3148940 - ]), - FieldElement.fromList([ - 10202177, - -6545839, - -31373232, - -9574638, - -32150642, - -8119683, - -12906320, - 3852694, - 13216206, - 14842320 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -15815640, - -10601066, - -6538952, - -7258995, - -6984659, - -6581778, - -31500847, - 13765824, - -27434397, - 9900184 - ]), - FieldElement.fromList([ - 14465505, - -13833331, - -32133984, - -14738873, - -27443187, - 12990492, - 33046193, - 15796406, - -7051866, - -8040114 - ]), - FieldElement.fromList([ - 30924417, - -8279620, - 6359016, - -12816335, - 16508377, - 9071735, - -25488601, - 15413635, - 9524356, - -7018878 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 12274201, - -13175547, - 32627641, - -1785326, - 6736625, - 13267305, - 5237659, - -5109483, - 15663516, - 4035784 - ]), - FieldElement.fromList([ - -2951309, - 8903985, - 17349946, - 601635, - -16432815, - -4612556, - -13732739, - -15889334, - -22258478, - 4659091 - ]), - FieldElement.fromList([ - -16916263, - -4952973, - -30393711, - -15158821, - 20774812, - 15897498, - 5736189, - 15026997, - -2178256, - -13455585 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -8858980, - -2219056, - 28571666, - -10155518, - -474467, - -10105698, - -3801496, - 278095, - 23440562, - -290208 - ]), - FieldElement.fromList([ - 10226241, - -5928702, - 15139956, - 120818, - -14867693, - 5218603, - 32937275, - 11551483, - -16571960, - -7442864 - ]), - FieldElement.fromList([ - 17932739, - -12437276, - -24039557, - 10749060, - 11316803, - 7535897, - 22503767, - 5561594, - -3646624, - 3898661 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 7749907, - -969567, - -16339731, - -16464, - -25018111, - 15122143, - -1573531, - 7152530, - 21831162, - 1245233 - ]), - FieldElement.fromList([ - 26958459, - -14658026, - 4314586, - 8346991, - -5677764, - 11960072, - -32589295, - -620035, - -30402091, - -16716212 - ]), - FieldElement.fromList([ - -12165896, - 9166947, - 33491384, - 13673479, - 29787085, - 13096535, - 6280834, - 14587357, - -22338025, - 13987525 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -24349909, - 7778775, - 21116000, - 15572597, - -4833266, - -5357778, - -4300898, - -5124639, - -7469781, - -2858068 - ]), - FieldElement.fromList([ - 9681908, - -6737123, - -31951644, - 13591838, - -6883821, - 386950, - 31622781, - 6439245, - -14581012, - 4091397 - ]), - FieldElement.fromList([ - -8426427, - 1470727, - -28109679, - -1596990, - 3978627, - -5123623, - -19622683, - 12092163, - 29077877, - -14741988 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 5269168, - -6859726, - -13230211, - -8020715, - 25932563, - 1763552, - -5606110, - -5505881, - -20017847, - 2357889 - ]), - FieldElement.fromList([ - 32264008, - -15407652, - -5387735, - -1160093, - -2091322, - -3946900, - 23104804, - -12869908, - 5727338, - 189038 - ]), - FieldElement.fromList([ - 14609123, - -8954470, - -6000566, - -16622781, - -14577387, - -7743898, - -26745169, - 10942115, - -25888931, - -14884697 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 20513500, - 5557931, - -15604613, - 7829531, - 26413943, - -2019404, - -21378968, - 7471781, - 13913677, - -5137875 - ]), - FieldElement.fromList([ - -25574376, - 11967826, - 29233242, - 12948236, - -6754465, - 4713227, - -8940970, - 14059180, - 12878652, - 8511905 - ]), - FieldElement.fromList([ - -25656801, - 3393631, - -2955415, - -7075526, - -2250709, - 9366908, - -30223418, - 6812974, - 5568676, - -3127656 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 11630004, - 12144454, - 2116339, - 13606037, - 27378885, - 15676917, - -17408753, - -13504373, - -14395196, - 8070818 - ]), - FieldElement.fromList([ - 27117696, - -10007378, - -31282771, - -5570088, - 1127282, - 12772488, - -29845906, - 10483306, - -11552749, - -1028714 - ]), - FieldElement.fromList([ - 10637467, - -5688064, - 5674781, - 1072708, - -26343588, - -6982302, - -1683975, - 9177853, - -27493162, - 15431203 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 20525145, - 10892566, - -12742472, - 12779443, - -29493034, - 16150075, - -28240519, - 14943142, - -15056790, - -7935931 - ]), - FieldElement.fromList([ - -30024462, - 5626926, - -551567, - -9981087, - 753598, - 11981191, - 25244767, - -3239766, - -3356550, - 9594024 - ]), - FieldElement.fromList([ - -23752644, - 2636870, - -5163910, - -10103818, - 585134, - 7877383, - 11345683, - -6492290, - 13352335, - -10977084 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -1931799, - -5407458, - 3304649, - -12884869, - 17015806, - -4877091, - -29783850, - -7752482, - -13215537, - -319204 - ]), - FieldElement.fromList([ - 20239939, - 6607058, - 6203985, - 3483793, - -18386976, - -779229, - -20723742, - 15077870, - -22750759, - 14523817 - ]), - FieldElement.fromList([ - 27406042, - -6041657, - 27423596, - -4497394, - 4996214, - 10002360, - -28842031, - -4545494, - -30172742, - -4805667 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 11374242, - 12660715, - 17861383, - -12540833, - 10935568, - 1099227, - -13886076, - -9091740, - -27727044, - 11358504 - ]), - FieldElement.fromList([ - -12730809, - 10311867, - 1510375, - 10778093, - -2119455, - -9145702, - 32676003, - 11149336, - -26123651, - 4985768 - ]), - FieldElement.fromList([ - -19096303, - 341147, - -6197485, - -239033, - 15756973, - -8796662, - -983043, - 13794114, - -19414307, - -15621255 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 6490081, - 11940286, - 25495923, - -7726360, - 8668373, - -8751316, - 3367603, - 6970005, - -1691065, - -9004790 - ]), - FieldElement.fromList([ - 1656497, - 13457317, - 15370807, - 6364910, - 13605745, - 8362338, - -19174622, - -5475723, - -16796596, - -5031438 - ]), - FieldElement.fromList([ - -22273315, - -13524424, - -64685, - -4334223, - -18605636, - -10921968, - -20571065, - -7007978, - -99853, - -10237333 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 17747465, - 10039260, - 19368299, - -4050591, - -20630635, - -16041286, - 31992683, - -15857976, - -29260363, - -5511971 - ]), - FieldElement.fromList([ - 31932027, - -4986141, - -19612382, - 16366580, - 22023614, - 88450, - 11371999, - -3744247, - 4882242, - -10626905 - ]), - FieldElement.fromList([ - 29796507, - 37186, - 19818052, - 10115756, - -11829032, - 3352736, - 18551198, - 3272828, - -5190932, - -4162409 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 12501286, - 4044383, - -8612957, - -13392385, - -32430052, - 5136599, - -19230378, - -3529697, - 330070, - -3659409 - ]), - FieldElement.fromList([ - 6384877, - 2899513, - 17807477, - 7663917, - -2358888, - 12363165, - 25366522, - -8573892, - -271295, - 12071499 - ]), - FieldElement.fromList([ - -8365515, - -4042521, - 25133448, - -4517355, - -6211027, - 2265927, - -32769618, - 1936675, - -5159697, - 3829363 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 28425966, - -5835433, - -577090, - -4697198, - -14217555, - 6870930, - 7921550, - -6567787, - 26333140, - 14267664 - ]), - FieldElement.fromList([ - -11067219, - 11871231, - 27385719, - -10559544, - -4585914, - -11189312, - 10004786, - -8709488, - -21761224, - 8930324 - ]), - FieldElement.fromList([ - -21197785, - -16396035, - 25654216, - -1725397, - 12282012, - 11008919, - 1541940, - 4757911, - -26491501, - -16408940 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 13537262, - -7759490, - -20604840, - 10961927, - -5922820, - -13218065, - -13156584, - 6217254, - -15943699, - 13814990 - ]), - FieldElement.fromList([ - -17422573, - 15157790, - 18705543, - 29619, - 24409717, - -260476, - 27361681, - 9257833, - -1956526, - -1776914 - ]), - FieldElement.fromList([ - -25045300, - -10191966, - 15366585, - 15166509, - -13105086, - 8423556, - -29171540, - 12361135, - -18685978, - 4578290 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 24579768, - 3711570, - 1342322, - -11180126, - -27005135, - 14124956, - -22544529, - 14074919, - 21964432, - 8235257 - ]), - FieldElement.fromList([ - -6528613, - -2411497, - 9442966, - -5925588, - 12025640, - -1487420, - -2981514, - -1669206, - 13006806, - 2355433 - ]), - FieldElement.fromList([ - -16304899, - -13605259, - -6632427, - -5142349, - 16974359, - -10911083, - 27202044, - 1719366, - 1141648, - -12796236 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -12863944, - -13219986, - -8318266, - -11018091, - -6810145, - -4843894, - 13475066, - -3133972, - 32674895, - 13715045 - ]), - FieldElement.fromList([ - 11423335, - -5468059, - 32344216, - 8962751, - 24989809, - 9241752, - -13265253, - 16086212, - -28740881, - -15642093 - ]), - FieldElement.fromList([ - -1409668, - 12530728, - -6368726, - 10847387, - 19531186, - -14132160, - -11709148, - 7791794, - -27245943, - 4383347 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -28970898, - 5271447, - -1266009, - -9736989, - -12455236, - 16732599, - -4862407, - -4906449, - 27193557, - 6245191 - ]), - FieldElement.fromList([ - -15193956, - 5362278, - -1783893, - 2695834, - 4960227, - 12840725, - 23061898, - 3260492, - 22510453, - 8577507 - ]), - FieldElement.fromList([ - -12632451, - 11257346, - -32692994, - 13548177, - -721004, - 10879011, - 31168030, - 13952092, - -29571492, - -3635906 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 3877321, - -9572739, - 32416692, - 5405324, - -11004407, - -13656635, - 3759769, - 11935320, - 5611860, - 8164018 - ]), - FieldElement.fromList([ - -16275802, - 14667797, - 15906460, - 12155291, - -22111149, - -9039718, - 32003002, - -8832289, - 5773085, - -8422109 - ]), - FieldElement.fromList([ - -23788118, - -8254300, - 1950875, - 8937633, - 18686727, - 16459170, - -905725, - 12376320, - 31632953, - 190926 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -24593607, - -16138885, - -8423991, - 13378746, - 14162407, - 6901328, - -8288749, - 4508564, - -25341555, - -3627528 - ]), - FieldElement.fromList([ - 8884438, - -5884009, - 6023974, - 10104341, - -6881569, - -4941533, - 18722941, - -14786005, - -1672488, - 827625 - ]), - FieldElement.fromList([ - -32720583, - -16289296, - -32503547, - 7101210, - 13354605, - 2659080, - -1800575, - -14108036, - -24878478, - 1541286 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 2901347, - -1117687, - 3880376, - -10059388, - -17620940, - -3612781, - -21802117, - -3567481, - 20456845, - -1885033 - ]), - FieldElement.fromList([ - 27019610, - 12299467, - -13658288, - -1603234, - -12861660, - -4861471, - -19540150, - -5016058, - 29439641, - 15138866 - ]), - FieldElement.fromList([ - 21536104, - -6626420, - -32447818, - -10690208, - -22408077, - 5175814, - -5420040, - -16361163, - 7779328, - 109896 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 30279744, - 14648750, - -8044871, - 6425558, - 13639621, - -743509, - 28698390, - 12180118, - 23177719, - -554075 - ]), - FieldElement.fromList([ - 26572847, - 3405927, - -31701700, - 12890905, - -19265668, - 5335866, - -6493768, - 2378492, - 4439158, - -13279347 - ]), - FieldElement.fromList([ - -22716706, - 3489070, - -9225266, - -332753, - 18875722, - -1140095, - 14819434, - -12731527, - -17717757, - -5461437 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -5056483, - 16566551, - 15953661, - 3767752, - -10436499, - 15627060, - -820954, - 2177225, - 8550082, - -15114165 - ]), - FieldElement.fromList([ - -18473302, - 16596775, - -381660, - 15663611, - 22860960, - 15585581, - -27844109, - -3582739, - -23260460, - -8428588 - ]), - FieldElement.fromList([ - -32480551, - 15707275, - -8205912, - -5652081, - 29464558, - 2713815, - -22725137, - 15860482, - -21902570, - 1494193 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -19562091, - -14087393, - -25583872, - -9299552, - 13127842, - 759709, - 21923482, - 16529112, - 8742704, - 12967017 - ]), - FieldElement.fromList([ - -28464899, - 1553205, - 32536856, - -10473729, - -24691605, - -406174, - -8914625, - -2933896, - -29903758, - 15553883 - ]), - FieldElement.fromList([ - 21877909, - 3230008, - 9881174, - 10539357, - -4797115, - 2841332, - 11543572, - 14513274, - 19375923, - -12647961 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 8832269, - -14495485, - 13253511, - 5137575, - 5037871, - 4078777, - 24880818, - -6222716, - 2862653, - 9455043 - ]), - FieldElement.fromList([ - 29306751, - 5123106, - 20245049, - -14149889, - 9592566, - 8447059, - -2077124, - -2990080, - 15511449, - 4789663 - ]), - FieldElement.fromList([ - -20679756, - 7004547, - 8824831, - -9434977, - -4045704, - -3750736, - -5754762, - 108893, - 23513200, - 16652362 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -33256173, - 4144782, - -4476029, - -6579123, - 10770039, - -7155542, - -6650416, - -12936300, - -18319198, - 10212860 - ]), - FieldElement.fromList([ - 2756081, - 8598110, - 7383731, - -6859892, - 22312759, - -1105012, - 21179801, - 2600940, - -9988298, - -12506466 - ]), - FieldElement.fromList([ - -24645692, - 13317462, - -30449259, - -15653928, - 21365574, - -10869657, - 11344424, - 864440, - -2499677, - -16710063 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -26432803, - 6148329, - -17184412, - -14474154, - 18782929, - -275997, - -22561534, - 211300, - 2719757, - 4940997 - ]), - FieldElement.fromList([ - -1323882, - 3911313, - -6948744, - 14759765, - -30027150, - 7851207, - 21690126, - 8518463, - 26699843, - 5276295 - ]), - FieldElement.fromList([ - -13149873, - -6429067, - 9396249, - 365013, - 24703301, - -10488939, - 1321586, - 149635, - -15452774, - 7159369 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 9987780, - -3404759, - 17507962, - 9505530, - 9731535, - -2165514, - 22356009, - 8312176, - 22477218, - -8403385 - ]), - FieldElement.fromList([ - 18155857, - -16504990, - 19744716, - 9006923, - 15154154, - -10538976, - 24256460, - -4864995, - -22548173, - 9334109 - ]), - FieldElement.fromList([ - 2986088, - -4911893, - 10776628, - -3473844, - 10620590, - -7083203, - -21413845, - 14253545, - -22587149, - 536906 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 4377756, - 8115836, - 24567078, - 15495314, - 11625074, - 13064599, - 7390551, - 10589625, - 10838060, - -15420424 - ]), - FieldElement.fromList([ - -19342404, - 867880, - 9277171, - -3218459, - -14431572, - -1986443, - 19295826, - -15796950, - 6378260, - 699185 - ]), - FieldElement.fromList([ - 7895026, - 4057113, - -7081772, - -13077756, - -17886831, - -323126, - -716039, - 15693155, - -5045064, - -13373962 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -7737563, - -5869402, - -14566319, - -7406919, - 11385654, - 13201616, - 31730678, - -10962840, - -3918636, - -9669325 - ]), - FieldElement.fromList([ - 10188286, - -15770834, - -7336361, - 13427543, - 22223443, - 14896287, - 30743455, - 7116568, - -21786507, - 5427593 - ]), - FieldElement.fromList([ - 696102, - 13206899, - 27047647, - -10632082, - 15285305, - -9853179, - 10798490, - -4578720, - 19236243, - 12477404 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -11229439, - 11243796, - -17054270, - -8040865, - -788228, - -8167967, - -3897669, - 11180504, - -23169516, - 7733644 - ]), - FieldElement.fromList([ - 17800790, - -14036179, - -27000429, - -11766671, - 23887827, - 3149671, - 23466177, - -10538171, - 10322027, - 15313801 - ]), - FieldElement.fromList([ - 26246234, - 11968874, - 32263343, - -5468728, - 6830755, - -13323031, - -15794704, - -101982, - -24449242, - 10890804 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -31365647, - 10271363, - -12660625, - -6267268, - 16690207, - -13062544, - -14982212, - 16484931, - 25180797, - -5334884 - ]), - FieldElement.fromList([ - -586574, - 10376444, - -32586414, - -11286356, - 19801893, - 10997610, - 2276632, - 9482883, - 316878, - 13820577 - ]), - FieldElement.fromList([ - -9882808, - -4510367, - -2115506, - 16457136, - -11100081, - 11674996, - 30756178, - -7515054, - 30696930, - -3712849 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 32988917, - -9603412, - 12499366, - 7910787, - -10617257, - -11931514, - -7342816, - -9985397, - -32349517, - 7392473 - ]), - FieldElement.fromList([ - -8855661, - 15927861, - 9866406, - -3649411, - -2396914, - -16655781, - -30409476, - -9134995, - 25112947, - -2926644 - ]), - FieldElement.fromList([ - -2504044, - -436966, - 25621774, - -5678772, - 15085042, - -5479877, - -24884878, - -13526194, - 5537438, - -13914319 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -11225584, - 2320285, - -9584280, - 10149187, - -33444663, - 5808648, - -14876251, - -1729667, - 31234590, - 6090599 - ]), - FieldElement.fromList([ - -9633316, - 116426, - 26083934, - 2897444, - -6364437, - -2688086, - 609721, - 15878753, - -6970405, - -9034768 - ]), - FieldElement.fromList([ - -27757857, - 247744, - -15194774, - -9002551, - 23288161, - -10011936, - -23869595, - 6503646, - 20650474, - 1804084 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -27589786, - 15456424, - 8972517, - 8469608, - 15640622, - 4439847, - 3121995, - -10329713, - 27842616, - -202328 - ]), - FieldElement.fromList([ - -15306973, - 2839644, - 22530074, - 10026331, - 4602058, - 5048462, - 28248656, - 5031932, - -11375082, - 12714369 - ]), - FieldElement.fromList([ - 20807691, - -7270825, - 29286141, - 11421711, - -27876523, - -13868230, - -21227475, - 1035546, - -19733229, - 12796920 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 12076899, - -14301286, - -8785001, - -11848922, - -25012791, - 16400684, - -17591495, - -12899438, - 3480665, - -15182815 - ]), - FieldElement.fromList([ - -32361549, - 5457597, - 28548107, - 7833186, - 7303070, - -11953545, - -24363064, - -15921875, - -33374054, - 2771025 - ]), - FieldElement.fromList([ - -21389266, - 421932, - 26597266, - 6860826, - 22486084, - -6737172, - -17137485, - -4210226, - -24552282, - 15673397 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -20184622, - 2338216, - 19788685, - -9620956, - -4001265, - -8740893, - -20271184, - 4733254, - 3727144, - -12934448 - ]), - FieldElement.fromList([ - 6120119, - 814863, - -11794402, - -622716, - 6812205, - -15747771, - 2019594, - 7975683, - 31123697, - -10958981 - ]), - FieldElement.fromList([ - 30069250, - -11435332, - 30434654, - 2958439, - 18399564, - -976289, - 12296869, - 9204260, - -16432438, - 9648165 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 32705432, - -1550977, - 30705658, - 7451065, - -11805606, - 9631813, - 3305266, - 5248604, - -26008332, - -11377501 - ]), - FieldElement.fromList([ - 17219865, - 2375039, - -31570947, - -5575615, - -19459679, - 9219903, - 294711, - 15298639, - 2662509, - -16297073 - ]), - FieldElement.fromList([ - -1172927, - -7558695, - -4366770, - -4287744, - -21346413, - -8434326, - 32087529, - -1222777, - 32247248, - -14389861 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 14312628, - 1221556, - 17395390, - -8700143, - -4945741, - -8684635, - -28197744, - -9637817, - -16027623, - -13378845 - ]), - FieldElement.fromList([ - -1428825, - -9678990, - -9235681, - 6549687, - -7383069, - -468664, - 23046502, - 9803137, - 17597934, - 2346211 - ]), - FieldElement.fromList([ - 18510800, - 15337574, - 26171504, - 981392, - -22241552, - 7827556, - -23491134, - -11323352, - 3059833, - -11782870 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 10141598, - 6082907, - 17829293, - -1947643, - 9830092, - 13613136, - -25556636, - -5544586, - -33502212, - 3592096 - ]), - FieldElement.fromList([ - 33114168, - -15889352, - -26525686, - -13343397, - 33076705, - 8716171, - 1151462, - 1521897, - -982665, - -6837803 - ]), - FieldElement.fromList([ - -32939165, - -4255815, - 23947181, - -324178, - -33072974, - -12305637, - -16637686, - 3891704, - 26353178, - 693168 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 30374239, - 1595580, - -16884039, - 13186931, - 4600344, - 406904, - 9585294, - -400668, - 31375464, - 14369965 - ]), - FieldElement.fromList([ - -14370654, - -7772529, - 1510301, - 6434173, - -18784789, - -6262728, - 32732230, - -13108839, - 17901441, - 16011505 - ]), - FieldElement.fromList([ - 18171223, - -11934626, - -12500402, - 15197122, - -11038147, - -15230035, - -19172240, - -16046376, - 8764035, - 12309598 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 5975908, - -5243188, - -19459362, - -9681747, - -11541277, - 14015782, - -23665757, - 1228319, - 17544096, - -10593782 - ]), - FieldElement.fromList([ - 5811932, - -1715293, - 3442887, - -2269310, - -18367348, - -8359541, - -18044043, - -15410127, - -5565381, - 12348900 - ]), - FieldElement.fromList([ - -31399660, - 11407555, - 25755363, - 6891399, - -3256938, - 14872274, - -24849353, - 8141295, - -10632534, - -585479 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -12675304, - 694026, - -5076145, - 13300344, - 14015258, - -14451394, - -9698672, - -11329050, - 30944593, - 1130208 - ]), - FieldElement.fromList([ - 8247766, - -6710942, - -26562381, - -7709309, - -14401939, - -14648910, - 4652152, - 2488540, - 23550156, - -271232 - ]), - FieldElement.fromList([ - 17294316, - -3788438, - 7026748, - 15626851, - 22990044, - 113481, - 2267737, - -5908146, - -408818, - -137719 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 16091085, - -16253926, - 18599252, - 7340678, - 2137637, - -1221657, - -3364161, - 14550936, - 3260525, - -7166271 - ]), - FieldElement.fromList([ - -4910104, - -13332887, - 18550887, - 10864893, - -16459325, - -7291596, - -23028869, - -13204905, - -12748722, - 2701326 - ]), - FieldElement.fromList([ - -8574695, - 16099415, - 4629974, - -16340524, - -20786213, - -6005432, - -10018363, - 9276971, - 11329923, - 1862132 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 14763076, - -15903608, - -30918270, - 3689867, - 3511892, - 10313526, - -21951088, - 12219231, - -9037963, - -940300 - ]), - FieldElement.fromList([ - 8894987, - -3446094, - 6150753, - 3013931, - 301220, - 15693451, - -31981216, - -2909717, - -15438168, - 11595570 - ]), - FieldElement.fromList([ - 15214962, - 3537601, - -26238722, - -14058872, - 4418657, - -15230761, - 13947276, - 10730794, - -13489462, - -4363670 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -2538306, - 7682793, - 32759013, - 263109, - -29984731, - -7955452, - -22332124, - -10188635, - 977108, - 699994 - ]), - FieldElement.fromList([ - -12466472, - 4195084, - -9211532, - 550904, - -15565337, - 12917920, - 19118110, - -439841, - -30534533, - -14337913 - ]), - FieldElement.fromList([ - 31788461, - -14507657, - 4799989, - 7372237, - 8808585, - -14747943, - 9408237, - -10051775, - 12493932, - -5409317 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -25680606, - 5260744, - -19235809, - -6284470, - -3695942, - 16566087, - 27218280, - 2607121, - 29375955, - 6024730 - ]), - FieldElement.fromList([ - 842132, - -2794693, - -4763381, - -8722815, - 26332018, - -12405641, - 11831880, - 6985184, - -9940361, - 2854096 - ]), - FieldElement.fromList([ - -4847262, - -7969331, - 2516242, - -5847713, - 9695691, - -7221186, - 16512645, - 960770, - 12121869, - 16648078 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -15218652, - 14667096, - -13336229, - 2013717, - 30598287, - -464137, - -31504922, - -7882064, - 20237806, - 2838411 - ]), - FieldElement.fromList([ - -19288047, - 4453152, - 15298546, - -16178388, - 22115043, - -15972604, - 12544294, - -13470457, - 1068881, - -12499905 - ]), - FieldElement.fromList([ - -9558883, - -16518835, - 33238498, - 13506958, - 30505848, - -1114596, - -8486907, - -2630053, - 12521378, - 4845654 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -28198521, - 10744108, - -2958380, - 10199664, - 7759311, - -13088600, - 3409348, - -873400, - -6482306, - -12885870 - ]), - FieldElement.fromList([ - -23561822, - 6230156, - -20382013, - 10655314, - -24040585, - -11621172, - 10477734, - -1240216, - -3113227, - 13974498 - ]), - FieldElement.fromList([ - 12966261, - 15550616, - -32038948, - -1615346, - 21025980, - -629444, - 5642325, - 7188737, - 18895762, - 12629579 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 14741879, - -14946887, - 22177208, - -11721237, - 1279741, - 8058600, - 11758140, - 789443, - 32195181, - 3895677 - ]), - FieldElement.fromList([ - 10758205, - 15755439, - -4509950, - 9243698, - -4879422, - 6879879, - -2204575, - -3566119, - -8982069, - 4429647 - ]), - FieldElement.fromList([ - -2453894, - 15725973, - -20436342, - -10410672, - -5803908, - -11040220, - -7135870, - -11642895, - 18047436, - -15281743 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -25173001, - -11307165, - 29759956, - 11776784, - -22262383, - -15820455, - 10993114, - -12850837, - -17620701, - -9408468 - ]), - FieldElement.fromList([ - 21987233, - 700364, - -24505048, - 14972008, - -7774265, - -5718395, - 32155026, - 2581431, - -29958985, - 8773375 - ]), - FieldElement.fromList([ - -25568350, - 454463, - -13211935, - 16126715, - 25240068, - 8594567, - 20656846, - 12017935, - -7874389, - -13920155 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 6028182, - 6263078, - -31011806, - -11301710, - -818919, - 2461772, - -31841174, - -5468042, - -1721788, - -2776725 - ]), - FieldElement.fromList([ - -12278994, - 16624277, - 987579, - -5922598, - 32908203, - 1248608, - 7719845, - -4166698, - 28408820, - 6816612 - ]), - FieldElement.fromList([ - -10358094, - -8237829, - 19549651, - -12169222, - 22082623, - 16147817, - 20613181, - 13982702, - -10339570, - 5067943 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -30505967, - -3821767, - 12074681, - 13582412, - -19877972, - 2443951, - -19719286, - 12746132, - 5331210, - -10105944 - ]), - FieldElement.fromList([ - 30528811, - 3601899, - -1957090, - 4619785, - -27361822, - -15436388, - 24180793, - -12570394, - 27679908, - -1648928 - ]), - FieldElement.fromList([ - 9402404, - -13957065, - 32834043, - 10838634, - -26580150, - -13237195, - 26653274, - -8685565, - 22611444, - -12715406 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 22190590, - 1118029, - 22736441, - 15130463, - -30460692, - -5991321, - 19189625, - -4648942, - 4854859, - 6622139 - ]), - FieldElement.fromList([ - -8310738, - -2953450, - -8262579, - -3388049, - -10401731, - -271929, - 13424426, - -3567227, - 26404409, - 13001963 - ]), - FieldElement.fromList([ - -31241838, - -15415700, - -2994250, - 8939346, - 11562230, - -12840670, - -26064365, - -11621720, - -15405155, - 11020693 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 1866042, - -7949489, - -7898649, - -10301010, - 12483315, - 13477547, - 3175636, - -12424163, - 28761762, - 1406734 - ]), - FieldElement.fromList([ - -448555, - -1777666, - 13018551, - 3194501, - -9580420, - -11161737, - 24760585, - -4347088, - 25577411, - -13378680 - ]), - FieldElement.fromList([ - -24290378, - 4759345, - -690653, - -1852816, - 2066747, - 10693769, - -29595790, - 9884936, - -9368926, - 4745410 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -9141284, - 6049714, - -19531061, - -4341411, - -31260798, - 9944276, - -15462008, - -11311852, - 10931924, - -11931931 - ]), - FieldElement.fromList([ - -16561513, - 14112680, - -8012645, - 4817318, - -8040464, - -11414606, - -22853429, - 10856641, - -20470770, - 13434654 - ]), - FieldElement.fromList([ - 22759489, - -10073434, - -16766264, - -1871422, - 13637442, - -10168091, - 1765144, - -12654326, - 28445307, - -5364710 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 29875063, - 12493613, - 2795536, - -3786330, - 1710620, - 15181182, - -10195717, - -8788675, - 9074234, - 1167180 - ]), - FieldElement.fromList([ - -26205683, - 11014233, - -9842651, - -2635485, - -26908120, - 7532294, - -18716888, - -9535498, - 3843903, - 9367684 - ]), - FieldElement.fromList([ - -10969595, - -6403711, - 9591134, - 9582310, - 11349256, - 108879, - 16235123, - 8601684, - -139197, - 4242895 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 22092954, - -13191123, - -2042793, - -11968512, - 32186753, - -11517388, - -6574341, - 2470660, - -27417366, - 16625501 - ]), - FieldElement.fromList([ - -11057722, - 3042016, - 13770083, - -9257922, - 584236, - -544855, - -7770857, - 2602725, - -27351616, - 14247413 - ]), - FieldElement.fromList([ - 6314175, - -10264892, - -32772502, - 15957557, - -10157730, - 168750, - -8618807, - 14290061, - 27108877, - -1180880 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -8586597, - -7170966, - 13241782, - 10960156, - -32991015, - -13794596, - 33547976, - -11058889, - -27148451, - 981874 - ]), - FieldElement.fromList([ - 22833440, - 9293594, - -32649448, - -13618667, - -9136966, - 14756819, - -22928859, - -13970780, - -10479804, - -16197962 - ]), - FieldElement.fromList([ - -7768587, - 3326786, - -28111797, - 10783824, - 19178761, - 14905060, - 22680049, - 13906969, - -15933690, - 3797899 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 21721356, - -4212746, - -12206123, - 9310182, - -3882239, - -13653110, - 23740224, - -2709232, - 20491983, - -8042152 - ]), - FieldElement.fromList([ - 9209270, - -15135055, - -13256557, - -6167798, - -731016, - 15289673, - 25947805, - 15286587, - 30997318, - -6703063 - ]), - FieldElement.fromList([ - 7392032, - 16618386, - 23946583, - -8039892, - -13265164, - -1533858, - -14197445, - -2321576, - 17649998, - -250080 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -9301088, - -14193827, - 30609526, - -3049543, - -25175069, - -1283752, - -15241566, - -9525724, - -2233253, - 7662146 - ]), - FieldElement.fromList([ - -17558673, - 1763594, - -33114336, - 15908610, - -30040870, - -12174295, - 7335080, - -8472199, - -3174674, - 3440183 - ]), - FieldElement.fromList([ - -19889700, - -5977008, - -24111293, - -9688870, - 10799743, - -16571957, - 40450, - -4431835, - 4862400, - 1133 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -32856209, - -7873957, - -5422389, - 14860950, - -16319031, - 7956142, - 7258061, - 311861, - -30594991, - -7379421 - ]), - FieldElement.fromList([ - -3773428, - -1565936, - 28985340, - 7499440, - 24445838, - 9325937, - 29727763, - 16527196, - 18278453, - 15405622 - ]), - FieldElement.fromList([ - -4381906, - 8508652, - -19898366, - -3674424, - -5984453, - 15149970, - -13313598, - 843523, - -21875062, - 13626197 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 2281448, - -13487055, - -10915418, - -2609910, - 1879358, - 16164207, - -10783882, - 3953792, - 13340839, - 15928663 - ]), - FieldElement.fromList([ - 31727126, - -7179855, - -18437503, - -8283652, - 2875793, - -16390330, - -25269894, - -7014826, - -23452306, - 5964753 - ]), - FieldElement.fromList([ - 4100420, - -5959452, - -17179337, - 6017714, - -18705837, - 12227141, - -26684835, - 11344144, - 2538215, - -7570755 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -9433605, - 6123113, - 11159803, - -2156608, - 30016280, - 14966241, - -20474983, - 1485421, - -629256, - -15958862 - ]), - FieldElement.fromList([ - -26804558, - 4260919, - 11851389, - 9658551, - -32017107, - 16367492, - -20205425, - -13191288, - 11659922, - -11115118 - ]), - FieldElement.fromList([ - 26180396, - 10015009, - -30844224, - -8581293, - 5418197, - 9480663, - 2231568, - -10170080, - 33100372, - -1306171 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 15121113, - -5201871, - -10389905, - 15427821, - -27509937, - -15992507, - 21670947, - 4486675, - -5931810, - -14466380 - ]), - FieldElement.fromList([ - 16166486, - -9483733, - -11104130, - 6023908, - -31926798, - -1364923, - 2340060, - -16254968, - -10735770, - -10039824 - ]), - FieldElement.fromList([ - 28042865, - -3557089, - -12126526, - 12259706, - -3717498, - -6945899, - 6766453, - -8689599, - 18036436, - 5803270 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -817581, - 6763912, - 11803561, - 1585585, - 10958447, - -2671165, - 23855391, - 4598332, - -6159431, - -14117438 - ]), - FieldElement.fromList([ - -31031306, - -14256194, - 17332029, - -2383520, - 31312682, - -5967183, - 696309, - 50292, - -20095739, - 11763584 - ]), - FieldElement.fromList([ - -594563, - -2514283, - -32234153, - 12643980, - 12650761, - 14811489, - 665117, - -12613632, - -19773211, - -10713562 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 30464590, - -11262872, - -4127476, - -12734478, - 19835327, - -7105613, - -24396175, - 2075773, - -17020157, - 992471 - ]), - FieldElement.fromList([ - 18357185, - -6994433, - 7766382, - 16342475, - -29324918, - 411174, - 14578841, - 8080033, - -11574335, - -10601610 - ]), - FieldElement.fromList([ - 19598397, - 10334610, - 12555054, - 2555664, - 18821899, - -10339780, - 21873263, - 16014234, - 26224780, - 16452269 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -30223925, - 5145196, - 5944548, - 16385966, - 3976735, - 2009897, - -11377804, - -7618186, - -20533829, - 3698650 - ]), - FieldElement.fromList([ - 14187449, - 3448569, - -10636236, - -10810935, - -22663880, - -3433596, - 7268410, - -10890444, - 27394301, - 12015369 - ]), - FieldElement.fromList([ - 19695761, - 16087646, - 28032085, - 12999827, - 6817792, - 11427614, - 20244189, - -1312777, - -13259127, - -3402461 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 30860103, - 12735208, - -1888245, - -4699734, - -16974906, - 2256940, - -8166013, - 12298312, - -8550524, - -10393462 - ]), - FieldElement.fromList([ - -5719826, - -11245325, - -1910649, - 15569035, - 26642876, - -7587760, - -5789354, - -15118654, - -4976164, - 12651793 - ]), - FieldElement.fromList([ - -2848395, - 9953421, - 11531313, - -5282879, - 26895123, - -12697089, - -13118820, - -16517902, - 9768698, - -2533218 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -24719459, - 1894651, - -287698, - -4704085, - 15348719, - -8156530, - 32767513, - 12765450, - 4940095, - 10678226 - ]), - FieldElement.fromList([ - 18860224, - 15980149, - -18987240, - -1562570, - -26233012, - -11071856, - -7843882, - 13944024, - -24372348, - 16582019 - ]), - FieldElement.fromList([ - -15504260, - 4970268, - -29893044, - 4175593, - -20993212, - -2199756, - -11704054, - 15444560, - -11003761, - 7989037 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 31490452, - 5568061, - -2412803, - 2182383, - -32336847, - 4531686, - -32078269, - 6200206, - -19686113, - -14800171 - ]), - FieldElement.fromList([ - -17308668, - -15879940, - -31522777, - -2831, - -32887382, - 16375549, - 8680158, - -16371713, - 28550068, - -6857132 - ]), - FieldElement.fromList([ - -28126887, - -5688091, - 16837845, - -1820458, - -6850681, - 12700016, - -30039981, - 4364038, - 1155602, - 5988841 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 21890435, - -13272907, - -12624011, - 12154349, - -7831873, - 15300496, - 23148983, - -4470481, - 24618407, - 8283181 - ]), - FieldElement.fromList([ - -33136107, - -10512751, - 9975416, - 6841041, - -31559793, - 16356536, - 3070187, - -7025928, - 1466169, - 10740210 - ]), - FieldElement.fromList([ - -1509399, - -15488185, - -13503385, - -10655916, - 32799044, - 909394, - -13938903, - -5779719, - -32164649, - -15327040 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 3960823, - -14267803, - -28026090, - -15918051, - -19404858, - 13146868, - 15567327, - 951507, - -3260321, - -573935 - ]), - FieldElement.fromList([ - 24740841, - 5052253, - -30094131, - 8961361, - 25877428, - 6165135, - -24368180, - 14397372, - -7380369, - -6144105 - ]), - FieldElement.fromList([ - -28888365, - 3510803, - -28103278, - -1158478, - -11238128, - -10631454, - -15441463, - -14453128, - -1625486, - -6494814 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 793299, - -9230478, - 8836302, - -6235707, - -27360908, - -2369593, - 33152843, - -4885251, - -9906200, - -621852 - ]), - FieldElement.fromList([ - 5666233, - 525582, - 20782575, - -8038419, - -24538499, - 14657740, - 16099374, - 1468826, - -6171428, - -15186581 - ]), - FieldElement.fromList([ - -4859255, - -3779343, - -2917758, - -6748019, - 7778750, - 11688288, - -30404353, - -9871238, - -1558923, - -9863646 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 10896332, - -7719704, - 824275, - 472601, - -19460308, - 3009587, - 25248958, - 14783338, - -30581476, - -15757844 - ]), - FieldElement.fromList([ - 10566929, - 12612572, - -31944212, - 11118703, - -12633376, - 12362879, - 21752402, - 8822496, - 24003793, - 14264025 - ]), - FieldElement.fromList([ - 27713862, - -7355973, - -11008240, - 9227530, - 27050101, - 2504721, - 23886875, - -13117525, - 13958495, - -5732453 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -23481610, - 4867226, - -27247128, - 3900521, - 29838369, - -8212291, - -31889399, - -10041781, - 7340521, - -15410068 - ]), - FieldElement.fromList([ - 4646514, - -8011124, - -22766023, - -11532654, - 23184553, - 8566613, - 31366726, - -1381061, - -15066784, - -10375192 - ]), - FieldElement.fromList([ - -17270517, - 12723032, - -16993061, - 14878794, - 21619651, - -6197576, - 27584817, - 3093888, - -8843694, - 3849921 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -9064912, - 2103172, - 25561640, - -15125738, - -5239824, - 9582958, - 32477045, - -9017955, - 5002294, - -15550259 - ]), - FieldElement.fromList([ - -12057553, - -11177906, - 21115585, - -13365155, - 8808712, - -12030708, - 16489530, - 13378448, - -25845716, - 12741426 - ]), - FieldElement.fromList([ - -5946367, - 10645103, - -30911586, - 15390284, - -3286982, - -7118677, - 24306472, - 15852464, - 28834118, - -7646072 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -17335748, - -9107057, - -24531279, - 9434953, - -8472084, - -583362, - -13090771, - 455841, - 20461858, - 5491305 - ]), - FieldElement.fromList([ - 13669248, - -16095482, - -12481974, - -10203039, - -14569770, - -11893198, - -24995986, - 11293807, - -28588204, - -9421832 - ]), - FieldElement.fromList([ - 28497928, - 6272777, - -33022994, - 14470570, - 8906179, - -1225630, - 18504674, - -14165166, - 29867745, - -8795943 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -16207023, - 13517196, - -27799630, - -13697798, - 24009064, - -6373891, - -6367600, - -13175392, - 22853429, - -4012011 - ]), - FieldElement.fromList([ - 24191378, - 16712145, - -13931797, - 15217831, - 14542237, - 1646131, - 18603514, - -11037887, - 12876623, - -2112447 - ]), - FieldElement.fromList([ - 17902668, - 4518229, - -411702, - -2829247, - 26878217, - 5258055, - -12860753, - 608397, - 16031844, - 3723494 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -28632773, - 12763728, - -20446446, - 7577504, - 33001348, - -13017745, - 17558842, - -7872890, - 23896954, - -4314245 - ]), - FieldElement.fromList([ - -20005381, - -12011952, - 31520464, - 605201, - 2543521, - 5991821, - -2945064, - 7229064, - -9919646, - -8826859 - ]), - FieldElement.fromList([ - 28816045, - 298879, - -28165016, - -15920938, - 19000928, - -1665890, - -12680833, - -2949325, - -18051778, - -2082915 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 16000882, - -344896, - 3493092, - -11447198, - -29504595, - -13159789, - 12577740, - 16041268, - -19715240, - 7847707 - ]), - FieldElement.fromList([ - 10151868, - 10572098, - 27312476, - 7922682, - 14825339, - 4723128, - -32855931, - -6519018, - -10020567, - 3852848 - ]), - FieldElement.fromList([ - -11430470, - 15697596, - -21121557, - -4420647, - 5386314, - 15063598, - 16514493, - -15932110, - 29330899, - -15076224 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -25499735, - -4378794, - -15222908, - -6901211, - 16615731, - 2051784, - 3303702, - 15490, - -27548796, - 12314391 - ]), - FieldElement.fromList([ - 15683520, - -6003043, - 18109120, - -9980648, - 15337968, - -5997823, - -16717435, - 15921866, - 16103996, - -3731215 - ]), - FieldElement.fromList([ - -23169824, - -10781249, - 13588192, - -1628807, - -3798557, - -1074929, - -19273607, - 5402699, - -29815713, - -9841101 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 23190676, - 2384583, - -32714340, - 3462154, - -29903655, - -1529132, - -11266856, - 8911517, - -25205859, - 2739713 - ]), - FieldElement.fromList([ - 21374101, - -3554250, - -33524649, - 9874411, - 15377179, - 11831242, - -33529904, - 6134907, - 4931255, - 11987849 - ]), - FieldElement.fromList([ - -7732, - -2978858, - -16223486, - 7277597, - 105524, - -322051, - -31480539, - 13861388, - -30076310, - 10117930 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -29501170, - -10744872, - -26163768, - 13051539, - -25625564, - 5089643, - -6325503, - 6704079, - 12890019, - 15728940 - ]), - FieldElement.fromList([ - -21972360, - -11771379, - -951059, - -4418840, - 14704840, - 2695116, - 903376, - -10428139, - 12885167, - 8311031 - ]), - FieldElement.fromList([ - -17516482, - 5352194, - 10384213, - -13811658, - 7506451, - 13453191, - 26423267, - 4384730, - 1888765, - -5435404 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -25817338, - -3107312, - -13494599, - -3182506, - 30896459, - -13921729, - -32251644, - -12707869, - -19464434, - -3340243 - ]), - FieldElement.fromList([ - -23607977, - -2665774, - -526091, - 4651136, - 5765089, - 4618330, - 6092245, - 14845197, - 17151279, - -9854116 - ]), - FieldElement.fromList([ - -24830458, - -12733720, - -15165978, - 10367250, - -29530908, - -265356, - 22825805, - -7087279, - -16866484, - 16176525 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -23583256, - 6564961, - 20063689, - 3798228, - -4740178, - 7359225, - 2006182, - -10363426, - -28746253, - -10197509 - ]), - FieldElement.fromList([ - -10626600, - -4486402, - -13320562, - -5125317, - 3432136, - -6393229, - 23632037, - -1940610, - 32808310, - 1099883 - ]), - FieldElement.fromList([ - 15030977, - 5768825, - -27451236, - -2887299, - -6427378, - -15361371, - -15277896, - -6809350, - 2051441, - -15225865 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -3362323, - -7239372, - 7517890, - 9824992, - 23555850, - 295369, - 5148398, - -14154188, - -22686354, - 16633660 - ]), - FieldElement.fromList([ - 4577086, - -16752288, - 13249841, - -15304328, - 19958763, - -14537274, - 18559670, - -10759549, - 8402478, - -9864273 - ]), - FieldElement.fromList([ - -28406330, - -1051581, - -26790155, - -907698, - -17212414, - -11030789, - 9453451, - -14980072, - 17983010, - 9967138 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -25762494, - 6524722, - 26585488, - 9969270, - 24709298, - 1220360, - -1677990, - 7806337, - 17507396, - 3651560 - ]), - FieldElement.fromList([ - -10420457, - -4118111, - 14584639, - 15971087, - -15768321, - 8861010, - 26556809, - -5574557, - -18553322, - -11357135 - ]), - FieldElement.fromList([ - 2839101, - 14284142, - 4029895, - 3472686, - 14402957, - 12689363, - -26642121, - 8459447, - -5605463, - -7621941 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -4839289, - -3535444, - 9744961, - 2871048, - 25113978, - 3187018, - -25110813, - -849066, - 17258084, - -7977739 - ]), - FieldElement.fromList([ - 18164541, - -10595176, - -17154882, - -1542417, - 19237078, - -9745295, - 23357533, - -15217008, - 26908270, - 12150756 - ]), - FieldElement.fromList([ - -30264870, - -7647865, - 5112249, - -7036672, - -1499807, - -6974257, - 43168, - -5537701, - -32302074, - 16215819 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -6898905, - 9824394, - -12304779, - -4401089, - -31397141, - -6276835, - 32574489, - 12532905, - -7503072, - -8675347 - ]), - FieldElement.fromList([ - -27343522, - -16515468, - -27151524, - -10722951, - 946346, - 16291093, - 254968, - 7168080, - 21676107, - -1943028 - ]), - FieldElement.fromList([ - 21260961, - -8424752, - -16831886, - -11920822, - -23677961, - 3968121, - -3651949, - -6215466, - -3556191, - -7913075 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 16544754, - 13250366, - -16804428, - 15546242, - -4583003, - 12757258, - -2462308, - -8680336, - -18907032, - -9662799 - ]), - FieldElement.fromList([ - -2415239, - -15577728, - 18312303, - 4964443, - -15272530, - -12653564, - 26820651, - 16690659, - 25459437, - -4564609 - ]), - FieldElement.fromList([ - -25144690, - 11425020, - 28423002, - -11020557, - -6144921, - -15826224, - 9142795, - -2391602, - -6432418, - -1644817 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -23104652, - 6253476, - 16964147, - -3768872, - -25113972, - -12296437, - -27457225, - -16344658, - 6335692, - 7249989 - ]), - FieldElement.fromList([ - -30333227, - 13979675, - 7503222, - -12368314, - -11956721, - -4621693, - -30272269, - 2682242, - 25993170, - -12478523 - ]), - FieldElement.fromList([ - 4364628, - 5930691, - 32304656, - -10044554, - -8054781, - 15091131, - 22857016, - -10598955, - 31820368, - 15075278 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 31879134, - -8918693, - 17258761, - 90626, - -8041836, - -4917709, - 24162788, - -9650886, - -17970238, - 12833045 - ]), - FieldElement.fromList([ - 19073683, - 14851414, - -24403169, - -11860168, - 7625278, - 11091125, - -19619190, - 2074449, - -9413939, - 14905377 - ]), - FieldElement.fromList([ - 24483667, - -11935567, - -2518866, - -11547418, - -1553130, - 15355506, - -25282080, - 9253129, - 27628530, - -7555480 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 17597607, - 8340603, - 19355617, - 552187, - 26198470, - -3176583, - 4593324, - -9157582, - -14110875, - 15297016 - ]), - FieldElement.fromList([ - 510886, - 14337390, - -31785257, - 16638632, - 6328095, - 2713355, - -20217417, - -11864220, - 8683221, - 2921426 - ]), - FieldElement.fromList([ - 18606791, - 11874196, - 27155355, - -5281482, - -24031742, - 6265446, - -25178240, - -1278924, - 4674690, - 13890525 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 13609624, - 13069022, - -27372361, - -13055908, - 24360586, - 9592974, - 14977157, - 9835105, - 4389687, - 288396 - ]), - FieldElement.fromList([ - 9922506, - -519394, - 13613107, - 5883594, - -18758345, - -434263, - -12304062, - 8317628, - 23388070, - 16052080 - ]), - FieldElement.fromList([ - 12720016, - 11937594, - -31970060, - -5028689, - 26900120, - 8561328, - -20155687, - -11632979, - -14754271, - -10812892 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 15961858, - 14150409, - 26716931, - -665832, - -22794328, - 13603569, - 11829573, - 7467844, - -28822128, - 929275 - ]), - FieldElement.fromList([ - 11038231, - -11582396, - -27310482, - -7316562, - -10498527, - -16307831, - -23479533, - -9371869, - -21393143, - 2465074 - ]), - FieldElement.fromList([ - 20017163, - -4323226, - 27915242, - 1529148, - 12396362, - 15675764, - 13817261, - -9658066, - 2463391, - -4622140 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -16358878, - -12663911, - -12065183, - 4996454, - -1256422, - 1073572, - 9583558, - 12851107, - 4003896, - 12673717 - ]), - FieldElement.fromList([ - -1731589, - -15155870, - -3262930, - 16143082, - 19294135, - 13385325, - 14741514, - -9103726, - 7903886, - 2348101 - ]), - FieldElement.fromList([ - 24536016, - -16515207, - 12715592, - -3862155, - 1511293, - 10047386, - -3842346, - -7129159, - -28377538, - 10048127 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -12622226, - -6204820, - 30718825, - 2591312, - -10617028, - 12192840, - 18873298, - -7297090, - -32297756, - 15221632 - ]), - FieldElement.fromList([ - -26478122, - -11103864, - 11546244, - -1852483, - 9180880, - 7656409, - -21343950, - 2095755, - 29769758, - 6593415 - ]), - FieldElement.fromList([ - -31994208, - -2907461, - 4176912, - 3264766, - 12538965, - -868111, - 26312345, - -6118678, - 30958054, - 8292160 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 31429822, - -13959116, - 29173532, - 15632448, - 12174511, - -2760094, - 32808831, - 3977186, - 26143136, - -3148876 - ]), - FieldElement.fromList([ - 22648901, - 1402143, - -22799984, - 13746059, - 7936347, - 365344, - -8668633, - -1674433, - -3758243, - -2304625 - ]), - FieldElement.fromList([ - -15491917, - 8012313, - -2514730, - -12702462, - -23965846, - -10254029, - -1612713, - -1535569, - -16664475, - 8194478 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 27338066, - -7507420, - -7414224, - 10140405, - -19026427, - -6589889, - 27277191, - 8855376, - 28572286, - 3005164 - ]), - FieldElement.fromList([ - 26287124, - 4821776, - 25476601, - -4145903, - -3764513, - -15788984, - -18008582, - 1182479, - -26094821, - -13079595 - ]), - FieldElement.fromList([ - -7171154, - 3178080, - 23970071, - 6201893, - -17195577, - -4489192, - -21876275, - -13982627, - 32208683, - -1198248 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -16657702, - 2817643, - -10286362, - 14811298, - 6024667, - 13349505, - -27315504, - -10497842, - -27672585, - -11539858 - ]), - FieldElement.fromList([ - 15941029, - -9405932, - -21367050, - 8062055, - 31876073, - -238629, - -15278393, - -1444429, - 15397331, - -4130193 - ]), - FieldElement.fromList([ - 8934485, - -13485467, - -23286397, - -13423241, - -32446090, - 14047986, - 31170398, - -1441021, - -27505566, - 15087184 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -18357243, - -2156491, - 24524913, - -16677868, - 15520427, - -6360776, - -15502406, - 11461896, - 16788528, - -5868942 - ]), - FieldElement.fromList([ - -1947386, - 16013773, - 21750665, - 3714552, - -17401782, - -16055433, - -3770287, - -10323320, - 31322514, - -11615635 - ]), - FieldElement.fromList([ - 21426655, - -5650218, - -13648287, - -5347537, - -28812189, - -4920970, - -18275391, - -14621414, - 13040862, - -12112948 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 11293895, - 12478086, - -27136401, - 15083750, - -29307421, - 14748872, - 14555558, - -13417103, - 1613711, - 4896935 - ]), - FieldElement.fromList([ - -25894883, - 15323294, - -8489791, - -8057900, - 25967126, - -13425460, - 2825960, - -4897045, - -23971776, - -11267415 - ]), - FieldElement.fromList([ - -15924766, - -5229880, - -17443532, - 6410664, - 3622847, - 10243618, - 20615400, - 12405433, - -23753030, - -8436416 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -7091295, - 12556208, - -20191352, - 9025187, - -17072479, - 4333801, - 4378436, - 2432030, - 23097949, - -566018 - ]), - FieldElement.fromList([ - 4565804, - -16025654, - 20084412, - -7842817, - 1724999, - 189254, - 24767264, - 10103221, - -18512313, - 2424778 - ]), - FieldElement.fromList([ - 366633, - -11976806, - 8173090, - -6890119, - 30788634, - 5745705, - -7168678, - 1344109, - -3642553, - 12412659 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -24001791, - 7690286, - 14929416, - -168257, - -32210835, - -13412986, - 24162697, - -15326504, - -3141501, - 11179385 - ]), - FieldElement.fromList([ - 18289522, - -14724954, - 8056945, - 16430056, - -21729724, - 7842514, - -6001441, - -1486897, - -18684645, - -11443503 - ]), - FieldElement.fromList([ - 476239, - 6601091, - -6152790, - -9723375, - 17503545, - -4863900, - 27672959, - 13403813, - 11052904, - 5219329 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 20678546, - -8375738, - -32671898, - 8849123, - -5009758, - 14574752, - 31186971, - -3973730, - 9014762, - -8579056 - ]), - FieldElement.fromList([ - -13644050, - -10350239, - -15962508, - 5075808, - -1514661, - -11534600, - -33102500, - 9160280, - 8473550, - -3256838 - ]), - FieldElement.fromList([ - 24900749, - 14435722, - 17209120, - -15292541, - -22592275, - 9878983, - -7689309, - -16335821, - -24568481, - 11788948 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -3118155, - -11395194, - -13802089, - 14797441, - 9652448, - -6845904, - -20037437, - 10410733, - -24568470, - -1458691 - ]), - FieldElement.fromList([ - -15659161, - 16736706, - -22467150, - 10215878, - -9097177, - 7563911, - 11871841, - -12505194, - -18513325, - 8464118 - ]), - FieldElement.fromList([ - -23400612, - 8348507, - -14585951, - -861714, - -3950205, - -6373419, - 14325289, - 8628612, - 33313881, - -8370517 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -20186973, - -4967935, - 22367356, - 5271547, - -1097117, - -4788838, - -24805667, - -10236854, - -8940735, - -5818269 - ]), - FieldElement.fromList([ - -6948785, - -1795212, - -32625683, - -16021179, - 32635414, - -7374245, - 15989197, - -12838188, - 28358192, - -4253904 - ]), - FieldElement.fromList([ - -23561781, - -2799059, - -32351682, - -1661963, - -9147719, - 10429267, - -16637684, - 4072016, - -5351664, - 5596589 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -28236598, - -3390048, - 12312896, - 6213178, - 3117142, - 16078565, - 29266239, - 2557221, - 1768301, - 15373193 - ]), - FieldElement.fromList([ - -7243358, - -3246960, - -4593467, - -7553353, - -127927, - -912245, - -1090902, - -4504991, - -24660491, - 3442910 - ]), - FieldElement.fromList([ - -30210571, - 5124043, - 14181784, - 8197961, - 18964734, - -11939093, - 22597931, - 7176455, - -18585478, - 13365930 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -7877390, - -1499958, - 8324673, - 4690079, - 6261860, - 890446, - 24538107, - -8570186, - -9689599, - -3031667 - ]), - FieldElement.fromList([ - 25008904, - -10771599, - -4305031, - -9638010, - 16265036, - 15721635, - 683793, - -11823784, - 15723479, - -15163481 - ]), - FieldElement.fromList([ - -9660625, - 12374379, - -27006999, - -7026148, - -7724114, - -12314514, - 11879682, - 5400171, - 519526, - -1235876 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 22258397, - -16332233, - -7869817, - 14613016, - -22520255, - -2950923, - -20353881, - 7315967, - 16648397, - 7605640 - ]), - FieldElement.fromList([ - -8081308, - -8464597, - -8223311, - 9719710, - 19259459, - -15348212, - 23994942, - -5281555, - -9468848, - 4763278 - ]), - FieldElement.fromList([ - -21699244, - 9220969, - -15730624, - 1084137, - -25476107, - -2852390, - 31088447, - -7764523, - -11356529, - 728112 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 26047220, - -11751471, - -6900323, - -16521798, - 24092068, - 9158119, - -4273545, - -12555558, - -29365436, - -5498272 - ]), - FieldElement.fromList([ - 17510331, - -322857, - 5854289, - 8403524, - 17133918, - -3112612, - -28111007, - 12327945, - 10750447, - 10014012 - ]), - FieldElement.fromList([ - -10312768, - 3936952, - 9156313, - -8897683, - 16498692, - -994647, - -27481051, - -666732, - 3424691, - 7540221 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 30322361, - -6964110, - 11361005, - -4143317, - 7433304, - 4989748, - -7071422, - -16317219, - -9244265, - 15258046 - ]), - FieldElement.fromList([ - 13054562, - -2779497, - 19155474, - 469045, - -12482797, - 4566042, - 5631406, - 2711395, - 1062915, - -5136345 - ]), - FieldElement.fromList([ - -19240248, - -11254599, - -29509029, - -7499965, - -5835763, - 13005411, - -6066489, - 12194497, - 32960380, - 1459310 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 19852034, - 7027924, - 23669353, - 10020366, - 8586503, - -6657907, - 394197, - -6101885, - 18638003, - -11174937 - ]), - FieldElement.fromList([ - 31395534, - 15098109, - 26581030, - 8030562, - -16527914, - -5007134, - 9012486, - -7584354, - -6643087, - -5442636 - ]), - FieldElement.fromList([ - -9192165, - -2347377, - -1997099, - 4529534, - 25766844, - 607986, - -13222, - 9677543, - -32294889, - -6456008 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -2444496, - -149937, - 29348902, - 8186665, - 1873760, - 12489863, - -30934579, - -7839692, - -7852844, - -8138429 - ]), - FieldElement.fromList([ - -15236356, - -15433509, - 7766470, - 746860, - 26346930, - -10221762, - -27333451, - 10754588, - -9431476, - 5203576 - ]), - FieldElement.fromList([ - 31834314, - 14135496, - -770007, - 5159118, - 20917671, - -16768096, - -7467973, - -7337524, - 31809243, - 7347066 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -9606723, - -11874240, - 20414459, - 13033986, - 13716524, - -11691881, - 19797970, - -12211255, - 15192876, - -2087490 - ]), - FieldElement.fromList([ - -12663563, - -2181719, - 1168162, - -3804809, - 26747877, - -14138091, - 10609330, - 12694420, - 33473243, - -13382104 - ]), - FieldElement.fromList([ - 33184999, - 11180355, - 15832085, - -11385430, - -1633671, - 225884, - 15089336, - -11023903, - -6135662, - 14480053 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 31308717, - -5619998, - 31030840, - -1897099, - 15674547, - -6582883, - 5496208, - 13685227, - 27595050, - 8737275 - ]), - FieldElement.fromList([ - -20318852, - -15150239, - 10933843, - -16178022, - 8335352, - -7546022, - -31008351, - -12610604, - 26498114, - 66511 - ]), - FieldElement.fromList([ - 22644454, - -8761729, - -16671776, - 4884562, - -3105614, - -13559366, - 30540766, - -4286747, - -13327787, - -7515095 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -28017847, - 9834845, - 18617207, - -2681312, - -3401956, - -13307506, - 8205540, - 13585437, - -17127465, - 15115439 - ]), - FieldElement.fromList([ - 23711543, - -672915, - 31206561, - -8362711, - 6164647, - -9709987, - -33535882, - -1426096, - 8236921, - 16492939 - ]), - FieldElement.fromList([ - -23910559, - -13515526, - -26299483, - -4503841, - 25005590, - -7687270, - 19574902, - 10071562, - 6708380, - -6222424 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 2101391, - -4930054, - 19702731, - 2367575, - -15427167, - 1047675, - 5301017, - 9328700, - 29955601, - -11678310 - ]), - FieldElement.fromList([ - 3096359, - 9271816, - -21620864, - -15521844, - -14847996, - -7592937, - -25892142, - -12635595, - -9917575, - 6216608 - ]), - FieldElement.fromList([ - -32615849, - 338663, - -25195611, - 2510422, - -29213566, - -13820213, - 24822830, - -6146567, - -26767480, - 7525079 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -23066649, - -13985623, - 16133487, - -7896178, - -3389565, - 778788, - -910336, - -2782495, - -19386633, - 11994101 - ]), - FieldElement.fromList([ - 21691500, - -13624626, - -641331, - -14367021, - 3285881, - -3483596, - -25064666, - 9718258, - -7477437, - 13381418 - ]), - FieldElement.fromList([ - 18445390, - -4202236, - 14979846, - 11622458, - -1727110, - -3582980, - 23111648, - -6375247, - 28535282, - 15779576 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 30098053, - 3089662, - -9234387, - 16662135, - -21306940, - 11308411, - -14068454, - 12021730, - 9955285, - -16303356 - ]), - FieldElement.fromList([ - 9734894, - -14576830, - -7473633, - -9138735, - 2060392, - 11313496, - -18426029, - 9924399, - 20194861, - 13380996 - ]), - FieldElement.fromList([ - -26378102, - -7965207, - -22167821, - 15789297, - -18055342, - -6168792, - -1984914, - 15707771, - 26342023, - 10146099 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -26016874, - -219943, - 21339191, - -41388, - 19745256, - -2878700, - -29637280, - 2227040, - 21612326, - -545728 - ]), - FieldElement.fromList([ - -13077387, - 1184228, - 23562814, - -5970442, - -20351244, - -6348714, - 25764461, - 12243797, - -20856566, - 11649658 - ]), - FieldElement.fromList([ - -10031494, - 11262626, - 27384172, - 2271902, - 26947504, - -15997771, - 39944, - 6114064, - 33514190, - 2333242 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -21433588, - -12421821, - 8119782, - 7219913, - -21830522, - -9016134, - -6679750, - -12670638, - 24350578, - -13450001 - ]), - FieldElement.fromList([ - -4116307, - -11271533, - -23886186, - 4843615, - -30088339, - 690623, - -31536088, - -10406836, - 8317860, - 12352766 - ]), - FieldElement.fromList([ - 18200138, - -14475911, - -33087759, - -2696619, - -23702521, - -9102511, - -23552096, - -2287550, - 20712163, - 6719373 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 26656208, - 6075253, - -7858556, - 1886072, - -28344043, - 4262326, - 11117530, - -3763210, - 26224235, - -3297458 - ]), - FieldElement.fromList([ - -17168938, - -14854097, - -3395676, - -16369877, - -19954045, - 14050420, - 21728352, - 9493610, - 18620611, - -16428628 - ]), - FieldElement.fromList([ - -13323321, - 13325349, - 11432106, - 5964811, - 18609221, - 6062965, - -5269471, - -9725556, - -30701573, - -16479657 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -23860538, - -11233159, - 26961357, - 1640861, - -32413112, - -16737940, - 12248509, - -5240639, - 13735342, - 1934062 - ]), - FieldElement.fromList([ - 25089769, - 6742589, - 17081145, - -13406266, - 21909293, - -16067981, - -15136294, - -3765346, - -21277997, - 5473616 - ]), - FieldElement.fromList([ - 31883677, - -7961101, - 1083432, - -11572403, - 22828471, - 13290673, - -7125085, - 12469656, - 29111212, - -5451014 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 24244947, - -15050407, - -26262976, - 2791540, - -14997599, - 16666678, - 24367466, - 6388839, - -10295587, - 452383 - ]), - FieldElement.fromList([ - -25640782, - -3417841, - 5217916, - 16224624, - 19987036, - -4082269, - -24236251, - -5915248, - 15766062, - 8407814 - ]), - FieldElement.fromList([ - -20406999, - 13990231, - 15495425, - 16395525, - 5377168, - 15166495, - -8917023, - -4388953, - -8067909, - 2276718 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 30157918, - 12924066, - -17712050, - 9245753, - 19895028, - 3368142, - -23827587, - 5096219, - 22740376, - -7303417 - ]), - FieldElement.fromList([ - 2041139, - -14256350, - 7783687, - 13876377, - -25946985, - -13352459, - 24051124, - 13742383, - -15637599, - 13295222 - ]), - FieldElement.fromList([ - 33338237, - -8505733, - 12532113, - 7977527, - 9106186, - -1715251, - -17720195, - -4612972, - -4451357, - -14669444 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -20045281, - 5454097, - -14346548, - 6447146, - 28862071, - 1883651, - -2469266, - -4141880, - 7770569, - 9620597 - ]), - FieldElement.fromList([ - 23208068, - 7979712, - 33071466, - 8149229, - 1758231, - -10834995, - 30945528, - -1694323, - -33502340, - -14767970 - ]), - FieldElement.fromList([ - 1439958, - -16270480, - -1079989, - -793782, - 4625402, - 10647766, - -5043801, - 1220118, - 30494170, - -11440799 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -5037580, - -13028295, - -2970559, - -3061767, - 15640974, - -6701666, - -26739026, - 926050, - -1684339, - -13333647 - ]), - FieldElement.fromList([ - 13908495, - -3549272, - 30919928, - -6273825, - -21521863, - 7989039, - 9021034, - 9078865, - 3353509, - 4033511 - ]), - FieldElement.fromList([ - -29663431, - -15113610, - 32259991, - -344482, - 24295849, - -12912123, - 23161163, - 8839127, - 27485041, - 7356032 - ]), - ), - ]), - List.from([ - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 9661027, - 705443, - 11980065, - -5370154, - -1628543, - 14661173, - -6346142, - 2625015, - 28431036, - -16771834 - ]), - FieldElement.fromList([ - -23839233, - -8311415, - -25945511, - 7480958, - -17681669, - -8354183, - -22545972, - 14150565, - 15970762, - 4099461 - ]), - FieldElement.fromList([ - 29262576, - 16756590, - 26350592, - -8793563, - 8529671, - -11208050, - 13617293, - -9937143, - 11465739, - 8317062 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -25493081, - -6962928, - 32500200, - -9419051, - -23038724, - -2302222, - 14898637, - 3848455, - 20969334, - -5157516 - ]), - FieldElement.fromList([ - -20384450, - -14347713, - -18336405, - 13884722, - -33039454, - 2842114, - -21610826, - -3649888, - 11177095, - 14989547 - ]), - FieldElement.fromList([ - -24496721, - -11716016, - 16959896, - 2278463, - 12066309, - 10137771, - 13515641, - 2581286, - -28487508, - 9930240 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -17751622, - -2097826, - 16544300, - -13009300, - -15914807, - -14949081, - 18345767, - -13403753, - 16291481, - -5314038 - ]), - FieldElement.fromList([ - -33229194, - 2553288, - 32678213, - 9875984, - 8534129, - 6889387, - -9676774, - 6957617, - 4368891, - 9788741 - ]), - FieldElement.fromList([ - 16660756, - 7281060, - -10830758, - 12911820, - 20108584, - -8101676, - -21722536, - -8613148, - 16250552, - -11111103 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -19765507, - 2390526, - -16551031, - 14161980, - 1905286, - 6414907, - 4689584, - 10604807, - -30190403, - 4782747 - ]), - FieldElement.fromList([ - -1354539, - 14736941, - -7367442, - -13292886, - 7710542, - -14155590, - -9981571, - 4383045, - 22546403, - 437323 - ]), - FieldElement.fromList([ - 31665577, - -12180464, - -16186830, - 1491339, - -18368625, - 3294682, - 27343084, - 2786261, - -30633590, - -14097016 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -14467279, - -683715, - -33374107, - 7448552, - 19294360, - 14334329, - -19690631, - 2355319, - -19284671, - -6114373 - ]), - FieldElement.fromList([ - 15121312, - -15796162, - 6377020, - -6031361, - -10798111, - -12957845, - 18952177, - 15496498, - -29380133, - 11754228 - ]), - FieldElement.fromList([ - -2637277, - -13483075, - 8488727, - -14303896, - 12728761, - -1622493, - 7141596, - 11724556, - 22761615, - -10134141 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - 16918416, - 11729663, - -18083579, - 3022987, - -31015732, - -13339659, - -28741185, - -12227393, - 32851222, - 11717399 - ]), - FieldElement.fromList([ - 11166634, - 7338049, - -6722523, - 4531520, - -29468672, - -7302055, - 31474879, - 3483633, - -1193175, - -4030831 - ]), - FieldElement.fromList([ - -185635, - 9921305, - 31456609, - -13536438, - -12013818, - 13348923, - 33142652, - 6546660, - -19985279, - -3948376 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -32460596, - 11266712, - -11197107, - -7899103, - 31703694, - 3855903, - -8537131, - -12833048, - -30772034, - -15486313 - ]), - FieldElement.fromList([ - -18006477, - 12709068, - 3991746, - -6479188, - -21491523, - -10550425, - -31135347, - -16049879, - 10928917, - 3011958 - ]), - FieldElement.fromList([ - -6957757, - -15594337, - 31696059, - 334240, - 29576716, - 14796075, - -30831056, - -12805180, - 18008031, - 10258577 - ]), - ), - PreComputedGroupElement.fromList( - FieldElement.fromList([ - -22448644, - 15655569, - 7018479, - -4410003, - -30314266, - -1201591, - -1853465, - 1367120, - 25127874, - 6671743 - ]), - FieldElement.fromList([ - 29701166, - -14373934, - -10878120, - 9279288, - -17568, - 13127210, - 21382910, - 11042292, - 25838796, - 4642684 - ]), - FieldElement.fromList([ - -20430234, - 14955537, - -24126347, - 8124619, - -5369288, - -5990470, - 30468147, - -13900640, - 18423289, - 4177476 - ]), - ), - ]), -]); diff --git a/ed25519_edwards/lib/src/edwards25519.dart b/ed25519_edwards/lib/src/edwards25519.dart deleted file mode 100644 index c9f1b5b..0000000 --- a/ed25519_edwards/lib/src/edwards25519.dart +++ /dev/null @@ -1,2127 +0,0 @@ -import 'dart:typed_data'; - -import 'package:adaptive_number/adaptive_number.dart'; -import 'package:ed25519_edwards/src/numbers.dart'; - -import 'const.dart'; - -class FieldElement { - late List innerList; - - FieldElement() { - innerList = List.generate(10, (index) => Number.zero); - } - - FieldElement.fromList(List list) { - innerList = list.map((e) => Number(e)).toList(); - } - - Number operator [](int index) { - return innerList[index]; - } - - void operator []=(int index, Number value) { - innerList[index] = value; - } - - int get length => innerList.length; -} - -void fieldElementCopy( - FieldElement src, int srcPos, FieldElement dest, int destPos, int length) { - dest.innerList.setRange(destPos, length + destPos, src.innerList, srcPos); -} - -void fieldElementFullCopy(FieldElement src, FieldElement dest) { - fieldElementCopy(src, 0, dest, 0, dest.length); -} - -var zero = FieldElement(); - -void FeZero(FieldElement fe) { - fieldElementFullCopy(zero, fe); -} - -void FeOne(FieldElement fe) { - FeZero(fe); - fe[0] = Number.one; -} - -void FeAdd(FieldElement dst, FieldElement a, FieldElement b) { - dst[0] = a[0] + b[0]; - dst[1] = a[1] + b[1]; - dst[2] = a[2] + b[2]; - dst[3] = a[3] + b[3]; - dst[4] = a[4] + b[4]; - dst[5] = a[5] + b[5]; - dst[6] = a[6] + b[6]; - dst[7] = a[7] + b[7]; - dst[8] = a[8] + b[8]; - dst[9] = a[9] + b[9]; -} - -void FeSub(FieldElement dst, FieldElement a, FieldElement b) { - dst[0] = a[0] - b[0]; - dst[1] = a[1] - b[1]; - dst[2] = a[2] - b[2]; - dst[3] = a[3] - b[3]; - dst[4] = a[4] - b[4]; - dst[5] = a[5] - b[5]; - dst[6] = a[6] - b[6]; - dst[7] = a[7] - b[7]; - dst[8] = a[8] - b[8]; - dst[9] = a[9] - b[9]; -} - -void FeCopy(FieldElement dst, FieldElement src) { - fieldElementFullCopy(src, dst); -} - -/// Replace (f,g) with (g,g) if b == 1; -/// replace (f,g) with (f,g) if b == 0. -/// -/// Preconditions: b in {0,1}. -void FeCMove(FieldElement f, FieldElement g, Number b) { - b = -b; - f[0] ^= b & (f[0] ^ g[0]); - f[1] ^= b & (f[1] ^ g[1]); - f[2] ^= b & (f[2] ^ g[2]); - f[3] ^= b & (f[3] ^ g[3]); - f[4] ^= b & (f[4] ^ g[4]); - f[5] ^= b & (f[5] ^ g[5]); - f[6] ^= b & (f[6] ^ g[6]); - f[7] ^= b & (f[7] ^ g[7]); - f[8] ^= b & (f[8] ^ g[8]); - f[9] ^= b & (f[9] ^ g[9]); -} - -Number load3(Uint8List input) { - int r; - r = input[0]; - r |= input[1] << 8; - r |= input[2] << 16; - return Number(r); -} - -Number load4(Uint8List input) { - int r; - r = input[0]; - r |= input[1] << 8; - r |= input[2] << 16; - r |= input[3] << 24; - return Number(r); -} - -void FeFromBytes(FieldElement dst, Uint8List src) { - var h0 = load4(src.sublist(0, src.length)); - var h1 = load3(src.sublist(4, src.length)) << 6; - var h2 = load3(src.sublist(7, src.length)) << 5; - var h3 = load3(src.sublist(10, src.length)) << 3; - var h4 = load3(src.sublist(13, src.length)) << 2; - var h5 = load4(src.sublist(16, src.length)); - var h6 = load3(src.sublist(20, src.length)) << 7; - var h7 = load3(src.sublist(23, src.length)) << 5; - var h8 = load3(src.sublist(26, src.length)) << 4; - var h9 = (load3(src.sublist(29, src.length)) & Number(8388607)) << 2; - - FeCombine(dst, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9); -} - -/// FeToBytes marshals h to s. -/// Preconditions: -/// |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. -/// -/// Write p=2^255-19; q=floor(h/p). -/// Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))). -/// -/// Proof: -/// Have |h|<=p so |q|<=1 so |19^2 2^(-255) q|<1/4. -/// Also have |h-2^230 h9|<2^230 so |19 2^(-255)(h-2^230 h9)|<1/4. -/// -/// Write y=2^(-1)-19^2 2^(-255)q-19 2^(-255)(h-2^230 h9). -/// Then 0.filled(10, Number.zero); - - var q = (Numbers.v19 * h[9] + (Number.one << 24)) >> 25; - q = (h[0] + q) >> 26; - q = (h[1] + q) >> 25; - q = (h[2] + q) >> 26; - q = (h[3] + q) >> 25; - q = (h[4] + q) >> 26; - q = (h[5] + q) >> 25; - q = (h[6] + q) >> 26; - q = (h[7] + q) >> 25; - q = (h[8] + q) >> 26; - q = (h[9] + q) >> 25; - - // Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20. - h[0] += Numbers.v19 * q; - // Goal: Output h-2^255 q, which is between 0 and 2^255-20. - - carry[0] = h[0] >> 26; - h[1] += carry[0]; - h[0] -= carry[0] << 26; - carry[1] = h[1] >> 25; - h[2] += carry[1]; - h[1] -= carry[1] << 25; - carry[2] = h[2] >> 26; - h[3] += carry[2]; - h[2] -= carry[2] << 26; - carry[3] = h[3] >> 25; - h[4] += carry[3]; - h[3] -= carry[3] << 25; - carry[4] = h[4] >> 26; - h[5] += carry[4]; - h[4] -= carry[4] << 26; - carry[5] = h[5] >> 25; - h[6] += carry[5]; - h[5] -= carry[5] << 25; - carry[6] = h[6] >> 26; - h[7] += carry[6]; - h[6] -= carry[6] << 26; - carry[7] = h[7] >> 25; - h[8] += carry[7]; - h[7] -= carry[7] << 25; - carry[8] = h[8] >> 26; - h[9] += carry[8]; - h[8] -= carry[8] << 26; - carry[9] = h[9] >> 25; - h[9] -= carry[9] << 25; - // h10 = carry9 - - // Goal: Output h[0]+...+2^255 h10-2^255 q, which is between 0 and 2^255-20. - // Have h[0]+...+2^230 h[9] between 0 and 2^255-1; - // evidently 2^255 h10-2^255 q = 0. - // Goal: Output h[0]+...+2^230 h[9]. - - s[0] = (h[0] >> 0).intValue; - s[1] = (h[0] >> 8).intValue; - s[2] = (h[0] >> 16).intValue; - s[3] = ((h[0] >> 24) | (h[1] << 2)).intValue; - s[4] = (h[1] >> 6).intValue; - s[5] = (h[1] >> 14).intValue; - s[6] = ((h[1] >> 22) | (h[2] << 3)).intValue; - s[7] = (h[2] >> 5).intValue; - s[8] = (h[2] >> 13).intValue; - s[9] = ((h[2] >> 21) | (h[3] << 5)).intValue; - s[10] = (h[3] >> 3).intValue; - s[11] = (h[3] >> 11).intValue; - s[12] = ((h[3] >> 19) | (h[4] << 6)).intValue; - s[13] = (h[4] >> 2).intValue; - s[14] = (h[4] >> 10).intValue; - s[15] = (h[4] >> 18).intValue; - s[16] = (h[5] >> 0).intValue; - s[17] = (h[5] >> 8).intValue; - s[18] = (h[5] >> 16).intValue; - s[19] = ((h[5] >> 24) | (h[6] << 1)).intValue; - s[20] = (h[6] >> 7).intValue; - s[21] = (h[6] >> 15).intValue; - s[22] = ((h[6] >> 23) | (h[7] << 3)).intValue; - s[23] = (h[7] >> 5).intValue; - s[24] = (h[7] >> 13).intValue; - s[25] = ((h[7] >> 21) | (h[8] << 4)).intValue; - s[26] = (h[8] >> 4).intValue; - s[27] = (h[8] >> 12).intValue; - s[28] = ((h[8] >> 20) | (h[9] << 6)).intValue; - s[29] = (h[9] >> 2).intValue; - s[30] = (h[9] >> 10).intValue; - s[31] = (h[9] >> 18).intValue; -} - -int FeIsNegative(FieldElement f) { - var s = Uint8List(32); - FeToBytes(s, f); - return s[0] & 1; -} - -int FeIsNonZero(FieldElement f) { - var s = Uint8List(32); - FeToBytes(s, f); - var x = 0; - for (var i = 0; i < s.length; i++) { - x |= s[i]; - } - x |= x >> 4; - x |= x >> 2; - x |= x >> 1; - return x & 1; -} - -/// FeNeg sets h = -f -/// -/// Preconditions: -/// |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. -/// -/// Postconditions: -/// |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. -void FeNeg(FieldElement h, FieldElement f) { - h[0] = -f[0]; - h[1] = -f[1]; - h[2] = -f[2]; - h[3] = -f[3]; - h[4] = -f[4]; - h[5] = -f[5]; - h[6] = -f[6]; - h[7] = -f[7]; - h[8] = -f[8]; - h[9] = -f[9]; -} - -void FeCombine(FieldElement h, Number h0, Number h1, Number h2, Number h3, - Number h4, Number h5, Number h6, Number h7, Number h8, Number h9) { - var c0 = Number.zero; - var c1 = Number.zero; - var c2 = Number.zero; - var c3 = Number.zero; - var c4 = Number.zero; - var c5 = Number.zero; - var c6 = Number.zero; - var c7 = Number.zero; - var c8 = Number.zero; - var c9 = Number.zero; - - /* - |h0| <= (1.1*1.1*2^52*(1+19+19+19+19)+1.1*1.1*2^50*(38+38+38+38+38)) - i.e. |h0| <= 1.2*2^59; narrower ranges for h2, h4, h6, h8 - |h1| <= (1.1*1.1*2^51*(1+1+19+19+19+19+19+19+19+19)) - i.e. |h1| <= 1.5*2^58; narrower ranges for h3, h5, h7, h9 - */ - - c0 = (h0 + (Number.one << 25)) >> 26; - h1 += c0; - h0 -= c0 << 26; - c4 = (h4 + (Number.one << 25)) >> 26; - h5 += c4; - h4 -= c4 << 26; - /* |h0| <= 2^25 */ - /* |h4| <= 2^25 */ - /* |h1| <= 1.51*2^58 */ - /* |h5| <= 1.51*2^58 */ - - c1 = (h1 + (Number.one << 24)) >> 25; - h2 += c1; - h1 -= c1 << 25; - c5 = (h5 + (Number.one << 24)) >> 25; - h6 += c5; - h5 -= c5 << 25; - /* |h1| <= 2^24; from now on fits into int32 */ - /* |h5| <= 2^24; from now on fits into int32 */ - /* |h2| <= 1.21*2^59 */ - /* |h6| <= 1.21*2^59 */ - - c2 = (h2 + (Number.one << 25)) >> 26; - h3 += c2; - h2 -= c2 << 26; - c6 = (h6 + (Number.one << 25)) >> 26; - h7 += c6; - h6 -= c6 << 26; - /* |h2| <= 2^25; from now on fits into int32 unchanged */ - /* |h6| <= 2^25; from now on fits into int32 unchanged */ - /* |h3| <= 1.51*2^58 */ - /* |h7| <= 1.51*2^58 */ - - c3 = (h3 + (Number.one << 24)) >> 25; - h4 += c3; - h3 -= c3 << 25; - c7 = (h7 + (Number.one << 24)) >> 25; - h8 += c7; - h7 -= c7 << 25; - /* |h3| <= 2^24; from now on fits into int32 unchanged */ - /* |h7| <= 2^24; from now on fits into int32 unchanged */ - /* |h4| <= 1.52*2^33 */ - /* |h8| <= 1.52*2^33 */ - - c4 = (h4 + (Number.one << 25)) >> 26; - h5 += c4; - h4 -= c4 << 26; - c8 = (h8 + (Number.one << 25)) >> 26; - h9 += c8; - h8 -= c8 << 26; - /* |h4| <= 2^25; from now on fits into int32 unchanged */ - /* |h8| <= 2^25; from now on fits into int32 unchanged */ - /* |h5| <= 1.01*2^24 */ - /* |h9| <= 1.51*2^58 */ - - c9 = (h9 + (Number.one << 24)) >> 25; - h0 += c9 * Numbers.v19; - h9 -= c9 << 25; - /* |h9| <= 2^24; from now on fits into int32 unchanged */ - /* |h0| <= 1.8*2^37 */ - - c0 = (h0 + (Number.one << 25)) >> 26; - h1 += c0; - h0 -= c0 << 26; - /* |h0| <= 2^25; from now on fits into int32 unchanged */ - /* |h1| <= 1.01*2^24 */ - - h[0] = h0; - h[1] = h1; - h[2] = h2; - h[3] = h3; - h[4] = h4; - h[5] = h5; - h[6] = h6; - h[7] = h7; - h[8] = h8; - h[9] = h9; -} - -/// FeMul calculates h = f * g -/// Can overlap h with f or g. -/// -/// Preconditions: -/// |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. -/// |g| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. -/// -/// Postconditions: -/// |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. -/// -/// Notes on implementation strategy: -/// -/// Using schoolbook multiplication. -/// Karatsuba would save a little in some cost models. -/// -/// Most multiplications by 2 and 19 are 32-bit precomputations; -/// cheaper than 64-bit postcomputations. -/// -/// There is one remaining multiplication by 19 in the carry chain; -/// one *19 precomputation can be merged into this, -/// but the resulting data flow is considerably less clean. -/// -/// There are 12 carries below. -/// 10 of them are 2-way parallelizable and vectorizable. -/// Can get away with 11 carries, but then data flow is much deeper. -/// -/// With tighter constraints on inputs, can squeeze carries into int32. -void FeMul(FieldElement h, FieldElement f, FieldElement g) { - var f0 = f[0]; - var f1 = f[1]; - var f2 = f[2]; - var f3 = f[3]; - var f4 = f[4]; - var f5 = f[5]; - var f6 = f[6]; - var f7 = f[7]; - var f8 = f[8]; - var f9 = f[9]; - - var f1_2 = Number.two * f[1]; - var f3_2 = Number.two * f[3]; - var f5_2 = Number.two * f[5]; - var f7_2 = Number.two * f[7]; - var f9_2 = Number.two * f[9]; - - var g0 = g[0]; - var g1 = g[1]; - var g2 = g[2]; - var g3 = g[3]; - var g4 = g[4]; - var g5 = g[5]; - var g6 = g[6]; - var g7 = g[7]; - var g8 = g[8]; - var g9 = g[9]; - - var g1_19 = Numbers.v19 * g[1]; /* 1.4*2^29 */ - var g2_19 = Numbers.v19 * g[2]; /* 1.4*2^30; still ok */ - var g3_19 = Numbers.v19 * g[3]; - var g4_19 = Numbers.v19 * g[4]; - var g5_19 = Numbers.v19 * g[5]; - var g6_19 = Numbers.v19 * g[6]; - var g7_19 = Numbers.v19 * g[7]; - var g8_19 = Numbers.v19 * g[8]; - var g9_19 = Numbers.v19 * g[9]; - - var h0 = f0 * g0 + - f1_2 * g9_19 + - f2 * g8_19 + - f3_2 * g7_19 + - f4 * g6_19 + - f5_2 * g5_19 + - f6 * g4_19 + - f7_2 * g3_19 + - f8 * g2_19 + - f9_2 * g1_19; - var h1 = f0 * g1 + - f1 * g0 + - f2 * g9_19 + - f3 * g8_19 + - f4 * g7_19 + - f5 * g6_19 + - f6 * g5_19 + - f7 * g4_19 + - f8 * g3_19 + - f9 * g2_19; - var h2 = f0 * g2 + - f1_2 * g1 + - f2 * g0 + - f3_2 * g9_19 + - f4 * g8_19 + - f5_2 * g7_19 + - f6 * g6_19 + - f7_2 * g5_19 + - f8 * g4_19 + - f9_2 * g3_19; - var h3 = f0 * g3 + - f1 * g2 + - f2 * g1 + - f3 * g0 + - f4 * g9_19 + - f5 * g8_19 + - f6 * g7_19 + - f7 * g6_19 + - f8 * g5_19 + - f9 * g4_19; - var h4 = f0 * g4 + - f1_2 * g3 + - f2 * g2 + - f3_2 * g1 + - f4 * g0 + - f5_2 * g9_19 + - f6 * g8_19 + - f7_2 * g7_19 + - f8 * g6_19 + - f9_2 * g5_19; - var h5 = f0 * g5 + - f1 * g4 + - f2 * g3 + - f3 * g2 + - f4 * g1 + - f5 * g0 + - f6 * g9_19 + - f7 * g8_19 + - f8 * g7_19 + - f9 * g6_19; - var h6 = f0 * g6 + - f1_2 * g5 + - f2 * g4 + - f3_2 * g3 + - f4 * g2 + - f5_2 * g1 + - f6 * g0 + - f7_2 * g9_19 + - f8 * g8_19 + - f9_2 * g7_19; - var h7 = f0 * g7 + - f1 * g6 + - f2 * g5 + - f3 * g4 + - f4 * g3 + - f5 * g2 + - f6 * g1 + - f7 * g0 + - f8 * g9_19 + - f9 * g8_19; - var h8 = f0 * g8 + - f1_2 * g7 + - f2 * g6 + - f3_2 * g5 + - f4 * g4 + - f5_2 * g3 + - f6 * g2 + - f7_2 * g1 + - f8 * g0 + - f9_2 * g9_19; - var h9 = f0 * g9 + - f1 * g8 + - f2 * g7 + - f3 * g6 + - f4 * g5 + - f5 * g4 + - f6 * g3 + - f7 * g2 + - f8 * g1 + - f9 * g0; - - FeCombine(h, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9); -} - -List feSquare(FieldElement f) { - var f0 = f[0]; - var f1 = f[1]; - var f2 = f[2]; - var f3 = f[3]; - var f4 = f[4]; - var f5 = f[5]; - var f6 = f[6]; - var f7 = f[7]; - var f8 = f[8]; - var f9 = f[9]; - var f0_2 = Number.two * f[0]; - var f1_2 = Number.two * f[1]; - var f2_2 = Number.two * f[2]; - var f3_2 = Number.two * f[3]; - var f4_2 = Number.two * f[4]; - var f5_2 = Number.two * f[5]; - var f6_2 = Number.two * f[6]; - var f7_2 = Number.two * f[7]; - var f5_38 = Numbers.v38 * f5; // 1.31*2^30 - var f6_19 = Numbers.v19 * f6; // 1.31*2^30 - var f7_38 = Numbers.v38 * f7; // 1.31*2^30 - var f8_19 = Numbers.v19 * f8; // 1.31*2^30 - var f9_38 = Numbers.v38 * f9; // 1.31*2^30 - - var h0 = f0 * f0 + - f1_2 * f9_38 + - f2_2 * f8_19 + - f3_2 * f7_38 + - f4_2 * f6_19 + - f5 * f5_38; - var h1 = f0_2 * f1 + f2 * f9_38 + f3_2 * f8_19 + f4 * f7_38 + f5_2 * f6_19; - var h2 = f0_2 * f2 + - f1_2 * f1 + - f3_2 * f9_38 + - f4_2 * f8_19 + - f5_2 * f7_38 + - f6 * f6_19; - var h3 = f0_2 * f3 + f1_2 * f2 + f4 * f9_38 + f5_2 * f8_19 + f6 * f7_38; - var h4 = f0_2 * f4 + - f1_2 * f3_2 + - f2 * f2 + - f5_2 * f9_38 + - f6_2 * f8_19 + - f7 * f7_38; - var h5 = f0_2 * f5 + f1_2 * f4 + f2_2 * f3 + f6 * f9_38 + f7_2 * f8_19; - var h6 = f0_2 * f6 + - f1_2 * f5_2 + - f2_2 * f4 + - f3_2 * f3 + - f7_2 * f9_38 + - f8 * f8_19; - var h7 = f0_2 * f7 + f1_2 * f6 + f2_2 * f5 + f3_2 * f4 + f8 * f9_38; - var h8 = - f0_2 * f8 + f1_2 * f7_2 + f2_2 * f6 + f3_2 * f5_2 + f4 * f4 + f9 * f9_38; - var h9 = f0_2 * f9 + f1_2 * f8 + f2_2 * f7 + f3_2 * f6 + f4_2 * f5; - - return [h0, h1, h2, h3, h4, h5, h6, h7, h8, h9]; -} - -/// FeSquare calculates h = f*f. Can overlap h with f. -/// -/// Preconditions: -/// |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. -/// -/// Postconditions: -/// |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. -void FeSquare(FieldElement h, FieldElement f) { - var fs = feSquare(f); - var h0 = fs[0]; - var h1 = fs[1]; - var h2 = fs[2]; - var h3 = fs[3]; - var h4 = fs[4]; - var h5 = fs[5]; - var h6 = fs[6]; - var h7 = fs[7]; - var h8 = fs[8]; - var h9 = fs[9]; - FeCombine(h, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9); -} - -/// FeSquare2 sets h = 2 * f * f -/// -/// Can overlap h with f. -/// -/// Preconditions: -/// |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc. -/// -/// Postconditions: -/// |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc. -/// See fe_mul.c for discussion of implementation strategy. -void FeSquare2(FieldElement h, FieldElement f) { - var fs = feSquare(f); - var h0 = fs[0]; - var h1 = fs[1]; - var h2 = fs[2]; - var h3 = fs[3]; - var h4 = fs[4]; - var h5 = fs[5]; - var h6 = fs[6]; - var h7 = fs[7]; - var h8 = fs[8]; - var h9 = fs[9]; - - h0 += h0; - h1 += h1; - h2 += h2; - h3 += h3; - h4 += h4; - h5 += h5; - h6 += h6; - h7 += h7; - h8 += h8; - h9 += h9; - - FeCombine(h, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9); -} - -void FeInvert(FieldElement out, FieldElement z) { - var t0 = FieldElement(); - var t1 = FieldElement(); - var t2 = FieldElement(); - var t3 = FieldElement(); - var i = 0; - - FeSquare(t0, z); // 2^1 - FeSquare(t1, t0); // 2^2 - for (i = 1; i < 2; i++) { - // 2^3 - FeSquare(t1, t1); - } - FeMul(t1, z, t1); // 2^3 + 2^0 - FeMul(t0, t0, t1); // 2^3 + 2^1 + 2^0 - FeSquare(t2, t0); // 2^4 + 2^2 + 2^1 - FeMul(t1, t1, t2); // 2^4 + 2^3 + 2^2 + 2^1 + 2^0 - FeSquare(t2, t1); // 5,4,3,2,1 - for (i = 1; i < 5; i++) { - // 9,8,7,6,5 - FeSquare(t2, t2); - } - FeMul(t1, t2, t1); // 9,8,7,6,5,4,3,2,1,0 - FeSquare(t2, t1); // 10..1 - for (i = 1; i < 10; i++) { - // 19..10 - FeSquare(t2, t2); - } - FeMul(t2, t2, t1); // 19..0 - FeSquare(t3, t2); // 20..1 - for (i = 1; i < 20; i++) { - // 39..20 - FeSquare(t3, t3); - } - FeMul(t2, t3, t2); // 39..0 - FeSquare(t2, t2); // 40..1 - for (i = 1; i < 10; i++) { - // 49..10 - FeSquare(t2, t2); - } - FeMul(t1, t2, t1); // 49..0 - FeSquare(t2, t1); // 50..1 - for (i = 1; i < 50; i++) { - // 99..50 - FeSquare(t2, t2); - } - FeMul(t2, t2, t1); // 99..0 - FeSquare(t3, t2); // 100..1 - for (i = 1; i < 100; i++) { - // 199..100 - FeSquare(t3, t3); - } - FeMul(t2, t3, t2); // 199..0 - FeSquare(t2, t2); // 200..1 - for (i = 1; i < 50; i++) { - // 249..50 - FeSquare(t2, t2); - } - FeMul(t1, t2, t1); // 249..0 - FeSquare(t1, t1); // 250..1 - for (i = 1; i < 5; i++) { - // 254..5 - FeSquare(t1, t1); - } - FeMul(out, t1, t0); // 254..5,3,1,0 -} - -void fePow22523(FieldElement out, FieldElement z) { - var t0 = FieldElement(); - var t1 = FieldElement(); - var t2 = FieldElement(); - var i = 0; - - FeSquare(t0, z); - for (i = 1; i < 1; i++) { - FeSquare(t0, t0); - } - FeSquare(t1, t0); - for (i = 1; i < 2; i++) { - FeSquare(t1, t1); - } - FeMul(t1, z, t1); - FeMul(t0, t0, t1); - FeSquare(t0, t0); - for (i = 1; i < 1; i++) { - FeSquare(t0, t0); - } - FeMul(t0, t1, t0); - FeSquare(t1, t0); - for (i = 1; i < 5; i++) { - FeSquare(t1, t1); - } - FeMul(t0, t1, t0); - FeSquare(t1, t0); - for (i = 1; i < 10; i++) { - FeSquare(t1, t1); - } - FeMul(t1, t1, t0); - FeSquare(t2, t1); - for (i = 1; i < 20; i++) { - FeSquare(t2, t2); - } - FeMul(t1, t2, t1); - FeSquare(t1, t1); - for (i = 1; i < 10; i++) { - FeSquare(t1, t1); - } - FeMul(t0, t1, t0); - FeSquare(t1, t0); - for (i = 1; i < 50; i++) { - FeSquare(t1, t1); - } - FeMul(t1, t1, t0); - FeSquare(t2, t1); - for (i = 1; i < 100; i++) { - FeSquare(t2, t2); - } - FeMul(t1, t2, t1); - FeSquare(t1, t1); - for (i = 1; i < 50; i++) { - FeSquare(t1, t1); - } - FeMul(t0, t1, t0); - FeSquare(t0, t0); - for (i = 1; i < 2; i++) { - FeSquare(t0, t0); - } - FeMul(out, t0, z); -} - -/// Group elements are members of the elliptic curve -x^2 + y^2 = 1 + d * x^2 * -/// y^2 where d = -121665/121666. -/// -/// Several representations are used: -/// ProjectiveGroupElement: (X:Y:Z) satisfying x=X/Z, y=Y/Z -/// ExtendedGroupElement: (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT -/// CompletedGroupElement: ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T -/// PreComputedGroupElement: (y+x,y-x,2dxy) -class ProjectiveGroupElement { - FieldElement X = FieldElement(); - FieldElement Y = FieldElement(); - FieldElement Z = FieldElement(); - - void Zero() { - FeZero(X); - FeOne(Y); - FeOne(Z); - } - - void Double(CompletedGroupElement r) { - var t0 = FieldElement(); - - FeSquare(r.X, X); - FeSquare(r.Z, Y); - FeSquare2(r.T, Z); - FeAdd(r.Y, X, Y); - FeSquare(t0, r.Y); - FeAdd(r.Y, r.Z, r.X); - FeSub(r.Z, r.Z, r.X); - FeSub(r.X, t0, r.Y); - FeSub(r.T, r.T, r.Z); - } - - void ToBytes(Uint8List s) { - var recip = FieldElement(); - var x = FieldElement(); - var y = FieldElement(); - - FeInvert(recip, Z); - FeMul(x, X, recip); - FeMul(y, Y, recip); - FeToBytes(s, y); - s[31] ^= FeIsNegative(x) << 7; - } -} - -class ExtendedGroupElement { - FieldElement X = FieldElement(); - FieldElement Y = FieldElement(); - FieldElement Z = FieldElement(); - FieldElement T = FieldElement(); - - void Zero() { - FeZero(X); - FeOne(Y); - FeOne(Z); - FeZero(T); - } - - void Double(CompletedGroupElement r) { - var q = ProjectiveGroupElement(); - ToProjective(q); - q.Double(r); - } - - void ToCached(CachedGroupElement r) { - FeAdd(r.yPlusX, Y, X); - FeSub(r.yMinusX, Y, X); - FeCopy(r.Z, Z); - FeMul(r.T2d, T, d2); - } - - void ToProjective(ProjectiveGroupElement r) { - FeCopy(r.X, X); - FeCopy(r.Y, Y); - FeCopy(r.Z, Z); - } - - void ToBytes(Uint8List s) { - var recip = FieldElement(); - var x = FieldElement(); - var y = FieldElement(); - - FeInvert(recip, Z); - FeMul(x, X, recip); - FeMul(y, Y, recip); - FeToBytes(s, y); - s[31] ^= FeIsNegative(x) << 7; - } - - bool FromBytes(Uint8List s) { - var u = FieldElement(); - var v = FieldElement(); - var v3 = FieldElement(); - var vxx = FieldElement(); - var check = FieldElement(); - - FeFromBytes(Y, s); - FeOne(Z); - FeSquare(u, Y); - FeMul(v, u, d); - FeSub(u, u, Z); // y = y^2-1 - FeAdd(v, v, Z); // v = dy^2+1 - - FeSquare(v3, v); - FeMul(v3, v3, v); // v3 = v^3 - FeSquare(X, v3); - FeMul(X, X, v); - FeMul(X, X, u); // x = uv^7 - - fePow22523(X, X); // x = (uv^7)^((q-5)/8) - FeMul(X, X, v3); - FeMul(X, X, u); // x = uv^3(uv^7)^((q-5)/8) - - var tmpX = Uint8List(32); - var tmp2 = Uint8List(32); - - FeSquare(vxx, X); - FeMul(vxx, vxx, v); - FeSub(check, vxx, u); // vx^2-u - if (FeIsNonZero(check) == 1) { - FeAdd(check, vxx, u); // vx^2+u - if (FeIsNonZero(check) == 1) { - return false; - } - FeMul(X, X, SqrtM1); - - FeToBytes(tmpX, X); - for (var i = 0; i < tmp2.length; i++) { - tmp2[31 - i] = tmp2[i]; - } - } - - if (FeIsNegative(X) != (s[31] >> 7)) { - FeNeg(X, X); - } - - FeMul(T, X, Y); - return true; - } -} - -class CompletedGroupElement { - FieldElement X = FieldElement(); - FieldElement Y = FieldElement(); - FieldElement Z = FieldElement(); - FieldElement T = FieldElement(); - - void ToProjective(ProjectiveGroupElement r) { - FeMul(r.X, X, T); - FeMul(r.Y, Y, Z); - FeMul(r.Z, Z, T); - } - - void ToExtended(ExtendedGroupElement r) { - FeMul(r.X, X, T); - FeMul(r.Y, Y, Z); - FeMul(r.Z, Z, T); - FeMul(r.T, X, Y); - } -} - -class PreComputedGroupElement { - FieldElement yPlusX = FieldElement(); - FieldElement yMinusX = FieldElement(); - FieldElement xy2d = FieldElement(); - - PreComputedGroupElement(); - - PreComputedGroupElement.fromList( - FieldElement ypx, FieldElement ymx, FieldElement xy2d) { - yPlusX = ypx; - yMinusX = ymx; - this.xy2d = xy2d; - } - - void Zero() { - FeOne(yPlusX); - FeOne(yMinusX); - FeZero(xy2d); - } -} - -class CachedGroupElement { - FieldElement yPlusX = FieldElement(); - FieldElement yMinusX = FieldElement(); - FieldElement Z = FieldElement(); - FieldElement T2d = FieldElement(); -} - -void geAdd( - CompletedGroupElement r, ExtendedGroupElement p, CachedGroupElement q) { - var t0 = FieldElement(); - - FeAdd(r.X, p.Y, p.X); - FeSub(r.Y, p.Y, p.X); - FeMul(r.Z, r.X, q.yPlusX); - FeMul(r.Y, r.Y, q.yMinusX); - FeMul(r.T, q.T2d, p.T); - FeMul(r.X, p.Z, q.Z); - FeAdd(t0, r.X, r.X); - FeSub(r.X, r.Z, r.Y); - FeAdd(r.Y, r.Z, r.Y); - FeAdd(r.Z, t0, r.T); - FeSub(r.T, t0, r.T); -} - -void geSub( - CompletedGroupElement r, ExtendedGroupElement p, CachedGroupElement q) { - var t0 = FieldElement(); - - FeAdd(r.X, p.Y, p.X); - FeSub(r.Y, p.Y, p.X); - FeMul(r.Z, r.X, q.yMinusX); - FeMul(r.Y, r.Y, q.yPlusX); - FeMul(r.T, q.T2d, p.T); - FeMul(r.X, p.Z, q.Z); - FeAdd(t0, r.X, r.X); - FeSub(r.X, r.Z, r.Y); - FeAdd(r.Y, r.Z, r.Y); - FeSub(r.Z, t0, r.T); - FeAdd(r.T, t0, r.T); -} - -void geMixedAdd(CompletedGroupElement r, ExtendedGroupElement p, - PreComputedGroupElement q) { - var t0 = FieldElement(); - - FeAdd(r.X, p.Y, p.X); - FeSub(r.Y, p.Y, p.X); - FeMul(r.Z, r.X, q.yPlusX); - FeMul(r.Y, r.Y, q.yMinusX); - FeMul(r.T, q.xy2d, p.T); - FeAdd(t0, p.Z, p.Z); - FeSub(r.X, r.Z, r.Y); - FeAdd(r.Y, r.Z, r.Y); - FeAdd(r.Z, t0, r.T); - FeSub(r.T, t0, r.T); -} - -void geMixedSub(CompletedGroupElement r, ExtendedGroupElement p, - PreComputedGroupElement q) { - var t0 = FieldElement(); - - FeAdd(r.X, p.Y, p.X); - FeSub(r.Y, p.Y, p.X); - FeMul(r.Z, r.X, q.yMinusX); - FeMul(r.Y, r.Y, q.yPlusX); - FeMul(r.T, q.xy2d, p.T); - FeAdd(t0, p.Z, p.Z); - FeSub(r.X, r.Z, r.Y); - FeAdd(r.Y, r.Z, r.Y); - FeSub(r.Z, t0, r.T); - FeAdd(r.T, t0, r.T); -} - -void slide(Int8List r, Uint8List a) { - for (var i = 0; i < r.length; i++) { - r[i] = 1 & (a[i >> 3] >> (i & 7)); - } - - for (var i = 0; i < r.length; i++) { - if (r[i] != 0) { - for (var b = 1; b <= 6 && i + b < 256; b++) { - if (r[i + b] != 0) { - if (r[i] + (r[i + b] << b) <= 15) { - r[i] += r[i + b] << b; - r[i + b] = 0; - } else if (r[i] - (r[i + b] << b) >= -15) { - r[i] -= r[i + b] << b; - for (var k = i + b; k < 256; k++) { - if (r[k] == 0) { - r[k] = 1; - break; - } - r[k] = 0; - } - } else { - break; - } - } - } - } - } -} - -/// GeDoubleScalarMultVartime sets r = a*A + b*B -/// where a = a[0]+256*a[1]+...+256^31 a[31]. -/// and b = b[0]+256*b[1]+...+256^31 b[31]. -/// B is the Ed25519 base point (x,4/5) with x positive. -void GeDoubleScalarMultVartime(ProjectiveGroupElement r, Uint8List a, - ExtendedGroupElement A, Uint8List b) { - var aSlide = Int8List(256); - var bSlide = Int8List(256); - var Ai = List.generate( - 8, (index) => CachedGroupElement()); // A,3A,5A,7A,9A,11A,13A,15A - var t = CompletedGroupElement(); - var u = ExtendedGroupElement(); - var A2 = ExtendedGroupElement(); - int i; - - slide(aSlide, a); - slide(bSlide, b); - - A.ToCached(Ai[0]); - A.Double(t); - t.ToExtended(A2); - - for (i = 0; i < 7; i++) { - geAdd(t, A2, Ai[i]); - t.ToExtended(u); - u.ToCached(Ai[i + 1]); - } - - r.Zero(); - - for (i = 255; i >= 0; i--) { - if (aSlide[i] != 0 || bSlide[i] != 0) { - break; - } - } - - for (; i >= 0; i--) { - r.Double(t); - - if (aSlide[i] > 0) { - t.ToExtended(u); - geAdd(t, u, Ai[aSlide[i] ~/ 2]); - } else if (aSlide[i] < 0) { - t.ToExtended(u); - geSub(t, u, Ai[(-aSlide[i]) ~/ 2]); - } - - if (bSlide[i] > 0) { - t.ToExtended(u); - geMixedAdd(t, u, bi[bSlide[i] ~/ 2]); - } else if (bSlide[i] < 0) { - t.ToExtended(u); - geMixedSub(t, u, bi[(-bSlide[i]) ~/ 2]); - } - - t.ToProjective(r); - } -} - -/// equal returns 1 if b == c and 0 otherwise, assuming that b and c are -/// non-negative. -Number equal(Number b, Number c) { - if (b == c) { - return Number.one; - } else { - return Number.zero; - } -// var x = b ^ c; -// x--; -// return x >> 31; -} - -/// negative returns 1 if b < 0 and 0 otherwise. -Number negative(Number b) { - if (b < Number.zero) { - return Number.one; - } else { - return Number.zero; - } -// return (b >> 31) & 1; -} - -void PreComputedGroupElementCMove( - PreComputedGroupElement t, PreComputedGroupElement u, Number b) { - FeCMove(t.yPlusX, u.yPlusX, b); - FeCMove(t.yMinusX, u.yMinusX, b); - FeCMove(t.xy2d, u.xy2d, b); -} - -void selectPoint(PreComputedGroupElement t, int pos, Number b) { - var minusT = PreComputedGroupElement(); - var bNegative = negative(b); - var bAbs = b - (((-bNegative) & b) << 1); - - t.Zero(); - for (var i = 0; i < 8; i++) { - PreComputedGroupElementCMove(t, base[pos][i], equal(bAbs, Number(i + 1))); - } - FeCopy(minusT.yPlusX, t.yMinusX); - FeCopy(minusT.yMinusX, t.yPlusX); - FeNeg(minusT.xy2d, t.xy2d); - PreComputedGroupElementCMove(t, minusT, bNegative); -} - -/// GeScalarMultBase computes h = a*B, where -/// a = a[0]+256*a[1]+...+256^31 a[31] -/// B is the Ed25519 base point (x,4/5) with x positive. -/// -/// Preconditions: -/// a[31] <= 127 -void GeScalarMultBase(ExtendedGroupElement h, Uint8List a) { - var e = List.filled(64, Number.zero); - - for (var i = 0; i < a.length; i++) { - var v = a[i]; - e[2 * i] = Number(v) & Numbers.v15; - e[2 * i + 1] = Number((v >> 4)) & Numbers.v15; - } - - // each e[i] is between 0 and 15 and e[63] is between 0 and 7. - - var carry = Number.zero; - for (var i = 0; i < 63; i++) { - e[i] += carry; - carry = (e[i] + Numbers.v8) >> 4; - e[i] -= carry << 4; - } - e[63] += carry; - // each e[i] is between -8 and 8. - - h.Zero(); - var t = PreComputedGroupElement(); - var r = CompletedGroupElement(); - for (var i = 1; i < 64; i += 2) { - selectPoint(t, i ~/ 2, e[i]); - geMixedAdd(r, h, t); - r.ToExtended(h); - } - - var s = ProjectiveGroupElement(); - - h.Double(r); - r.ToProjective(s); - s.Double(r); - r.ToProjective(s); - s.Double(r); - r.ToProjective(s); - s.Double(r); - r.ToExtended(h); - - for (var i = 0; i < 64; i += 2) { - selectPoint(t, i ~/ 2, e[i]); - geMixedAdd(r, h, t); - r.ToExtended(h); - } -} - -/// The scalars are GF(2^252 + 27742317777372353535851937790883648493). - -/// Input: -/// a[0]+256*a[1]+...+256^31*a[31] = a -/// b[0]+256*b[1]+...+256^31*b[31] = b -/// c[0]+256*c[1]+...+256^31*c[31] = c -/// -/// Output: -/// s[0]+256*s[1]+...+256^31*s[31] = (ab+c) mod l -/// where l = 2^252 + 27742317777372353535851937790883648493. -void ScMulAdd(Uint8List s, Uint8List a, Uint8List b, Uint8List c) { - var a0 = Numbers.v2097151 & load3(a.sublist(0, a.length)); - var a1 = Numbers.v2097151 & (load4(a.sublist(2, a.length)) >> 5); - var a2 = Numbers.v2097151 & (load3(a.sublist(5, a.length)) >> 2); - var a3 = Numbers.v2097151 & (load4(a.sublist(7, a.length)) >> 7); - var a4 = Numbers.v2097151 & (load4(a.sublist(10, a.length)) >> 4); - var a5 = Numbers.v2097151 & (load3(a.sublist(13, a.length)) >> 1); - var a6 = Numbers.v2097151 & (load4(a.sublist(15, a.length)) >> 6); - var a7 = Numbers.v2097151 & (load3(a.sublist(18, a.length)) >> 3); - var a8 = Numbers.v2097151 & load3(a.sublist(21, a.length)); - var a9 = Numbers.v2097151 & (load4(a.sublist(23, a.length)) >> 5); - var a10 = Numbers.v2097151 & (load3(a.sublist(26, a.length)) >> 2); - var a11 = (load4(a.sublist(28, a.length)) >> 7); - - var b0 = Numbers.v2097151 & load3(b.sublist(0, b.length)); - var b1 = Numbers.v2097151 & (load4(b.sublist(2, b.length)) >> 5); - var b2 = Numbers.v2097151 & (load3(b.sublist(5, b.length)) >> 2); - var b3 = Numbers.v2097151 & (load4(b.sublist(7, b.length)) >> 7); - var b4 = Numbers.v2097151 & (load4(b.sublist(10, b.length)) >> 4); - var b5 = Numbers.v2097151 & (load3(b.sublist(13, b.length)) >> 1); - var b6 = Numbers.v2097151 & (load4(b.sublist(15, b.length)) >> 6); - var b7 = Numbers.v2097151 & (load3(b.sublist(18, b.length)) >> 3); - var b8 = Numbers.v2097151 & load3(b.sublist(21, b.length)); - var b9 = Numbers.v2097151 & (load4(b.sublist(23, b.length)) >> 5); - var b10 = Numbers.v2097151 & (load3(b.sublist(26, b.length)) >> 2); - var b11 = (load4(b.sublist(28, b.length)) >> 7); - - var c0 = Numbers.v2097151 & load3(c.sublist(0, c.length)); - var c1 = Numbers.v2097151 & (load4(c.sublist(2, c.length)) >> 5); - var c2 = Numbers.v2097151 & (load3(c.sublist(5, c.length)) >> 2); - var c3 = Numbers.v2097151 & (load4(c.sublist(7, c.length)) >> 7); - var c4 = Numbers.v2097151 & (load4(c.sublist(10, c.length)) >> 4); - var c5 = Numbers.v2097151 & (load3(c.sublist(13, c.length)) >> 1); - var c6 = Numbers.v2097151 & (load4(c.sublist(15, c.length)) >> 6); - var c7 = Numbers.v2097151 & (load3(c.sublist(18, c.length)) >> 3); - var c8 = Numbers.v2097151 & load3(c.sublist(21, c.length)); - var c9 = Numbers.v2097151 & (load4(c.sublist(23, c.length)) >> 5); - var c10 = Numbers.v2097151 & (load3(c.sublist(26, c.length)) >> 2); - var c11 = (load4(c.sublist(28, c.length)) >> 7); - - var carry = List.filled(23, Number.zero); - - var s0 = c0 + a0 * b0; - var s1 = c1 + a0 * b1 + a1 * b0; - var s2 = c2 + a0 * b2 + a1 * b1 + a2 * b0; - var s3 = c3 + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0; - var s4 = c4 + a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0; - var s5 = c5 + a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0; - var s6 = - c6 + a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 + a6 * b0; - var s7 = c7 + - a0 * b7 + - a1 * b6 + - a2 * b5 + - a3 * b4 + - a4 * b3 + - a5 * b2 + - a6 * b1 + - a7 * b0; - var s8 = c8 + - a0 * b8 + - a1 * b7 + - a2 * b6 + - a3 * b5 + - a4 * b4 + - a5 * b3 + - a6 * b2 + - a7 * b1 + - a8 * b0; - var s9 = c9 + - a0 * b9 + - a1 * b8 + - a2 * b7 + - a3 * b6 + - a4 * b5 + - a5 * b4 + - a6 * b3 + - a7 * b2 + - a8 * b1 + - a9 * b0; - var s10 = c10 + - a0 * b10 + - a1 * b9 + - a2 * b8 + - a3 * b7 + - a4 * b6 + - a5 * b5 + - a6 * b4 + - a7 * b3 + - a8 * b2 + - a9 * b1 + - a10 * b0; - var s11 = c11 + - a0 * b11 + - a1 * b10 + - a2 * b9 + - a3 * b8 + - a4 * b7 + - a5 * b6 + - a6 * b5 + - a7 * b4 + - a8 * b3 + - a9 * b2 + - a10 * b1 + - a11 * b0; - var s12 = a1 * b11 + - a2 * b10 + - a3 * b9 + - a4 * b8 + - a5 * b7 + - a6 * b6 + - a7 * b5 + - a8 * b4 + - a9 * b3 + - a10 * b2 + - a11 * b1; - var s13 = a2 * b11 + - a3 * b10 + - a4 * b9 + - a5 * b8 + - a6 * b7 + - a7 * b6 + - a8 * b5 + - a9 * b4 + - a10 * b3 + - a11 * b2; - var s14 = a3 * b11 + - a4 * b10 + - a5 * b9 + - a6 * b8 + - a7 * b7 + - a8 * b6 + - a9 * b5 + - a10 * b4 + - a11 * b3; - var s15 = a4 * b11 + - a5 * b10 + - a6 * b9 + - a7 * b8 + - a8 * b7 + - a9 * b6 + - a10 * b5 + - a11 * b4; - var s16 = - a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5; - var s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6; - var s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7; - var s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8; - var s20 = a9 * b11 + a10 * b10 + a11 * b9; - var s21 = a10 * b11 + a11 * b10; - var s22 = a11 * b11; - var s23 = Number.zero; - - carry[0] = (s0 + (Number.one << 20)) >> 21; - s1 += carry[0]; - s0 -= carry[0] << 21; - carry[2] = (s2 + (Number.one << 20)) >> 21; - s3 += carry[2]; - s2 -= carry[2] << 21; - carry[4] = (s4 + (Number.one << 20)) >> 21; - s5 += carry[4]; - s4 -= carry[4] << 21; - carry[6] = (s6 + (Number.one << 20)) >> 21; - s7 += carry[6]; - s6 -= carry[6] << 21; - carry[8] = (s8 + (Number.one << 20)) >> 21; - s9 += carry[8]; - s8 -= carry[8] << 21; - carry[10] = (s10 + (Number.one << 20)) >> 21; - s11 += carry[10]; - s10 -= carry[10] << 21; - carry[12] = (s12 + (Number.one << 20)) >> 21; - s13 += carry[12]; - s12 -= carry[12] << 21; - carry[14] = (s14 + (Number.one << 20)) >> 21; - s15 += carry[14]; - s14 -= carry[14] << 21; - carry[16] = (s16 + (Number.one << 20)) >> 21; - s17 += carry[16]; - s16 -= carry[16] << 21; - carry[18] = (s18 + (Number.one << 20)) >> 21; - s19 += carry[18]; - s18 -= carry[18] << 21; - carry[20] = (s20 + (Number.one << 20)) >> 21; - s21 += carry[20]; - s20 -= carry[20] << 21; - carry[22] = (s22 + (Number.one << 20)) >> 21; - s23 += carry[22]; - s22 -= carry[22] << 21; - - carry[1] = (s1 + (Number.one << 20)) >> 21; - s2 += carry[1]; - s1 -= carry[1] << 21; - carry[3] = (s3 + (Number.one << 20)) >> 21; - s4 += carry[3]; - s3 -= carry[3] << 21; - carry[5] = (s5 + (Number.one << 20)) >> 21; - s6 += carry[5]; - s5 -= carry[5] << 21; - carry[7] = (s7 + (Number.one << 20)) >> 21; - s8 += carry[7]; - s7 -= carry[7] << 21; - carry[9] = (s9 + (Number.one << 20)) >> 21; - s10 += carry[9]; - s9 -= carry[9] << 21; - carry[11] = (s11 + (Number.one << 20)) >> 21; - s12 += carry[11]; - s11 -= carry[11] << 21; - carry[13] = (s13 + (Number.one << 20)) >> 21; - s14 += carry[13]; - s13 -= carry[13] << 21; - carry[15] = (s15 + (Number.one << 20)) >> 21; - s16 += carry[15]; - s15 -= carry[15] << 21; - carry[17] = (s17 + (Number.one << 20)) >> 21; - s18 += carry[17]; - s17 -= carry[17] << 21; - carry[19] = (s19 + (Number.one << 20)) >> 21; - s20 += carry[19]; - s19 -= carry[19] << 21; - carry[21] = (s21 + (Number.one << 20)) >> 21; - s22 += carry[21]; - s21 -= carry[21] << 21; - - s11 += s23 * Numbers.v666643; - s12 += s23 * Numbers.v470296; - s13 += s23 * Numbers.v654183; - s14 -= s23 * Numbers.v997805; - s15 += s23 * Numbers.v136657; - s16 -= s23 * Numbers.v683901; - s23 = Number.zero; - - s10 += s22 * Numbers.v666643; - s11 += s22 * Numbers.v470296; - s12 += s22 * Numbers.v654183; - s13 -= s22 * Numbers.v997805; - s14 += s22 * Numbers.v136657; - s15 -= s22 * Numbers.v683901; - s22 = Number.zero; - - s9 += s21 * Numbers.v666643; - s10 += s21 * Numbers.v470296; - s11 += s21 * Numbers.v654183; - s12 -= s21 * Numbers.v997805; - s13 += s21 * Numbers.v136657; - s14 -= s21 * Numbers.v683901; - s21 = Number.zero; - - s8 += s20 * Numbers.v666643; - s9 += s20 * Numbers.v470296; - s10 += s20 * Numbers.v654183; - s11 -= s20 * Numbers.v997805; - s12 += s20 * Numbers.v136657; - s13 -= s20 * Numbers.v683901; - s20 = Number.zero; - - s7 += s19 * Numbers.v666643; - s8 += s19 * Numbers.v470296; - s9 += s19 * Numbers.v654183; - s10 -= s19 * Numbers.v997805; - s11 += s19 * Numbers.v136657; - s12 -= s19 * Numbers.v683901; - s19 = Number.zero; - - s6 += s18 * Numbers.v666643; - s7 += s18 * Numbers.v470296; - s8 += s18 * Numbers.v654183; - s9 -= s18 * Numbers.v997805; - s10 += s18 * Numbers.v136657; - s11 -= s18 * Numbers.v683901; - s18 = Number.zero; - - carry[6] = (s6 + (Number.one << 20)) >> 21; - s7 += carry[6]; - s6 -= carry[6] << 21; - carry[8] = (s8 + (Number.one << 20)) >> 21; - s9 += carry[8]; - s8 -= carry[8] << 21; - carry[10] = (s10 + (Number.one << 20)) >> 21; - s11 += carry[10]; - s10 -= carry[10] << 21; - carry[12] = (s12 + (Number.one << 20)) >> 21; - s13 += carry[12]; - s12 -= carry[12] << 21; - carry[14] = (s14 + (Number.one << 20)) >> 21; - s15 += carry[14]; - s14 -= carry[14] << 21; - carry[16] = (s16 + (Number.one << 20)) >> 21; - s17 += carry[16]; - s16 -= carry[16] << 21; - - carry[7] = (s7 + (Number.one << 20)) >> 21; - s8 += carry[7]; - s7 -= carry[7] << 21; - carry[9] = (s9 + (Number.one << 20)) >> 21; - s10 += carry[9]; - s9 -= carry[9] << 21; - carry[11] = (s11 + (Number.one << 20)) >> 21; - s12 += carry[11]; - s11 -= carry[11] << 21; - carry[13] = (s13 + (Number.one << 20)) >> 21; - s14 += carry[13]; - s13 -= carry[13] << 21; - carry[15] = (s15 + (Number.one << 20)) >> 21; - s16 += carry[15]; - s15 -= carry[15] << 21; - - s5 += s17 * Numbers.v666643; - s6 += s17 * Numbers.v470296; - s7 += s17 * Numbers.v654183; - s8 -= s17 * Numbers.v997805; - s9 += s17 * Numbers.v136657; - s10 -= s17 * Numbers.v683901; - s17 = Number.zero; - - s4 += s16 * Numbers.v666643; - s5 += s16 * Numbers.v470296; - s6 += s16 * Numbers.v654183; - s7 -= s16 * Numbers.v997805; - s8 += s16 * Numbers.v136657; - s9 -= s16 * Numbers.v683901; - s16 = Number.zero; - - s3 += s15 * Numbers.v666643; - s4 += s15 * Numbers.v470296; - s5 += s15 * Numbers.v654183; - s6 -= s15 * Numbers.v997805; - s7 += s15 * Numbers.v136657; - s8 -= s15 * Numbers.v683901; - s15 = Number.zero; - - s2 += s14 * Numbers.v666643; - s3 += s14 * Numbers.v470296; - s4 += s14 * Numbers.v654183; - s5 -= s14 * Numbers.v997805; - s6 += s14 * Numbers.v136657; - s7 -= s14 * Numbers.v683901; - s14 = Number.zero; - - s1 += s13 * Numbers.v666643; - s2 += s13 * Numbers.v470296; - s3 += s13 * Numbers.v654183; - s4 -= s13 * Numbers.v997805; - s5 += s13 * Numbers.v136657; - s6 -= s13 * Numbers.v683901; - s13 = Number.zero; - - s0 += s12 * Numbers.v666643; - s1 += s12 * Numbers.v470296; - s2 += s12 * Numbers.v654183; - s3 -= s12 * Numbers.v997805; - s4 += s12 * Numbers.v136657; - s5 -= s12 * Numbers.v683901; - s12 = Number.zero; - - carry[0] = (s0 + (Number.one << 20)) >> 21; - s1 += carry[0]; - s0 -= carry[0] << 21; - carry[2] = (s2 + (Number.one << 20)) >> 21; - s3 += carry[2]; - s2 -= carry[2] << 21; - carry[4] = (s4 + (Number.one << 20)) >> 21; - s5 += carry[4]; - s4 -= carry[4] << 21; - carry[6] = (s6 + (Number.one << 20)) >> 21; - s7 += carry[6]; - s6 -= carry[6] << 21; - carry[8] = (s8 + (Number.one << 20)) >> 21; - s9 += carry[8]; - s8 -= carry[8] << 21; - carry[10] = (s10 + (Number.one << 20)) >> 21; - s11 += carry[10]; - s10 -= carry[10] << 21; - - carry[1] = (s1 + (Number.one << 20)) >> 21; - s2 += carry[1]; - s1 -= carry[1] << 21; - carry[3] = (s3 + (Number.one << 20)) >> 21; - s4 += carry[3]; - s3 -= carry[3] << 21; - carry[5] = (s5 + (Number.one << 20)) >> 21; - s6 += carry[5]; - s5 -= carry[5] << 21; - carry[7] = (s7 + (Number.one << 20)) >> 21; - s8 += carry[7]; - s7 -= carry[7] << 21; - carry[9] = (s9 + (Number.one << 20)) >> 21; - s10 += carry[9]; - s9 -= carry[9] << 21; - carry[11] = (s11 + (Number.one << 20)) >> 21; - s12 += carry[11]; - s11 -= carry[11] << 21; - - s0 += s12 * Numbers.v666643; - s1 += s12 * Numbers.v470296; - s2 += s12 * Numbers.v654183; - s3 -= s12 * Numbers.v997805; - s4 += s12 * Numbers.v136657; - s5 -= s12 * Numbers.v683901; - s12 = Number.zero; - - carry[0] = s0 >> 21; - s1 += carry[0]; - s0 -= carry[0] << 21; - carry[1] = s1 >> 21; - s2 += carry[1]; - s1 -= carry[1] << 21; - carry[2] = s2 >> 21; - s3 += carry[2]; - s2 -= carry[2] << 21; - carry[3] = s3 >> 21; - s4 += carry[3]; - s3 -= carry[3] << 21; - carry[4] = s4 >> 21; - s5 += carry[4]; - s4 -= carry[4] << 21; - carry[5] = s5 >> 21; - s6 += carry[5]; - s5 -= carry[5] << 21; - carry[6] = s6 >> 21; - s7 += carry[6]; - s6 -= carry[6] << 21; - carry[7] = s7 >> 21; - s8 += carry[7]; - s7 -= carry[7] << 21; - carry[8] = s8 >> 21; - s9 += carry[8]; - s8 -= carry[8] << 21; - carry[9] = s9 >> 21; - s10 += carry[9]; - s9 -= carry[9] << 21; - carry[10] = s10 >> 21; - s11 += carry[10]; - s10 -= carry[10] << 21; - carry[11] = s11 >> 21; - s12 += carry[11]; - s11 -= carry[11] << 21; - - s0 += s12 * Numbers.v666643; - s1 += s12 * Numbers.v470296; - s2 += s12 * Numbers.v654183; - s3 -= s12 * Numbers.v997805; - s4 += s12 * Numbers.v136657; - s5 -= s12 * Numbers.v683901; - s12 = Number.zero; - - carry[0] = s0 >> 21; - s1 += carry[0]; - s0 -= carry[0] << 21; - carry[1] = s1 >> 21; - s2 += carry[1]; - s1 -= carry[1] << 21; - carry[2] = s2 >> 21; - s3 += carry[2]; - s2 -= carry[2] << 21; - carry[3] = s3 >> 21; - s4 += carry[3]; - s3 -= carry[3] << 21; - carry[4] = s4 >> 21; - s5 += carry[4]; - s4 -= carry[4] << 21; - carry[5] = s5 >> 21; - s6 += carry[5]; - s5 -= carry[5] << 21; - carry[6] = s6 >> 21; - s7 += carry[6]; - s6 -= carry[6] << 21; - carry[7] = s7 >> 21; - s8 += carry[7]; - s7 -= carry[7] << 21; - carry[8] = s8 >> 21; - s9 += carry[8]; - s8 -= carry[8] << 21; - carry[9] = s9 >> 21; - s10 += carry[9]; - s9 -= carry[9] << 21; - carry[10] = s10 >> 21; - s11 += carry[10]; - s10 -= carry[10] << 21; - - s[0] = (s0 >> 0).intValue; - s[1] = (s0 >> 8).intValue; - s[2] = ((s0 >> 16) | (s1 << 5)).intValue; - s[3] = (s1 >> 3).intValue; - s[4] = (s1 >> 11).intValue; - s[5] = ((s1 >> 19) | (s2 << 2)).intValue; - s[6] = (s2 >> 6).intValue; - s[7] = ((s2 >> 14) | (s3 << 7)).intValue; - s[8] = (s3 >> 1).intValue; - s[9] = (s3 >> 9).intValue; - s[10] = ((s3 >> 17) | (s4 << 4)).intValue; - s[11] = (s4 >> 4).intValue; - s[12] = (s4 >> 12).intValue; - s[13] = ((s4 >> 20) | (s5 << 1)).intValue; - s[14] = (s5 >> 7).intValue; - s[15] = ((s5 >> 15) | (s6 << 6)).intValue; - s[16] = (s6 >> 2).intValue; - s[17] = (s6 >> 10).intValue; - s[18] = ((s6 >> 18) | (s7 << 3)).intValue; - s[19] = (s7 >> 5).intValue; - s[20] = (s7 >> 13).intValue; - s[21] = (s8 >> 0).intValue; - s[22] = (s8 >> 8).intValue; - s[23] = ((s8 >> 16) | (s9 << 5)).intValue; - s[24] = (s9 >> 3).intValue; - s[25] = (s9 >> 11).intValue; - s[26] = ((s9 >> 19) | (s10 << 2)).intValue; - s[27] = (s10 >> 6).intValue; - s[28] = ((s10 >> 14) | (s11 << 7)).intValue; - s[29] = (s11 >> 1).intValue; - s[30] = (s11 >> 9).intValue; - s[31] = (s11 >> 17).intValue; -} - -/// Input: -/// s[0]+256*s[1]+...+256^63*s[63] = s -/// -/// Output: -/// s[0]+256*s[1]+...+256^31*s[31] = s mod l -/// where l = 2^252 + 27742317777372353535851937790883648493. -void ScReduce(Uint8List out, Uint8List s) { - var s0 = Numbers.v2097151 & load3(s.sublist(0, s.length)); - var s1 = Numbers.v2097151 & (load4(s.sublist(2, s.length)) >> 5); - var s2 = Numbers.v2097151 & (load3(s.sublist(5, s.length)) >> 2); - var s3 = Numbers.v2097151 & (load4(s.sublist(7, s.length)) >> 7); - var s4 = Numbers.v2097151 & (load4(s.sublist(10, s.length)) >> 4); - var s5 = Numbers.v2097151 & (load3(s.sublist(13, s.length)) >> 1); - var s6 = Numbers.v2097151 & (load4(s.sublist(15, s.length)) >> 6); - var s7 = Numbers.v2097151 & (load3(s.sublist(18, s.length)) >> 3); - var s8 = Numbers.v2097151 & load3(s.sublist(21, s.length)); - var s9 = Numbers.v2097151 & (load4(s.sublist(23, s.length)) >> 5); - var s10 = Numbers.v2097151 & (load3(s.sublist(26, s.length)) >> 2); - var s11 = Numbers.v2097151 & (load4(s.sublist(28, s.length)) >> 7); - var s12 = Numbers.v2097151 & (load4(s.sublist(31, s.length)) >> 4); - var s13 = Numbers.v2097151 & (load3(s.sublist(34, s.length)) >> 1); - var s14 = Numbers.v2097151 & (load4(s.sublist(36, s.length)) >> 6); - var s15 = Numbers.v2097151 & (load3(s.sublist(39, s.length)) >> 3); - var s16 = Numbers.v2097151 & load3(s.sublist(42, s.length)); - var s17 = Numbers.v2097151 & (load4(s.sublist(44, s.length)) >> 5); - var s18 = Numbers.v2097151 & (load3(s.sublist(47, s.length)) >> 2); - var s19 = Numbers.v2097151 & (load4(s.sublist(49, s.length)) >> 7); - var s20 = Numbers.v2097151 & (load4(s.sublist(52, s.length)) >> 4); - var s21 = Numbers.v2097151 & (load3(s.sublist(55, s.length)) >> 1); - var s22 = Numbers.v2097151 & (load4(s.sublist(57, s.length)) >> 6); - var s23 = (load4(s.sublist(60, s.length)) >> 3); - - s11 += s23 * Numbers.v666643; - s12 += s23 * Numbers.v470296; - s13 += s23 * Numbers.v654183; - s14 -= s23 * Numbers.v997805; - s15 += s23 * Numbers.v136657; - s16 -= s23 * Numbers.v683901; - s23 = Number.zero; - - s10 += s22 * Numbers.v666643; - s11 += s22 * Numbers.v470296; - s12 += s22 * Numbers.v654183; - s13 -= s22 * Numbers.v997805; - s14 += s22 * Numbers.v136657; - s15 -= s22 * Numbers.v683901; - s22 = Number.zero; - - s9 += s21 * Numbers.v666643; - s10 += s21 * Numbers.v470296; - s11 += s21 * Numbers.v654183; - s12 -= s21 * Numbers.v997805; - s13 += s21 * Numbers.v136657; - s14 -= s21 * Numbers.v683901; - s21 = Number.zero; - - s8 += s20 * Numbers.v666643; - s9 += s20 * Numbers.v470296; - s10 += s20 * Numbers.v654183; - s11 -= s20 * Numbers.v997805; - s12 += s20 * Numbers.v136657; - s13 -= s20 * Numbers.v683901; - s20 = Number.zero; - - s7 += s19 * Numbers.v666643; - s8 += s19 * Numbers.v470296; - s9 += s19 * Numbers.v654183; - s10 -= s19 * Numbers.v997805; - s11 += s19 * Numbers.v136657; - s12 -= s19 * Numbers.v683901; - s19 = Number.zero; - - s6 += s18 * Numbers.v666643; - s7 += s18 * Numbers.v470296; - s8 += s18 * Numbers.v654183; - s9 -= s18 * Numbers.v997805; - s10 += s18 * Numbers.v136657; - s11 -= s18 * Numbers.v683901; - s18 = Number.zero; - - var carry = List.filled(64, Number.zero); - - carry[6] = (s6 + (Number.one << 20)) >> 21; - s7 += carry[6]; - s6 -= carry[6] << 21; - carry[8] = (s8 + (Number.one << 20)) >> 21; - s9 += carry[8]; - s8 -= carry[8] << 21; - carry[10] = (s10 + (Number.one << 20)) >> 21; - s11 += carry[10]; - s10 -= carry[10] << 21; - carry[12] = (s12 + (Number.one << 20)) >> 21; - s13 += carry[12]; - s12 -= carry[12] << 21; - carry[14] = (s14 + (Number.one << 20)) >> 21; - s15 += carry[14]; - s14 -= carry[14] << 21; - carry[16] = (s16 + (Number.one << 20)) >> 21; - s17 += carry[16]; - s16 -= carry[16] << 21; - - carry[7] = (s7 + (Number.one << 20)) >> 21; - s8 += carry[7]; - s7 -= carry[7] << 21; - carry[9] = (s9 + (Number.one << 20)) >> 21; - s10 += carry[9]; - s9 -= carry[9] << 21; - carry[11] = (s11 + (Number.one << 20)) >> 21; - s12 += carry[11]; - s11 -= carry[11] << 21; - carry[13] = (s13 + (Number.one << 20)) >> 21; - s14 += carry[13]; - s13 -= carry[13] << 21; - carry[15] = (s15 + (Number.one << 20)) >> 21; - s16 += carry[15]; - s15 -= carry[15] << 21; - - s5 += s17 * Numbers.v666643; - s6 += s17 * Numbers.v470296; - s7 += s17 * Numbers.v654183; - s8 -= s17 * Numbers.v997805; - s9 += s17 * Numbers.v136657; - s10 -= s17 * Numbers.v683901; - s17 = Number.zero; - - s4 += s16 * Numbers.v666643; - s5 += s16 * Numbers.v470296; - s6 += s16 * Numbers.v654183; - s7 -= s16 * Numbers.v997805; - s8 += s16 * Numbers.v136657; - s9 -= s16 * Numbers.v683901; - s16 = Number.zero; - - s3 += s15 * Numbers.v666643; - s4 += s15 * Numbers.v470296; - s5 += s15 * Numbers.v654183; - s6 -= s15 * Numbers.v997805; - s7 += s15 * Numbers.v136657; - s8 -= s15 * Numbers.v683901; - s15 = Number.zero; - - s2 += s14 * Numbers.v666643; - s3 += s14 * Numbers.v470296; - s4 += s14 * Numbers.v654183; - s5 -= s14 * Numbers.v997805; - s6 += s14 * Numbers.v136657; - s7 -= s14 * Numbers.v683901; - s14 = Number.zero; - - s1 += s13 * Numbers.v666643; - s2 += s13 * Numbers.v470296; - s3 += s13 * Numbers.v654183; - s4 -= s13 * Numbers.v997805; - s5 += s13 * Numbers.v136657; - s6 -= s13 * Numbers.v683901; - s13 = Number.zero; - - s0 += s12 * Numbers.v666643; - s1 += s12 * Numbers.v470296; - s2 += s12 * Numbers.v654183; - s3 -= s12 * Numbers.v997805; - s4 += s12 * Numbers.v136657; - s5 -= s12 * Numbers.v683901; - s12 = Number.zero; - - carry[0] = (s0 + (Number.one << 20)) >> 21; - s1 += carry[0]; - s0 -= carry[0] << 21; - carry[2] = (s2 + (Number.one << 20)) >> 21; - s3 += carry[2]; - s2 -= carry[2] << 21; - carry[4] = (s4 + (Number.one << 20)) >> 21; - s5 += carry[4]; - s4 -= carry[4] << 21; - carry[6] = (s6 + (Number.one << 20)) >> 21; - s7 += carry[6]; - s6 -= carry[6] << 21; - carry[8] = (s8 + (Number.one << 20)) >> 21; - s9 += carry[8]; - s8 -= carry[8] << 21; - carry[10] = (s10 + (Number.one << 20)) >> 21; - s11 += carry[10]; - s10 -= carry[10] << 21; - - carry[1] = (s1 + (Number.one << 20)) >> 21; - s2 += carry[1]; - s1 -= carry[1] << 21; - carry[3] = (s3 + (Number.one << 20)) >> 21; - s4 += carry[3]; - s3 -= carry[3] << 21; - carry[5] = (s5 + (Number.one << 20)) >> 21; - s6 += carry[5]; - s5 -= carry[5] << 21; - carry[7] = (s7 + (Number.one << 20)) >> 21; - s8 += carry[7]; - s7 -= carry[7] << 21; - carry[9] = (s9 + (Number.one << 20)) >> 21; - s10 += carry[9]; - s9 -= carry[9] << 21; - carry[11] = (s11 + (Number.one << 20)) >> 21; - s12 += carry[11]; - s11 -= carry[11] << 21; - - s0 += s12 * Numbers.v666643; - s1 += s12 * Numbers.v470296; - s2 += s12 * Numbers.v654183; - s3 -= s12 * Numbers.v997805; - s4 += s12 * Numbers.v136657; - s5 -= s12 * Numbers.v683901; - s12 = Number.zero; - - carry[0] = s0 >> 21; - s1 += carry[0]; - s0 -= carry[0] << 21; - carry[1] = s1 >> 21; - s2 += carry[1]; - s1 -= carry[1] << 21; - carry[2] = s2 >> 21; - s3 += carry[2]; - s2 -= carry[2] << 21; - carry[3] = s3 >> 21; - s4 += carry[3]; - s3 -= carry[3] << 21; - carry[4] = s4 >> 21; - s5 += carry[4]; - s4 -= carry[4] << 21; - carry[5] = s5 >> 21; - s6 += carry[5]; - s5 -= carry[5] << 21; - carry[6] = s6 >> 21; - s7 += carry[6]; - s6 -= carry[6] << 21; - carry[7] = s7 >> 21; - s8 += carry[7]; - s7 -= carry[7] << 21; - carry[8] = s8 >> 21; - s9 += carry[8]; - s8 -= carry[8] << 21; - carry[9] = s9 >> 21; - s10 += carry[9]; - s9 -= carry[9] << 21; - carry[10] = s10 >> 21; - s11 += carry[10]; - s10 -= carry[10] << 21; - carry[11] = s11 >> 21; - s12 += carry[11]; - s11 -= carry[11] << 21; - - s0 += s12 * Numbers.v666643; - s1 += s12 * Numbers.v470296; - s2 += s12 * Numbers.v654183; - s3 -= s12 * Numbers.v997805; - s4 += s12 * Numbers.v136657; - s5 -= s12 * Numbers.v683901; - s12 = Number.zero; - - carry[0] = s0 >> 21; - s1 += carry[0]; - s0 -= carry[0] << 21; - carry[1] = s1 >> 21; - s2 += carry[1]; - s1 -= carry[1] << 21; - carry[2] = s2 >> 21; - s3 += carry[2]; - s2 -= carry[2] << 21; - carry[3] = s3 >> 21; - s4 += carry[3]; - s3 -= carry[3] << 21; - carry[4] = s4 >> 21; - s5 += carry[4]; - s4 -= carry[4] << 21; - carry[5] = s5 >> 21; - s6 += carry[5]; - s5 -= carry[5] << 21; - carry[6] = s6 >> 21; - s7 += carry[6]; - s6 -= carry[6] << 21; - carry[7] = s7 >> 21; - s8 += carry[7]; - s7 -= carry[7] << 21; - carry[8] = s8 >> 21; - s9 += carry[8]; - s8 -= carry[8] << 21; - carry[9] = s9 >> 21; - s10 += carry[9]; - s9 -= carry[9] << 21; - carry[10] = s10 >> 21; - s11 += carry[10]; - s10 -= carry[10] << 21; - - out[0] = (s0 >> 0).intValue; - out[1] = (s0 >> 8).intValue; - out[2] = ((s0 >> 16) | (s1 << 5)).intValue; - out[3] = (s1 >> 3).intValue; - out[4] = (s1 >> 11).intValue; - out[5] = ((s1 >> 19) | (s2 << 2)).intValue; - out[6] = (s2 >> 6).intValue; - out[7] = ((s2 >> 14) | (s3 << 7)).intValue; - out[8] = (s3 >> 1).intValue; - out[9] = (s3 >> 9).intValue; - out[10] = ((s3 >> 17) | (s4 << 4)).intValue; - out[11] = (s4 >> 4).intValue; - out[12] = (s4 >> 12).intValue; - out[13] = ((s4 >> 20) | (s5 << 1)).intValue; - out[14] = (s5 >> 7).intValue; - out[15] = ((s5 >> 15) | (s6 << 6)).intValue; - out[16] = (s6 >> 2).intValue; - out[17] = (s6 >> 10).intValue; - out[18] = ((s6 >> 18) | (s7 << 3)).intValue; - out[19] = (s7 >> 5).intValue; - out[20] = (s7 >> 13).intValue; - out[21] = (s8 >> 0).intValue; - out[22] = (s8 >> 8).intValue; - out[23] = ((s8 >> 16) | (s9 << 5)).intValue; - out[24] = (s9 >> 3).intValue; - out[25] = (s9 >> 11).intValue; - out[26] = ((s9 >> 19) | (s10 << 2)).intValue; - out[27] = (s10 >> 6).intValue; - out[28] = ((s10 >> 14) | (s11 << 7)).intValue; - out[29] = (s11 >> 1).intValue; - out[30] = (s11 >> 9).intValue; - out[31] = (s11 >> 17).intValue; -} - -/// order is the order of Curve25519 in little-endian form. -var order = List.from( - [ - BigInt.parse('0x5812631a5cf5d3ed'), - BigInt.parse('0x14def9dea2f79cd6'), - BigInt.zero, - BigInt.parse('0x1000000000000000') - ], -); - -/// ScMinimal returns true if the given scalar is less than the order of the -/// curve. -bool ScMinimal(Uint8List scalar) { - for (var i = 3;; i--) { - // var v = binary.LittleEndian.Uint64(scalar[i*8:]); - var v = Uint64(scalar.sublist(i * 8, scalar.length)); - if (v > order[i].toInt()) { - return false; - } else if (v < order[i].toInt()) { - break; - } else if (i == 0) { - return false; - } - } - - return true; -} - -int Uint64(Uint8List b) { - return b[0] | - b[1] << 8 | - b[2] << 16 | - b[3] << 24 | - b[4] << 32 | - b[5] << 40 | - b[6] << 48 | - b[7] << 56; -} diff --git a/ed25519_edwards/lib/src/numbers.dart b/ed25519_edwards/lib/src/numbers.dart deleted file mode 100644 index ba603f9..0000000 --- a/ed25519_edwards/lib/src/numbers.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'package:adaptive_number/adaptive_number.dart'; - -abstract class Numbers { - static Number v8 = Number(8); - static Number v15 = Number(15); - static Number v19 = Number(19); - static Number v24 = Number(24); - static Number v25 = Number(25); - static Number v26 = Number(26); - static Number v38 = Number(38); - static Number v136657 = Number(136657); - static Number v2097151 = Number(2097151); - static Number v470296 = Number(470296); - static Number v683901 = Number(683901); - static Number v654183 = Number(654183); - static Number v666643 = Number(666643); - static Number v997805 = Number(997805); -} diff --git a/ed25519_edwards/lib/src/util.dart b/ed25519_edwards/lib/src/util.dart deleted file mode 100644 index 301b952..0000000 --- a/ed25519_edwards/lib/src/util.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'dart:math'; - -import 'dart:typed_data'; - -void arrayCopy(List src, int srcPos, List dest, int destPos, int length) { - dest.setRange(destPos, length + destPos, src, srcPos); -} - -final _defaultSecureRandom = Random.secure(); - -void fillBytesWithSecureRandomNumbers(Uint8List bytes, {Random? random}) { - random ??= _defaultSecureRandom; - for (var i = 0; i < bytes.length; i++) { - bytes[i] = random.nextInt(256); - } -} diff --git a/ed25519_edwards/pubspec.yaml b/ed25519_edwards/pubspec.yaml deleted file mode 100644 index 90d2cea..0000000 --- a/ed25519_edwards/pubspec.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: ed25519_edwards -description: Dart port of ed25519 from Go Cryptography ed25519 -version: 0.3.1 -homepage: https://github.com/Tougee/ed25519 - -environment: - sdk: '>=2.12.0 <3.0.0' - -dependencies: - collection: ^1.15.0 - crypto: ^3.0.0 - convert: ^3.0.0 - adaptive_number: ^1.0.0 -dev_dependencies: - pedantic: ^1.10.0 - test: ^1.16.4 - hex: ^0.2.0 - benchmark_harness: ^2.0.0 diff --git a/libsignal_protocol_dart/LICENSE b/libsignal_protocol_dart/LICENSE deleted file mode 100644 index f288702..0000000 --- a/libsignal_protocol_dart/LICENSE +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/libsignal_protocol_dart/lib/libsignal_protocol_dart.dart b/libsignal_protocol_dart/lib/libsignal_protocol_dart.dart deleted file mode 100644 index c720691..0000000 --- a/libsignal_protocol_dart/lib/libsignal_protocol_dart.dart +++ /dev/null @@ -1,52 +0,0 @@ -export 'src/decryption_callback.dart'; -export 'src/duplicate_message_exception.dart'; -export 'src/ecc/curve.dart'; -export 'src/ecc/djb_ec_private_key.dart'; -export 'src/ecc/djb_ec_public_key.dart'; -export 'src/ecc/ec_key_pair.dart'; -export 'src/ecc/ec_private_key.dart'; -export 'src/ecc/ec_public_key.dart'; -export 'src/fingerprint/displayable_fingerprint.dart'; -export 'src/fingerprint/fingerprint.dart'; -export 'src/fingerprint/numeric_fingerprint_generator.dart'; -export 'src/fingerprint/scannable_fingerprint.dart'; -export 'src/groups/group_cipher.dart'; -export 'src/groups/group_session_builder.dart'; -export 'src/groups/sender_key_name.dart'; -export 'src/groups/state/in_memory_sender_key_store.dart'; -export 'src/groups/state/sender_key_record.dart'; -export 'src/groups/state/sender_key_store.dart'; -export 'src/identity_key.dart'; -export 'src/identity_key_pair.dart'; -export 'src/invalid_key_exception.dart'; -export 'src/invalid_key_id_exception.dart'; -export 'src/legacy_message_exception.dart'; -export 'src/no_session_exception.dart'; -export 'src/protocol/ciphertext_message.dart'; -export 'src/protocol/pre_key_signal_message.dart'; -export 'src/protocol/sender_key_distribution_message_wrapper.dart'; -export 'src/protocol/sender_key_message.dart'; -export 'src/protocol/signal_message.dart'; -export 'src/provisioning_cipher.dart'; -export 'src/session_builder.dart'; -export 'src/session_cipher.dart'; -export 'src/signal_protocol_address.dart'; -export 'src/state/identity_key_store.dart'; -export 'src/state/impl/in_memory_identity_key_store.dart'; -export 'src/state/impl/in_memory_pre_key_store.dart'; -export 'src/state/impl/in_memory_session_store.dart'; -export 'src/state/impl/in_memory_signal_protocol_store.dart'; -export 'src/state/impl/in_memory_signed_pre_key_store.dart'; -export 'src/state/pre_key_bundle.dart'; -export 'src/state/pre_key_record.dart'; -export 'src/state/pre_key_store.dart'; -export 'src/state/session_record.dart'; -export 'src/state/session_state.dart'; -export 'src/state/session_store.dart'; -export 'src/state/signal_protocol_store.dart'; -export 'src/state/signed_pre_key_record.dart'; -export 'src/state/signed_pre_key_store.dart'; -export 'src/untrusted_identity_exception.dart'; -export 'src/util/byte_util.dart'; -export 'src/util/key_helper.dart'; -export 'src/util/medium.dart'; diff --git a/libsignal_protocol_dart/lib/src/cbc.dart b/libsignal_protocol_dart/lib/src/cbc.dart deleted file mode 100644 index c77e4b2..0000000 --- a/libsignal_protocol_dart/lib/src/cbc.dart +++ /dev/null @@ -1,40 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/export.dart'; - -Uint8List aesCbcEncrypt(Uint8List key, Uint8List iv, Uint8List plaintext) { - final paddedPlaintext = pad(plaintext, 16); - final cbc = CBCBlockCipher(AESEngine()) - ..init(true, ParametersWithIV(KeyParameter(key), iv)); // true=encrypt - - final cipherText = Uint8List(paddedPlaintext.length); // allocate space - var offset = 0; - while (offset < paddedPlaintext.length) { - offset += cbc.processBlock(paddedPlaintext, offset, cipherText, offset); - } - assert(offset == paddedPlaintext.length); - return cipherText; -} - -Uint8List aesCbcDecrypt(Uint8List key, Uint8List iv, Uint8List cipherText) { - final cbc = CBCBlockCipher(AESEngine()) - ..init(false, ParametersWithIV(KeyParameter(key), iv)); // false=decrypt - - final paddedPlainText = Uint8List(cipherText.length); // allocate space - var offset = 0; - while (offset < cipherText.length) { - offset += cbc.processBlock(cipherText, offset, paddedPlainText, offset); - } - assert(offset == cipherText.length); - return unpad(paddedPlainText); -} - -Uint8List pad(Uint8List bytes, int blockSize) { - final padLength = blockSize - (bytes.length % blockSize); - final padded = Uint8List(bytes.length + padLength)..setAll(0, bytes); - PKCS7Padding().addPadding(padded, bytes.length); - return padded; -} - -Uint8List unpad(Uint8List padded) => - padded.sublist(0, padded.length - PKCS7Padding().padCount(padded)); diff --git a/libsignal_protocol_dart/lib/src/decryption_callback.dart b/libsignal_protocol_dart/lib/src/decryption_callback.dart deleted file mode 100644 index d56013f..0000000 --- a/libsignal_protocol_dart/lib/src/decryption_callback.dart +++ /dev/null @@ -1,3 +0,0 @@ -import 'dart:typed_data'; - -typedef DecryptionCallback = void Function(Uint8List plaintext); diff --git a/libsignal_protocol_dart/lib/src/devices/device_consistency_code_generator.dart b/libsignal_protocol_dart/lib/src/devices/device_consistency_code_generator.dart deleted file mode 100644 index 29a6699..0000000 --- a/libsignal_protocol_dart/lib/src/devices/device_consistency_code_generator.dart +++ /dev/null @@ -1,41 +0,0 @@ -import 'dart:typed_data'; - -import 'package:convert/convert.dart'; -import 'package:crypto/crypto.dart'; -import '../util/byte_util.dart'; - -import 'device_consistency_commitment.dart'; -import 'device_consistency_signature.dart'; - -class DeviceConsistencyCodeGenerator { - static const int codeVersion = 0; - - static String generateFor(DeviceConsistencyCommitment commitment, - List signatures) { - final sortedSignatures = [...signatures] - ..sort(compareSignature); - - final output = AccumulatorSink(); - final input = sha512.startChunkedConversion(output) - ..add(ByteUtil.shortToByteArray(codeVersion)) - ..add(commitment.serialized); - - for (final signature in sortedSignatures) { - input.add(signature.vrfOutput); - } - input.close(); - final hash = output.events.single.bytes; - final digits = getEncodedChunk(Uint8List.fromList(hash), 0) + - getEncodedChunk(Uint8List.fromList(hash), 5); - return digits.substring(0, 6); - } - - static String getEncodedChunk(Uint8List hash, int offset) { - final chunk = ByteUtil.byteArray5ToLong(hash, offset).remainder(100000); - return chunk.toString().padLeft(5, '0'); - } -} - -int compareSignature( - DeviceConsistencySignature a, DeviceConsistencySignature b) => - ByteUtil.compare(a.vrfOutput, b.vrfOutput); diff --git a/libsignal_protocol_dart/lib/src/devices/device_consistency_commitment.dart b/libsignal_protocol_dart/lib/src/devices/device_consistency_commitment.dart deleted file mode 100644 index 1e0dc92..0000000 --- a/libsignal_protocol_dart/lib/src/devices/device_consistency_commitment.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:convert/convert.dart'; -import 'package:crypto/crypto.dart'; - -import '../identity_key.dart'; -import '../util/byte_util.dart'; - -class DeviceConsistencyCommitment { - DeviceConsistencyCommitment(int generation, List identityKeys) { - final sortedIdentityKeys = [...identityKeys]..sort((a, b) => - ByteUtil.compare(a.publicKey.serialize(), b.publicKey.serialize())); - - final output = AccumulatorSink(); - final input = sha512.startChunkedConversion(output) - ..add(utf8.encode(version)) - ..add(ByteUtil.intToByteArray(generation)); - - for (final commitment in sortedIdentityKeys) { - input.add(commitment.publicKey.serialize()); - } - input.close(); - - _generation = generation; - _serialized = Uint8List.fromList(output.events.single.bytes); - } - - static const String version = 'DeviceConsistencyCommitment_V0'; - - late int _generation; - late Uint8List _serialized; - - Uint8List get serialized => _serialized; - - int get generation => _generation; -} diff --git a/libsignal_protocol_dart/lib/src/devices/device_consistency_signature.dart b/libsignal_protocol_dart/lib/src/devices/device_consistency_signature.dart deleted file mode 100644 index 965e4f2..0000000 --- a/libsignal_protocol_dart/lib/src/devices/device_consistency_signature.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'dart:typed_data'; - -class DeviceConsistencySignature { - DeviceConsistencySignature(this._signature, this._vrfOutput); - - final Uint8List _signature; - final Uint8List _vrfOutput; - - Uint8List get vrfOutput => _vrfOutput; - - Uint8List get signature => _signature; -} diff --git a/libsignal_protocol_dart/lib/src/duplicate_message_exception.dart b/libsignal_protocol_dart/lib/src/duplicate_message_exception.dart deleted file mode 100644 index 662e7a6..0000000 --- a/libsignal_protocol_dart/lib/src/duplicate_message_exception.dart +++ /dev/null @@ -1,7 +0,0 @@ -class DuplicateMessageException implements Exception { - DuplicateMessageException(this.detailMessage); - final String detailMessage; - - @override - String toString() => 'DuplicateMessageException - $detailMessage'; -} diff --git a/libsignal_protocol_dart/lib/src/ecc/curve.dart b/libsignal_protocol_dart/lib/src/ecc/curve.dart deleted file mode 100644 index 4deda5e..0000000 --- a/libsignal_protocol_dart/lib/src/ecc/curve.dart +++ /dev/null @@ -1,187 +0,0 @@ -import 'dart:typed_data'; - -import 'package:x25519/x25519.dart' as x25519; - -import '../invalid_key_exception.dart'; -import '../util/key_helper.dart'; -import 'djb_ec_private_key.dart'; -import 'djb_ec_public_key.dart'; -import 'ec_key_pair.dart'; -import 'ec_private_key.dart'; -import 'ec_public_key.dart'; -import 'ed25519.dart'; - -typedef KeyPairGenerator = GeneratedKeyPair Function(); -typedef AgreementCalculator = Uint8List Function(Uint8List, Uint8List); - -class GeneratedKeyPair { - GeneratedKeyPair(this.private, this.public); - - final Uint8List private; - final Uint8List public; -} - -class Curve { - static const int djbType = 0x05; - - static KeyPairGenerator? keyPairGenerator; - static AgreementCalculator? agreementCalculator; - - static ECKeyPair generateKeyPair() { - final x25519.KeyPair keyPair; - final generator = keyPairGenerator; - if (generator != null) { - final kp = generator(); - keyPair = x25519.KeyPair(privateKey: kp.private, publicKey: kp.public); - } else { - keyPair = x25519.generateKeyPair(); - } - - return ECKeyPair(DjbECPublicKey(Uint8List.fromList(keyPair.publicKey)), - DjbECPrivateKey(Uint8List.fromList(keyPair.privateKey))); - } - - static ECKeyPair generateKeyPairFromPrivate(List private) { - if (private.length != 32) { - throw InvalidKeyException( - 'Invalid private key length: ${private.length}'); - } - final public = List.filled(32, 0); - - private[0] &= 248; - private[31] &= 127; - private[31] |= 64; - - x25519.ScalarBaseMult(public, private); - - return ECKeyPair(DjbECPublicKey(Uint8List.fromList(public)), - DjbECPrivateKey(Uint8List.fromList(private))); - } - - static ECPublicKey decodePointList(List bytes, int offset) => - decodePoint(Uint8List.fromList(bytes), offset); - - static ECPublicKey decodePoint(Uint8List bytes, int offset) { - if (bytes.length - offset < 1) { - throw InvalidKeyException('No key type identifier'); - } - - final type = bytes[offset] & 0xFF; - - switch (type) { - case Curve.djbType: - if (bytes.length - offset < 33) { - throw InvalidKeyException('Bad key length: ${bytes.length}'); - } - - final keyBytes = Uint8List(32); - arraycopy(bytes, offset + 1, keyBytes, 0, keyBytes.length); - return DjbECPublicKey(keyBytes); - default: - throw InvalidKeyException('Bad key type: $type'); - } - } - - static void arraycopy( - List src, int srcPos, List dest, int destPos, int length) { - dest.setRange(destPos, length + destPos, src, srcPos); - } - - static ECPrivateKey decodePrivatePoint(Uint8List bytes) => - DjbECPrivateKey(bytes); - - static Uint8List calculateAgreement( - ECPublicKey? publicKey, ECPrivateKey? privateKey) { - if (publicKey == null) { - throw Exception('publicKey value is null'); - } - - if (privateKey == null) { - throw Exception('privateKey value is null'); - } - if (publicKey.getType() != privateKey.getType()) { - throw Exception('Public and private keys must be of the same type!'); - } - - if (publicKey.getType() == djbType) { - final calculator = agreementCalculator; - if (calculator != null) { - return calculator( - (privateKey as DjbECPrivateKey).privateKey, - (publicKey as DjbECPublicKey).publicKey, - ); - } - - final secretKey = x25519.X25519( - List.from((privateKey as DjbECPrivateKey).privateKey), - List.from((publicKey as DjbECPublicKey).publicKey), - ); - return secretKey; - } else { - throw Exception('Unknown type: ${publicKey.getType()}'); - } - } - - static bool verifySignature( - ECPublicKey? signingKey, Uint8List? message, Uint8List? signature) { - if (signingKey == null || message == null || signature == null) { - throw InvalidKeyException('Values must not be null'); - } - - if (signingKey.getType() == djbType) { - if (signature.length != 64) { - return false; - } - - final publicKey = (signingKey as DjbECPublicKey).publicKey; - return verifySig(publicKey, message, signature); - } else { - throw InvalidKeyException( - 'Unknown Signing Key type${signingKey.getType()}'); - } - } - - static Uint8List calculateSignature( - ECPrivateKey? signingKey, Uint8List? message) { - if (signingKey == null || message == null) { - throw Exception('Values must not be null'); - } - - if (signingKey.getType() == djbType) { - final privateKey = signingKey.serialize(); - final random = generateRandomBytes(); - - return sign(privateKey, message, random); - } else { - throw Exception('Unknown Signing Key type${signingKey.getType()}'); - } - } - - static Uint8List calculateVrfSignature( - ECPrivateKey? signingKey, Uint8List? message) { - if (signingKey == null || message == null) { - throw Exception('Values must not be null'); - } - - if (signingKey.getType() == djbType) { - // TODO - } else { - throw Exception('Unknown Signing Key type${signingKey.getType()}'); - } - return Uint8List(0); - } - - static Uint8List verifyVrfSignature( - ECPublicKey? signingKey, Uint8List? message, Uint8List? signature) { - if (signingKey == null || message == null || signature == null) { - throw Exception('Values must not be null'); - } - - if (signingKey.getType() == djbType) { - // TODO - } else { - throw Exception('Unknown Signing Key type${signingKey.getType()}'); - } - return Uint8List(0); - } -} diff --git a/libsignal_protocol_dart/lib/src/ecc/djb_ec_private_key.dart b/libsignal_protocol_dart/lib/src/ecc/djb_ec_private_key.dart deleted file mode 100644 index c5ae4f9..0000000 --- a/libsignal_protocol_dart/lib/src/ecc/djb_ec_private_key.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'dart:typed_data'; - -import 'curve.dart'; -import 'ec_private_key.dart'; - -class DjbECPrivateKey extends ECPrivateKey { - DjbECPrivateKey(this._privateKey); - - final Uint8List _privateKey; - - @override - int getType() => Curve.djbType; - - @override - Uint8List serialize() => privateKey; - - Uint8List get privateKey => _privateKey; -} diff --git a/libsignal_protocol_dart/lib/src/ecc/djb_ec_public_key.dart b/libsignal_protocol_dart/lib/src/ecc/djb_ec_public_key.dart deleted file mode 100644 index e86e3bd..0000000 --- a/libsignal_protocol_dart/lib/src/ecc/djb_ec_public_key.dart +++ /dev/null @@ -1,44 +0,0 @@ -import 'dart:typed_data'; - -import 'package:meta/meta.dart'; - -import '../eq.dart'; - -import 'curve.dart'; -import 'ec_public_key.dart'; - -@immutable -class DjbECPublicKey extends ECPublicKey { - DjbECPublicKey(this._publicKey); - - final Uint8List _publicKey; - - @override - int getType() => Curve.djbType; - - @override - Uint8List serialize() => Uint8List.fromList([Curve.djbType] + _publicKey); - - Uint8List get publicKey => _publicKey; - - @override - int compareTo(ECPublicKey another) => decodeBigInt(publicKey) - .compareTo(decodeBigInt((another as DjbECPublicKey).publicKey)); - - @override - bool operator ==(Object other) { - if (other is! DjbECPublicKey) return false; - return eq(_publicKey, other._publicKey); - } - - @override - int get hashCode => _publicKey.hashCode; - - BigInt decodeBigInt(List bytes) { - var result = BigInt.from(0); - for (var i = 0; i < bytes.length; i++) { - result += BigInt.from(bytes[bytes.length - i - 1]) << (8 * i); - } - return result; - } -} diff --git a/libsignal_protocol_dart/lib/src/ecc/ec_key_pair.dart b/libsignal_protocol_dart/lib/src/ecc/ec_key_pair.dart deleted file mode 100644 index 56b1a71..0000000 --- a/libsignal_protocol_dart/lib/src/ecc/ec_key_pair.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'ec_private_key.dart'; -import 'ec_public_key.dart'; - -class ECKeyPair { - ECKeyPair(this._publicKey, this._privateKey); - - final ECPublicKey _publicKey; - final ECPrivateKey _privateKey; - - ECPublicKey get publicKey => _publicKey; - - ECPrivateKey get privateKey => _privateKey; -} diff --git a/libsignal_protocol_dart/lib/src/ecc/ec_private_key.dart b/libsignal_protocol_dart/lib/src/ecc/ec_private_key.dart deleted file mode 100644 index 4fe18c5..0000000 --- a/libsignal_protocol_dart/lib/src/ecc/ec_private_key.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'dart:typed_data'; - -abstract class ECPrivateKey { - Uint8List serialize(); - int getType(); -} diff --git a/libsignal_protocol_dart/lib/src/ecc/ec_public_key.dart b/libsignal_protocol_dart/lib/src/ecc/ec_public_key.dart deleted file mode 100644 index 21e5886..0000000 --- a/libsignal_protocol_dart/lib/src/ecc/ec_public_key.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'dart:typed_data'; - -abstract class ECPublicKey implements Comparable { - static const int keySize = 33; - - Uint8List serialize(); - int getType(); -} diff --git a/libsignal_protocol_dart/lib/src/ecc/ed25519.dart b/libsignal_protocol_dart/lib/src/ecc/ed25519.dart deleted file mode 100644 index 3bb28e8..0000000 --- a/libsignal_protocol_dart/lib/src/ecc/ed25519.dart +++ /dev/null @@ -1,117 +0,0 @@ -import 'dart:typed_data'; - -import 'package:convert/convert.dart'; -import 'package:crypto/crypto.dart' as cr; -import 'package:ed25519_edwards/ed25519_edwards.dart'; -// ignore: implementation_imports -import 'package:ed25519_edwards/src/edwards25519.dart'; - -import 'curve.dart'; - -Uint8List sign(Uint8List privateKey, Uint8List message, Uint8List random) { - final A = ExtendedGroupElement(); - final publicKey = Uint8List(32); - GeScalarMultBase(A, privateKey); - A.ToBytes(publicKey); - - // Calculate r - final diversifier = Uint8List.fromList([ - 0xFE, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0xFF - ]); - - var output = AccumulatorSink(); - cr.sha512.startChunkedConversion(output) - ..add(diversifier) - ..add(privateKey) - ..add(message) - ..add(random) - ..close(); - final r = output.events.single.bytes; - - final rReduced = Uint8List(32); - ScReduce(rReduced, Uint8List.fromList(r)); - final R = ExtendedGroupElement(); - GeScalarMultBase(R, rReduced); - - final encodedR = Uint8List(32); - R.ToBytes(encodedR); - - output = AccumulatorSink(); - cr.sha512.startChunkedConversion(output) - ..add(encodedR) - ..add(publicKey) - ..add(message) - ..close(); - final hramDigest = output.events.single.bytes; - - final hramDigestReduced = Uint8List(32); - ScReduce(hramDigestReduced, Uint8List.fromList(hramDigest)); - - final s = Uint8List(32); - ScMulAdd(s, hramDigestReduced, privateKey, rReduced); - - final signature = Uint8List(64); - Curve.arraycopy(encodedR, 0, signature, 0, 32); - Curve.arraycopy(s, 0, signature, 32, 32); - signature[63] |= publicKey[31] & 0x80; - - return signature; -} - -// verify checks whether the message has a valid signature. -bool verifySig(Uint8List publicKey, Uint8List message, Uint8List signature) { - publicKey[31] &= 0x7F; - - final edY = FieldElement(); - final one = FieldElement(); - final montX = FieldElement(); - final montXMinusOne = FieldElement(); - final montXPlusOne = FieldElement(); - FeFromBytes(montX, publicKey); - FeOne(one); - FeSub(montXMinusOne, montX, one); - FeAdd(montXPlusOne, montX, one); - FeInvert(montXPlusOne, montXPlusOne); - FeMul(edY, montXMinusOne, montXPlusOne); - - // ignore: non_constant_identifier_names - final A_ed = Uint8List(32); - FeToBytes(A_ed, edY); - - A_ed[31] |= signature[63] & 0x80; - signature[63] &= 0x7F; - -// bool verify(PublicKey publicKey, Uint8List message, Uint8List sig) { - return verify(PublicKey(A_ed.toList()), message, signature); -} diff --git a/libsignal_protocol_dart/lib/src/entry.dart b/libsignal_protocol_dart/lib/src/entry.dart deleted file mode 100644 index 5085002..0000000 --- a/libsignal_protocol_dart/lib/src/entry.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'dart:collection'; - -base class Entry extends LinkedListEntry> { - Entry(this.value); - T value; -} diff --git a/libsignal_protocol_dart/lib/src/eq.dart b/libsignal_protocol_dart/lib/src/eq.dart deleted file mode 100644 index 4c2dde6..0000000 --- a/libsignal_protocol_dart/lib/src/eq.dart +++ /dev/null @@ -1,4 +0,0 @@ -import 'package:collection/collection.dart'; - -bool eq(List? list1, List? list2) => - ListEquality().equals(list1, list2); diff --git a/libsignal_protocol_dart/lib/src/fingerprint/displayable_fingerprint.dart b/libsignal_protocol_dart/lib/src/fingerprint/displayable_fingerprint.dart deleted file mode 100644 index d92f44c..0000000 --- a/libsignal_protocol_dart/lib/src/fingerprint/displayable_fingerprint.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'dart:typed_data'; - -import '../util/byte_util.dart'; - -class DisplayableFingerprint { - DisplayableFingerprint( - Uint8List localFingerprint, Uint8List remoteFingerprint) { - localFingerprintNumbers = _getDisplayStringFor(localFingerprint); - remoteFingerprintNumbers = _getDisplayStringFor(remoteFingerprint); - } - - late String localFingerprintNumbers; - late String remoteFingerprintNumbers; - - String getDisplayText() { - if (localFingerprintNumbers.compareTo(remoteFingerprintNumbers) <= 0) { - return localFingerprintNumbers + remoteFingerprintNumbers; - } else { - return remoteFingerprintNumbers + localFingerprintNumbers; - } - } - - String _getDisplayStringFor(Uint8List fingerprint) => - _getEncodedChunk(fingerprint, 0) + - _getEncodedChunk(fingerprint, 5) + - _getEncodedChunk(fingerprint, 10) + - _getEncodedChunk(fingerprint, 15) + - _getEncodedChunk(fingerprint, 20) + - _getEncodedChunk(fingerprint, 25); - - String _getEncodedChunk(Uint8List hash, int offset) { - final chunk = ByteUtil.byteArray5ToLong(hash, offset).remainder(100000); - return chunk.toString().padLeft(5, '0'); - } -} diff --git a/libsignal_protocol_dart/lib/src/fingerprint/fingerprint.dart b/libsignal_protocol_dart/lib/src/fingerprint/fingerprint.dart deleted file mode 100644 index 5b3f433..0000000 --- a/libsignal_protocol_dart/lib/src/fingerprint/fingerprint.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'displayable_fingerprint.dart'; -import 'scannable_fingerprint.dart'; - -class Fingerprint { - Fingerprint(this._displayableFingerprint, this._scannableFingerprint); - - final DisplayableFingerprint _displayableFingerprint; - final ScannableFingerprint _scannableFingerprint; - - DisplayableFingerprint get displayableFingerprint => _displayableFingerprint; - ScannableFingerprint get scannableFingerprint => _scannableFingerprint; -} diff --git a/libsignal_protocol_dart/lib/src/fingerprint/fingerprint_generator.dart b/libsignal_protocol_dart/lib/src/fingerprint/fingerprint_generator.dart deleted file mode 100644 index 0f98086..0000000 --- a/libsignal_protocol_dart/lib/src/fingerprint/fingerprint_generator.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'dart:typed_data'; - -import '../identity_key.dart'; -import 'fingerprint.dart'; - -abstract class FingerprintGenerator { - Fingerprint createFor( - int version, - Uint8List localStableIdentifier, - IdentityKey localIdentityKey, - Uint8List remoteStableIdentifier, - IdentityKey remoteIdentityKey); - - Fingerprint createListFor( - int version, - Uint8List localStableIdentifier, - List localIdentityKey, - Uint8List remoteStableIdentifier, - List remoteIdentityKey); -} diff --git a/libsignal_protocol_dart/lib/src/fingerprint/fingerprint_parsing_exception.dart b/libsignal_protocol_dart/lib/src/fingerprint/fingerprint_parsing_exception.dart deleted file mode 100644 index 61f5807..0000000 --- a/libsignal_protocol_dart/lib/src/fingerprint/fingerprint_parsing_exception.dart +++ /dev/null @@ -1,8 +0,0 @@ -class FingerprintParsingException implements Exception { - FingerprintParsingException(this._message); - - final Exception _message; - - @override - String toString() => 'FingerprintParsingException - $_message'; -} diff --git a/libsignal_protocol_dart/lib/src/fingerprint/fingerprint_version_mismatch_exception.dart b/libsignal_protocol_dart/lib/src/fingerprint/fingerprint_version_mismatch_exception.dart deleted file mode 100644 index a0aa351..0000000 --- a/libsignal_protocol_dart/lib/src/fingerprint/fingerprint_version_mismatch_exception.dart +++ /dev/null @@ -1,8 +0,0 @@ -class FingerprintVersionMismatchException implements Exception { - FingerprintVersionMismatchException(this._theirVersion, this._ourVersion); - - // ignore: unused_field - final int _theirVersion; - // ignore: unused_field - final int _ourVersion; -} diff --git a/libsignal_protocol_dart/lib/src/fingerprint/numeric_fingerprint_generator.dart b/libsignal_protocol_dart/lib/src/fingerprint/numeric_fingerprint_generator.dart deleted file mode 100644 index 41a121c..0000000 --- a/libsignal_protocol_dart/lib/src/fingerprint/numeric_fingerprint_generator.dart +++ /dev/null @@ -1,79 +0,0 @@ -import 'dart:typed_data'; - -import 'package:convert/convert.dart'; -import 'package:crypto/crypto.dart'; - -import '../identity_key.dart'; -import '../util/byte_util.dart'; -import '../util/identity_key_comparator.dart'; -import 'displayable_fingerprint.dart'; -import 'fingerprint.dart'; -import 'fingerprint_generator.dart'; -import 'scannable_fingerprint.dart'; - -class NumericFingerprintGenerator implements FingerprintGenerator { - NumericFingerprintGenerator(this._iterations); - - static const int fingerprintVersion = 0; - - final int _iterations; - - @override - Fingerprint createFor( - int version, - Uint8List localStableIdentifier, - IdentityKey localIdentityKey, - Uint8List remoteStableIdentifier, - IdentityKey remoteIdentityKey) => - createListFor(version, localStableIdentifier, [localIdentityKey], - remoteStableIdentifier, [remoteIdentityKey]); - - @override - Fingerprint createListFor( - int version, - Uint8List localStableIdentifier, - List localIdentityKey, - Uint8List remoteStableIdentifier, - List remoteIdentityKey) { - final localFingerprint = - _getFingerprint(_iterations, localStableIdentifier, localIdentityKey); - final remoteFingerprint = - _getFingerprint(_iterations, remoteStableIdentifier, remoteIdentityKey); - final displayableFingerprint = - DisplayableFingerprint(localFingerprint, remoteFingerprint); - final scannableFingerprint = - ScannableFingerprint(version, localFingerprint, remoteFingerprint); - return Fingerprint(displayableFingerprint, scannableFingerprint); - } - - Uint8List _getFingerprint(int iterations, Uint8List stableIdentifier, - List unsortedIdentityKeys) { - final publicKey = _getLogicalKeyBytes(unsortedIdentityKeys); - var hash = ByteUtil.combine([ - ByteUtil.shortToByteArray(fingerprintVersion), - publicKey, - stableIdentifier - ]); - for (var i = 0; i < iterations; i++) { - final output = AccumulatorSink(); - sha512.startChunkedConversion(output) - ..add(hash) - ..add(publicKey) - ..close(); - hash = Uint8List.fromList(output.events.single.bytes); - } - - return hash; - } - - Uint8List _getLogicalKeyBytes(List identityKeys) { - final sortedIdentityKeys = [...identityKeys]..sort(identityKeyComparator); - - final keys = []; - sortedIdentityKeys.forEach((key) { - final publicKeyBytes = key.publicKey.serialize(); - keys.addAll(publicKeyBytes.toList()); - }); - return Uint8List.fromList(keys); - } -} diff --git a/libsignal_protocol_dart/lib/src/fingerprint/scannable_fingerprint.dart b/libsignal_protocol_dart/lib/src/fingerprint/scannable_fingerprint.dart deleted file mode 100644 index b84c99d..0000000 --- a/libsignal_protocol_dart/lib/src/fingerprint/scannable_fingerprint.dart +++ /dev/null @@ -1,49 +0,0 @@ -import 'dart:typed_data'; - -import 'package:crypto/crypto.dart'; -import 'package:protobuf/protobuf.dart'; - -import '../state/fingerprint_protocol.pb.dart'; -import '../util/byte_util.dart'; -import 'fingerprint_parsing_exception.dart'; -import 'fingerprint_version_mismatch_exception.dart'; - -class ScannableFingerprint { - ScannableFingerprint(int version, Uint8List localFingerprintData, - Uint8List remoteFingerprintData) { - final localFingerprint = LogicalFingerprint.create() - ..content = ByteUtil.trim(localFingerprintData, 32); - - final remoteFingerprint = LogicalFingerprint.create() - ..content = ByteUtil.trim(remoteFingerprintData, 32); - - _version = version; - _fingerprints = CombinedFingerprints.create() - ..version = version - ..localFingerprint = localFingerprint - ..remoteFingerprint = remoteFingerprint; - } - - late int _version; - late CombinedFingerprints _fingerprints; - - bool compareTo(Uint8List scannedFingerprintData) { - try { - final scanned = CombinedFingerprints.fromBuffer(scannedFingerprintData); - if (!scanned.hasRemoteFingerprint() || - !scanned.hasLocalFingerprint() || - !scanned.hasVersion() || - scanned.version != _version) { - throw FingerprintVersionMismatchException(scanned.version, _version); - } - return Digest(_fingerprints.localFingerprint.content) == - Digest(scanned.remoteFingerprint.content) && - Digest(_fingerprints.remoteFingerprint.content) == - Digest(scanned.localFingerprint.content); - } on InvalidProtocolBufferException catch (e) { - throw FingerprintParsingException(e); - } - } - - Uint8List get fingerprints => _fingerprints.writeToBuffer(); -} diff --git a/libsignal_protocol_dart/lib/src/groups/group_cipher.dart b/libsignal_protocol_dart/lib/src/groups/group_cipher.dart deleted file mode 100644 index f2b7c38..0000000 --- a/libsignal_protocol_dart/lib/src/groups/group_cipher.dart +++ /dev/null @@ -1,98 +0,0 @@ -import 'dart:typed_data'; - -import '../cbc.dart'; -import '../decryption_callback.dart'; -import '../duplicate_message_exception.dart'; -import '../invalid_key_exception.dart'; -import '../invalid_key_id_exception.dart'; -import '../invalid_message_exception.dart'; -import '../no_session_exception.dart'; -import '../protocol/sender_key_message.dart'; -import 'ratchet/sender_message_key.dart'; -import 'sender_key_name.dart'; -import 'state/sender_key_state.dart'; -import 'state/sender_key_store.dart'; - -class GroupCipher { - GroupCipher(this._senderKeyStore, this._senderKeyId); - - final SenderKeyStore _senderKeyStore; - final SenderKeyName _senderKeyId; - - Future encrypt(Uint8List paddedPlaintext) async { - try { - final record = await _senderKeyStore.loadSenderKey(_senderKeyId); - final senderKeyState = record.getSenderKeyState(); - final senderKey = senderKeyState.senderChainKey.senderMessageKey; - final ciphertext = - aesCbcEncrypt(senderKey.cipherKey, senderKey.iv, paddedPlaintext); - final senderKeyMessage = SenderKeyMessage(senderKeyState.keyId, - senderKey.iteration, ciphertext, senderKeyState.signingKeyPrivate); - final nextSenderChainKey = senderKeyState.senderChainKey.next; - senderKeyState.senderChainKey = nextSenderChainKey; - await _senderKeyStore.storeSenderKey(_senderKeyId, record); - return senderKeyMessage.serialize(); - } on InvalidKeyIdException catch (e) { - throw NoSessionException(e.detailMessage); - } - } - - Future decrypt(Uint8List senderKeyMessageBytes) async => - decryptWithCallback(senderKeyMessageBytes, () {}()); - - Future decryptWithCallback( - Uint8List senderKeyMessageBytes, DecryptionCallback? callback) async { - try { - final record = await _senderKeyStore.loadSenderKey(_senderKeyId); - if (record.isEmpty) { - throw NoSessionException( - 'No group sender key for: ${_senderKeyId.serialize()}'); - } - - final senderKeyMessage = - SenderKeyMessage.fromSerialized(senderKeyMessageBytes); - final senderKeyState = - record.getSenderKeyStateById(senderKeyMessage.keyId); - senderKeyMessage.verifySignature(senderKeyState.signingKeyPublic); - final senderKey = - getSenderKey(senderKeyState, senderKeyMessage.iteration); - final plaintext = aesCbcDecrypt( - senderKey.cipherKey, senderKey.iv, senderKeyMessage.ciphertext); - - if (callback != null) { - callback(plaintext); - } - - await _senderKeyStore.storeSenderKey(_senderKeyId, record); - return plaintext; - } on InvalidKeyIdException catch (e) { - throw InvalidMessageException(e.detailMessage); - } on InvalidKeyException catch (e) { - throw InvalidMessageException(e.detailMessage); - } - } - - SenderMessageKey getSenderKey(SenderKeyState senderKeyState, int iteration) { - var senderChainKey = senderKeyState.senderChainKey; - if (senderChainKey.iteration > iteration) { - if (senderKeyState.hasSenderMessageKey(iteration)) { - return senderKeyState.removeSenderMessageKey(iteration)!; - } else { - throw DuplicateMessageException('Received message with old counter: ' - '${senderChainKey.iteration} , $iteration'); - } - } - - if (iteration - senderChainKey.iteration > 2000) { - throw InvalidMessageException('Over 2000 messages into the future!'); - } - - while (senderChainKey.iteration < iteration) { - senderKeyState.addSenderMessageKey(senderChainKey.senderMessageKey); - senderChainKey = senderChainKey.next; - } - - senderKeyState.senderChainKey = senderChainKey.next; - return senderChainKey.senderMessageKey; - } -} diff --git a/libsignal_protocol_dart/lib/src/groups/group_session_builder.dart b/libsignal_protocol_dart/lib/src/groups/group_session_builder.dart deleted file mode 100644 index 14832cc..0000000 --- a/libsignal_protocol_dart/lib/src/groups/group_session_builder.dart +++ /dev/null @@ -1,48 +0,0 @@ -import '../invalid_key_exception.dart'; -import '../invalid_key_id_exception.dart'; -import '../protocol/sender_key_distribution_message_wrapper.dart'; -import '../util/key_helper.dart'; -import 'sender_key_name.dart'; -import 'state/sender_key_store.dart'; - -class GroupSessionBuilder { - GroupSessionBuilder(this._senderKeyStore); - - final SenderKeyStore _senderKeyStore; - - Future process( - SenderKeyName senderKeyName, - SenderKeyDistributionMessageWrapper - senderKeyDistributionMessageWrapper) async { - final senderKeyRecord = await _senderKeyStore.loadSenderKey(senderKeyName); - senderKeyRecord.addSenderKeyState( - senderKeyDistributionMessageWrapper.id, - senderKeyDistributionMessageWrapper.iteration, - senderKeyDistributionMessageWrapper.chainKey, - senderKeyDistributionMessageWrapper.signatureKey); - await _senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord); - } - - Future create( - SenderKeyName senderKeyName) async { - try { - final senderKeyRecord = - await _senderKeyStore.loadSenderKey(senderKeyName); - if (senderKeyRecord.isEmpty) { - senderKeyRecord.setSenderKeyState(generateSenderKeyId(), 0, - generateSenderKey(), generateSenderSigningKey()); - await _senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord); - } - final state = senderKeyRecord.getSenderKeyState(); - return SenderKeyDistributionMessageWrapper( - state.keyId, - state.senderChainKey.iteration, - state.senderChainKey.seed, - state.signingKeyPublic); - } on InvalidKeyIdException catch (e) { - throw AssertionError(e); - } on InvalidKeyException catch (e) { - throw AssertionError(e); - } - } -} diff --git a/libsignal_protocol_dart/lib/src/groups/ratchet/sender_chain_key.dart b/libsignal_protocol_dart/lib/src/groups/ratchet/sender_chain_key.dart deleted file mode 100644 index 0d8b377..0000000 --- a/libsignal_protocol_dart/lib/src/groups/ratchet/sender_chain_key.dart +++ /dev/null @@ -1,31 +0,0 @@ -import 'dart:typed_data'; - -import 'package:crypto/crypto.dart'; - -import 'sender_message_key.dart'; - -class SenderChainKey { - SenderChainKey(this._iteration, this._chainKey); - - static final Uint8List _messageKeySeed = Uint8List.fromList([0x01]); - static final Uint8List _chainKeySeed = Uint8List.fromList([0x02]); - - final int _iteration; - final Uint8List _chainKey; - - int get iteration => _iteration; - - Uint8List get seed => _chainKey; - - SenderMessageKey get senderMessageKey => - SenderMessageKey(_iteration, getDerivative(_messageKeySeed, _chainKey)); - - SenderChainKey get next => - SenderChainKey(_iteration + 1, getDerivative(_chainKeySeed, _chainKey)); - - Uint8List getDerivative(Uint8List seed, Uint8List key) { - final hmacSha256 = Hmac(sha256, key); - final digest = hmacSha256.convert(seed); - return Uint8List.fromList(digest.bytes); - } -} diff --git a/libsignal_protocol_dart/lib/src/groups/ratchet/sender_message_key.dart b/libsignal_protocol_dart/lib/src/groups/ratchet/sender_message_key.dart deleted file mode 100644 index 52979f7..0000000 --- a/libsignal_protocol_dart/lib/src/groups/ratchet/sender_message_key.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'dart:typed_data'; - -import '../../kdf/hkdfv3.dart'; -import '../../util/byte_util.dart'; - -class SenderMessageKey { - SenderMessageKey(this._iteration, this._seed) { - final derivative = HKDFv3() - .deriveSecrets(seed, Uint8List.fromList('WhisperGroup'.codeUnits), 48); - final parts = ByteUtil.splitTwo(derivative, 16, 32); - _iv = parts[0]; - _cipherKey = parts[1]; - } - - final int _iteration; - final Uint8List _seed; - late Uint8List _iv; - late Uint8List _cipherKey; - - int get iteration => _iteration; - Uint8List get iv => _iv; - Uint8List get cipherKey => _cipherKey; - Uint8List get seed => _seed; -} diff --git a/libsignal_protocol_dart/lib/src/groups/sender_key_name.dart b/libsignal_protocol_dart/lib/src/groups/sender_key_name.dart deleted file mode 100644 index 2420385..0000000 --- a/libsignal_protocol_dart/lib/src/groups/sender_key_name.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:meta/meta.dart'; - -import '../signal_protocol_address.dart'; - -@immutable -class SenderKeyName { - const SenderKeyName(this._groupId, this._sender); - - final String _groupId; - final SignalProtocolAddress _sender; - - String get groupId => _groupId; - - SignalProtocolAddress get sender => _sender; - - String serialize() => - '$_groupId::${_sender.getName()}::${_sender.getDeviceId()}'; - - @override - bool operator ==(Object other) { - if (other is! SenderKeyName) return false; - - return _groupId == other.groupId && _sender == other.sender; - } - - @override - int get hashCode => _groupId.hashCode ^ _sender.hashCode; -} diff --git a/libsignal_protocol_dart/lib/src/groups/state/in_memory_sender_key_store.dart b/libsignal_protocol_dart/lib/src/groups/state/in_memory_sender_key_store.dart deleted file mode 100644 index 9884fbc..0000000 --- a/libsignal_protocol_dart/lib/src/groups/state/in_memory_sender_key_store.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'dart:collection'; - -import '../sender_key_name.dart'; -import 'sender_key_record.dart'; -import 'sender_key_store.dart'; - -class InMemorySenderKeyStore extends SenderKeyStore { - final _store = HashMap(); - - @override - Future loadSenderKey(SenderKeyName senderKeyName) async { - try { - final record = _store[senderKeyName]; - if (record == null) { - return SenderKeyRecord(); - } else { - return SenderKeyRecord.fromSerialized(record.serialize()); - } - } on Exception catch (e) { - throw AssertionError(e); - } - } - - @override - Future storeSenderKey( - SenderKeyName senderKeyName, SenderKeyRecord record) async { - _store[senderKeyName] = record; - } -} diff --git a/libsignal_protocol_dart/lib/src/groups/state/sender_key_record.dart b/libsignal_protocol_dart/lib/src/groups/state/sender_key_record.dart deleted file mode 100644 index 878bcc1..0000000 --- a/libsignal_protocol_dart/lib/src/groups/state/sender_key_record.dart +++ /dev/null @@ -1,71 +0,0 @@ -import 'dart:collection'; -import 'dart:typed_data'; - -import '../../ecc/ec_key_pair.dart'; -import '../../ecc/ec_public_key.dart'; -import '../../entry.dart'; -import '../../invalid_key_id_exception.dart'; -import '../../state/local_storage_protocol.pb.dart'; -import 'sender_key_state.dart'; - -class SenderKeyRecord { - SenderKeyRecord(); - - SenderKeyRecord.fromSerialized(Uint8List serialized) { - final senderKeyRecordStructure = - SenderKeyRecordStructure.fromBuffer(serialized); - for (final structure in senderKeyRecordStructure.senderKeyStates) { - _senderKeyStates - .add(Entry(SenderKeyState.fromSenderKeyStateStructure(structure))); - } - } - - static const int _maxStates = 5; - - final LinkedList> _senderKeyStates = - LinkedList>(); - - bool get isEmpty => _senderKeyStates.isEmpty; - - SenderKeyState getSenderKeyState() { - if (_senderKeyStates.isNotEmpty) { - return _senderKeyStates.first.value; - } else { - throw InvalidKeyIdException('No key state in record!'); - } - } - - SenderKeyState getSenderKeyStateById(int keyId) { - for (final state in _senderKeyStates) { - if (state.value.keyId == keyId) { - return state.value; - } - } - throw InvalidKeyIdException('No key for: $keyId'); - } - - void addSenderKeyState( - int id, int iteration, Uint8List chainKey, ECPublicKey signatureKey) { - _senderKeyStates.addFirst(Entry( - SenderKeyState.fromPublicKey(id, iteration, chainKey, signatureKey))); - if (_senderKeyStates.length > _maxStates) { - _senderKeyStates.remove(_senderKeyStates.last); - } - } - - void setSenderKeyState( - int id, int iteration, Uint8List chainKey, ECKeyPair signatureKey) { - _senderKeyStates - ..clear() - ..add(Entry( - SenderKeyState.fromKeyPair(id, iteration, chainKey, signatureKey))); - } - - Uint8List serialize() { - final recordStructure = SenderKeyRecordStructure.create(); - _senderKeyStates.forEach((entry) { - recordStructure.senderKeyStates.add(entry.value.structure); - }); - return recordStructure.writeToBuffer(); - } -} diff --git a/libsignal_protocol_dart/lib/src/groups/state/sender_key_state.dart b/libsignal_protocol_dart/lib/src/groups/state/sender_key_state.dart deleted file mode 100644 index 8b71842..0000000 --- a/libsignal_protocol_dart/lib/src/groups/state/sender_key_state.dart +++ /dev/null @@ -1,107 +0,0 @@ -import 'dart:typed_data'; - -import 'package:optional/optional.dart'; - -import '../../ecc/curve.dart'; -import '../../ecc/ec_key_pair.dart'; -import '../../ecc/ec_private_key.dart'; -import '../../ecc/ec_public_key.dart'; -import '../../state/local_storage_protocol.pb.dart'; -import '../ratchet/sender_chain_key.dart'; -import '../ratchet/sender_message_key.dart'; - -class SenderKeyState { - SenderKeyState.fromPublicKey(int id, int iteration, Uint8List chainKey, - ECPublicKey signatureKeyPublic) { - init(id, iteration, chainKey, signatureKeyPublic, const Optional.empty()); - } - - SenderKeyState.fromKeyPair( - int id, int iteration, Uint8List chainKey, ECKeyPair signatureKey) { - final signatureKeyPublic = signatureKey.publicKey; - final signatureKeyPrivate = Optional.of(signatureKey.privateKey); - init(id, iteration, chainKey, signatureKeyPublic, signatureKeyPrivate); - } - - SenderKeyState.fromSenderKeyStateStructure( - SenderKeyStateStructure senderKeyStateStructure) { - _senderKeyStateStructure = senderKeyStateStructure; - } - - static const int _maxMessageKeys = 2000; - - late SenderKeyStateStructure _senderKeyStateStructure; - - void init( - int id, int iteration, Uint8List chainKey, ECPublicKey signatureKeyPublic, - [Optional? signatureKeyPrivate]) { - final seed = Uint8List.fromList(chainKey); - final senderChainKeyStructure = - SenderKeyStateStructureSenderChainKey.create() - ..iteration = iteration - ..seed = seed; - final signingKeyStructure = SenderKeyStateStructureSenderSigningKey.create() - ..public = signatureKeyPublic.serialize(); - if (signatureKeyPrivate!.isPresent) { - signingKeyStructure.private = signatureKeyPrivate.value.serialize(); - } - _senderKeyStateStructure = SenderKeyStateStructure.create() - ..senderKeyId = id - ..senderChainKey = senderChainKeyStructure - ..senderSigningKey = signingKeyStructure; - } - - int get keyId => _senderKeyStateStructure.senderKeyId; - - SenderChainKey get senderChainKey => SenderChainKey( - _senderKeyStateStructure.senderChainKey.iteration, - Uint8List.fromList(_senderKeyStateStructure.senderChainKey.seed)); - - set senderChainKey(SenderChainKey senderChainKey) => { - _senderKeyStateStructure.senderChainKey = - SenderKeyStateStructureSenderChainKey.create() - ..iteration = senderChainKey.iteration - ..seed = List.from(senderChainKey.seed) - }; - - ECPublicKey get signingKeyPublic => Curve.decodePointList( - _senderKeyStateStructure.senderSigningKey.public, 0); - - ECPrivateKey get signingKeyPrivate => Curve.decodePrivatePoint( - Uint8List.fromList(_senderKeyStateStructure.senderSigningKey.private)); - - bool hasSenderMessageKey(int iteration) { - for (final senderMessageKey in _senderKeyStateStructure.senderMessageKeys) { - if (senderMessageKey.iteration == iteration) { - return true; - } - } - return false; - } - - void addSenderMessageKey(SenderMessageKey senderMessageKey) { - final senderMessageKeyStructure = - SenderKeyStateStructureSenderMessageKey.create() - ..iteration = senderMessageKey.iteration - ..seed = senderMessageKey.seed; - _senderKeyStateStructure.senderMessageKeys.add(senderMessageKeyStructure); - if (_senderKeyStateStructure.senderMessageKeys.length > _maxMessageKeys) { - _senderKeyStateStructure.senderMessageKeys.removeAt(0); - } - } - - SenderMessageKey? removeSenderMessageKey(int iteration) { - _senderKeyStateStructure.senderMessageKeys - .toList() - .addAll(_senderKeyStateStructure.senderMessageKeys); - final index = _senderKeyStateStructure.senderMessageKeys - .indexWhere((item) => item.iteration == iteration); - if (index == -1) return null; - final senderMessageKey = - _senderKeyStateStructure.senderMessageKeys.removeAt(index); - return SenderMessageKey( - senderMessageKey.iteration, Uint8List.fromList(senderMessageKey.seed)); - } - - SenderKeyStateStructure get structure => _senderKeyStateStructure; -} diff --git a/libsignal_protocol_dart/lib/src/groups/state/sender_key_store.dart b/libsignal_protocol_dart/lib/src/groups/state/sender_key_store.dart deleted file mode 100644 index 5e57359..0000000 --- a/libsignal_protocol_dart/lib/src/groups/state/sender_key_store.dart +++ /dev/null @@ -1,9 +0,0 @@ -import '../sender_key_name.dart'; -import 'sender_key_record.dart'; - -abstract class SenderKeyStore { - Future storeSenderKey( - SenderKeyName senderKeyName, SenderKeyRecord record); - - Future loadSenderKey(SenderKeyName senderKeyName); -} diff --git a/libsignal_protocol_dart/lib/src/identity_key.dart b/libsignal_protocol_dart/lib/src/identity_key.dart deleted file mode 100644 index f2516df..0000000 --- a/libsignal_protocol_dart/lib/src/identity_key.dart +++ /dev/null @@ -1,33 +0,0 @@ -import 'dart:typed_data'; - -import 'package:convert/convert.dart'; -import 'package:meta/meta.dart'; - -import 'ecc/curve.dart'; -import 'ecc/ec_public_key.dart'; - -@immutable -class IdentityKey { - const IdentityKey(this._publicKey); - - factory IdentityKey.fromBytes(Uint8List bytes, int offset) => - IdentityKey(Curve.decodePoint(bytes, offset)); - - final ECPublicKey _publicKey; - - ECPublicKey get publicKey => _publicKey; - - Uint8List serialize() => _publicKey.serialize(); - - String getFingerprint() => hex.encode(_publicKey.serialize()); - - @override - bool operator ==(Object other) { - if (other is! IdentityKey) return false; - - return _publicKey == other._publicKey; - } - - @override - int get hashCode => _publicKey.hashCode; -} diff --git a/libsignal_protocol_dart/lib/src/identity_key_pair.dart b/libsignal_protocol_dart/lib/src/identity_key_pair.dart deleted file mode 100644 index 6c9d4e0..0000000 --- a/libsignal_protocol_dart/lib/src/identity_key_pair.dart +++ /dev/null @@ -1,32 +0,0 @@ -import 'dart:typed_data'; - -import 'ecc/curve.dart'; -import 'ecc/ec_private_key.dart'; -import 'identity_key.dart'; -import 'state/local_storage_protocol.pb.dart'; - -class IdentityKeyPair { - IdentityKeyPair(this._publicKey, this._privateKey); - - IdentityKeyPair.fromSerialized(Uint8List serialized) { - final structure = IdentityKeyPairStructure.fromBuffer(serialized); - _publicKey = - IdentityKey.fromBytes(Uint8List.fromList(structure.publicKey), 0); - _privateKey = - Curve.decodePrivatePoint(Uint8List.fromList(structure.privateKey)); - } - - late IdentityKey _publicKey; - late ECPrivateKey _privateKey; - - IdentityKey getPublicKey() => _publicKey; - - ECPrivateKey getPrivateKey() => _privateKey; - - Uint8List serialize() { - final i = IdentityKeyPairStructure.create() - ..publicKey = List.from(_publicKey.serialize()) - ..privateKey = List.from(_privateKey.serialize()); - return i.toBuilder().writeToBuffer(); - } -} diff --git a/libsignal_protocol_dart/lib/src/invalid_key_exception.dart b/libsignal_protocol_dart/lib/src/invalid_key_exception.dart deleted file mode 100644 index e3bef90..0000000 --- a/libsignal_protocol_dart/lib/src/invalid_key_exception.dart +++ /dev/null @@ -1,7 +0,0 @@ -class InvalidKeyException implements Exception { - InvalidKeyException(this.detailMessage); - final String detailMessage; - - @override - String toString() => 'InvalidKeyException - $detailMessage'; -} diff --git a/libsignal_protocol_dart/lib/src/invalid_key_id_exception.dart b/libsignal_protocol_dart/lib/src/invalid_key_id_exception.dart deleted file mode 100644 index 265adcb..0000000 --- a/libsignal_protocol_dart/lib/src/invalid_key_id_exception.dart +++ /dev/null @@ -1,7 +0,0 @@ -class InvalidKeyIdException implements Exception { - InvalidKeyIdException(this.detailMessage); - final String detailMessage; - - @override - String toString() => 'InvalidKeyIdException - $detailMessage'; -} diff --git a/libsignal_protocol_dart/lib/src/invalid_mac_exception.dart b/libsignal_protocol_dart/lib/src/invalid_mac_exception.dart deleted file mode 100644 index d49b853..0000000 --- a/libsignal_protocol_dart/lib/src/invalid_mac_exception.dart +++ /dev/null @@ -1,7 +0,0 @@ -class InvalidMacException implements Exception { - InvalidMacException(this.detailMessage); - final String detailMessage; - - @override - String toString() => 'InvalidMacException - $detailMessage'; -} diff --git a/libsignal_protocol_dart/lib/src/invalid_message_exception.dart b/libsignal_protocol_dart/lib/src/invalid_message_exception.dart deleted file mode 100644 index 388b79d..0000000 --- a/libsignal_protocol_dart/lib/src/invalid_message_exception.dart +++ /dev/null @@ -1,7 +0,0 @@ -class InvalidMessageException implements Exception { - InvalidMessageException(this.detailMessage); - final String detailMessage; - - @override - String toString() => 'InvalidMessageException - $detailMessage'; -} diff --git a/libsignal_protocol_dart/lib/src/kdf/derived_message_secrets.dart b/libsignal_protocol_dart/lib/src/kdf/derived_message_secrets.dart deleted file mode 100644 index d54f4be..0000000 --- a/libsignal_protocol_dart/lib/src/kdf/derived_message_secrets.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'dart:typed_data'; - -import '../util/byte_util.dart'; - -class DerivedMessageSecrets { - DerivedMessageSecrets(Uint8List okm) { - final keys = - ByteUtil.split(okm, _cipherKeyLength, _macKeyLength, _ivLength); - - _cipherKey = keys[0]; - _macKey = keys[1]; - _iv = keys[2]; - } - - static const int size = 80; - static const int _cipherKeyLength = 32; - static const int _macKeyLength = 32; - static const int _ivLength = 16; - - late Uint8List _cipherKey; - late Uint8List _macKey; - late Uint8List _iv; - - Uint8List getCipherKey() => _cipherKey; - - Uint8List getMacKey() => _macKey; - - Uint8List getIv() => _iv; -} diff --git a/libsignal_protocol_dart/lib/src/kdf/derived_root_secrets.dart b/libsignal_protocol_dart/lib/src/kdf/derived_root_secrets.dart deleted file mode 100644 index 9426186..0000000 --- a/libsignal_protocol_dart/lib/src/kdf/derived_root_secrets.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'dart:typed_data'; - -import '../util/byte_util.dart'; - -class DerivedRootSecrets { - DerivedRootSecrets(Uint8List okm) { - final keys = ByteUtil.splitTwo(okm, 32, 32); - _rootKey = keys[0]; - _chainKey = keys[1]; - } - - static const int size = 64; - - late Uint8List _rootKey; - late Uint8List _chainKey; - - Uint8List getRootKey() => _rootKey; - - Uint8List getChainKey() => _chainKey; -} diff --git a/libsignal_protocol_dart/lib/src/kdf/hkdf.dart b/libsignal_protocol_dart/lib/src/kdf/hkdf.dart deleted file mode 100644 index 5645147..0000000 --- a/libsignal_protocol_dart/lib/src/kdf/hkdf.dart +++ /dev/null @@ -1,81 +0,0 @@ -import 'dart:math'; -import 'dart:typed_data'; - -import 'package:convert/convert.dart'; -import 'package:crypto/crypto.dart'; - -import '../invalid_key_exception.dart'; -import 'hkdfv2.dart'; -import 'hkdfv3.dart'; - -abstract class HKDF { - static const int hashOutputSize = 32; - - static HKDF createFor(int messageVersion) { - switch (messageVersion) { - case 2: - return HKDFv2(); - case 3: - return HKDFv3(); - default: - throw AssertionError('Unknown version: $messageVersion'); - } - } - - Uint8List deriveSecrets( - Uint8List inputKeyMaterial, Uint8List info, int outputLength) { - final salt = Uint8List(hashOutputSize); - return deriveSecrets4(inputKeyMaterial, salt, info, outputLength); - } - - Uint8List deriveSecrets4(Uint8List inputKeyMaterial, Uint8List salt, - Uint8List info, int outputLength) { - final prk = extract(salt, inputKeyMaterial); - return expand(prk, info, outputLength); - } - - Uint8List extract(Uint8List salt, Uint8List inputKeyMaterial) { - final hmacSha256 = Hmac(sha256, salt); - final digest = hmacSha256.convert(inputKeyMaterial); - return Uint8List.fromList(digest.bytes); - } - - Uint8List expand(Uint8List prk, Uint8List? info, int outputSize) { - try { - final iterations = - (outputSize.toDouble() / hashOutputSize.toDouble()).ceil(); - var mix = Uint8List(0); - final results = Uint8List(outputSize); - var remainingBytes = outputSize; - - for (var i = getIterationStartOffset(); - i < iterations + getIterationStartOffset(); - i++) { - final mac = Hmac(sha256, prk); - final output = AccumulatorSink(); - final input = mac.startChunkedConversion(output)..add(mix); - if (info != null) { - input.add(info); - } - input - ..add([i]) - ..close(); - final stepResult = Uint8List.fromList(output.events.single.bytes); - final stepSize = min(remainingBytes, stepResult.length); - - for (var j = 0; j < stepSize; j++) { - final offset = (i - getIterationStartOffset()) * hashOutputSize + j; - results[offset] = stepResult[j]; - } - - mix = stepResult; - remainingBytes -= stepSize; - } - return results.buffer.asUint8List(); - } on InvalidKeyException catch (e) { - throw AssertionError(e); - } - } - - int getIterationStartOffset(); -} diff --git a/libsignal_protocol_dart/lib/src/kdf/hkdfv2.dart b/libsignal_protocol_dart/lib/src/kdf/hkdfv2.dart deleted file mode 100644 index 3c7bc7b..0000000 --- a/libsignal_protocol_dart/lib/src/kdf/hkdfv2.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'hkdf.dart'; - -class HKDFv2 extends HKDF { - @override - int getIterationStartOffset() => 0; -} diff --git a/libsignal_protocol_dart/lib/src/kdf/hkdfv3.dart b/libsignal_protocol_dart/lib/src/kdf/hkdfv3.dart deleted file mode 100644 index 1defb1e..0000000 --- a/libsignal_protocol_dart/lib/src/kdf/hkdfv3.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'hkdf.dart'; - -class HKDFv3 extends HKDF { - @override - int getIterationStartOffset() => 1; -} diff --git a/libsignal_protocol_dart/lib/src/legacy_message_exception.dart b/libsignal_protocol_dart/lib/src/legacy_message_exception.dart deleted file mode 100644 index e389d13..0000000 --- a/libsignal_protocol_dart/lib/src/legacy_message_exception.dart +++ /dev/null @@ -1,7 +0,0 @@ -class LegacyMessageException implements Exception { - LegacyMessageException(this.detailMessage); - final String detailMessage; - - @override - String toString() => 'LegacyMessageException - $detailMessage'; -} diff --git a/libsignal_protocol_dart/lib/src/no_session_exception.dart b/libsignal_protocol_dart/lib/src/no_session_exception.dart deleted file mode 100644 index ed9b257..0000000 --- a/libsignal_protocol_dart/lib/src/no_session_exception.dart +++ /dev/null @@ -1,7 +0,0 @@ -class NoSessionException implements Exception { - NoSessionException(this.detailMessage); - final String detailMessage; - - @override - String toString() => 'NoSessionException - $detailMessage'; -} diff --git a/libsignal_protocol_dart/lib/src/protocol/ciphertext_message.dart b/libsignal_protocol_dart/lib/src/protocol/ciphertext_message.dart deleted file mode 100644 index 17bb26e..0000000 --- a/libsignal_protocol_dart/lib/src/protocol/ciphertext_message.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'dart:typed_data'; - -abstract class CiphertextMessage { - static const int currentVersion = 3; - - static const int whisperType = 2; - static const int prekeyType = 3; - static const int senderKeyType = 4; - static const int senderKeyDistributionType = 5; - - // This should be the worst case (worse than V2). So not always accurate, but good enough for padding. - static const int encryptedMessageOverhead = 53; - - Uint8List serialize(); - int getType(); -} diff --git a/libsignal_protocol_dart/lib/src/protocol/device_consistency_message.dart b/libsignal_protocol_dart/lib/src/protocol/device_consistency_message.dart deleted file mode 100644 index a87fe7d..0000000 --- a/libsignal_protocol_dart/lib/src/protocol/device_consistency_message.dart +++ /dev/null @@ -1,71 +0,0 @@ -import 'dart:typed_data'; - -import 'package:protobuf/protobuf.dart'; - -import '../devices/device_consistency_commitment.dart'; -import '../devices/device_consistency_signature.dart'; -import '../ecc/curve.dart'; -import '../identity_key.dart'; -import '../identity_key_pair.dart'; -import '../invalid_key_exception.dart'; -import '../invalid_message_exception.dart'; -import '../state/whisper_text_protocol.pb.dart'; - -class DeviceConsistencyMessage { - DeviceConsistencyMessage( - DeviceConsistencyCommitment commitment, IdentityKeyPair identityKeyPair) { - try { - final signatureBytes = Curve.calculateVrfSignature( - identityKeyPair.getPrivateKey(), commitment.serialized); - final vrfOutputBytes = Curve.verifyVrfSignature( - identityKeyPair.getPublicKey().publicKey, - commitment.serialized, - signatureBytes); - - _generation = commitment.generation; - _signature = DeviceConsistencySignature(signatureBytes, vrfOutputBytes); - final d = DeviceConsistencyCodeMessage.create() - ..generation = commitment.generation - ..signature = _signature.signature.toList(); - _serialized = d.writeToBuffer(); - } on InvalidKeyException catch (e) { - throw AssertionError(e); - } -// } on VrfSignatureVerificationFailedException catch (e) { -// throw AssertionError(e); -// } - } - - DeviceConsistencyMessage.fromSerialized( - DeviceConsistencyCommitment commitment, - Uint8List serialized, - IdentityKey identityKey) { - try { - final message = DeviceConsistencyCodeMessage.fromBuffer(serialized); - final vrfOutputBytes = Curve.verifyVrfSignature(identityKey.publicKey, - commitment.serialized, Uint8List.fromList(message.signature)); - - _generation = message.generation; - _signature = DeviceConsistencySignature( - Uint8List.fromList(message.signature), vrfOutputBytes); - _serialized = serialized; - } on InvalidProtocolBufferException catch (e) { - throw InvalidMessageException(e.message); - } on InvalidKeyException catch (e) { - throw InvalidMessageException(e.detailMessage); - } -// } on VrfSignatureVerificationFailedException catch (e) { -// throw AssertionError(e); -// } - } - - late DeviceConsistencySignature _signature; - late int _generation; - late Uint8List _serialized; - - Uint8List get serialized => _serialized; - - DeviceConsistencySignature get signature => _signature; - - int get generation => _generation; -} diff --git a/libsignal_protocol_dart/lib/src/protocol/pre_key_signal_message.dart b/libsignal_protocol_dart/lib/src/protocol/pre_key_signal_message.dart deleted file mode 100644 index 058bb83..0000000 --- a/libsignal_protocol_dart/lib/src/protocol/pre_key_signal_message.dart +++ /dev/null @@ -1,101 +0,0 @@ -import 'dart:typed_data'; - -import 'package:optional/optional.dart'; - -import '../ecc/curve.dart'; -import '../ecc/ec_public_key.dart'; -import '../identity_key.dart'; -import '../invalid_key_exception.dart'; -import '../invalid_message_exception.dart'; -import '../legacy_message_exception.dart'; -import '../protocol/ciphertext_message.dart'; -import '../protocol/signal_message.dart'; -import '../state/whisper_text_protocol.pb.dart' as signal_protos; -import '../util/byte_util.dart'; - -class PreKeySignalMessage extends CiphertextMessage { - PreKeySignalMessage(Uint8List serialized) { - try { - _version = ByteUtil.highBitsToInt(serialized[0]); - - final preKeyWhisperMessage = - signal_protos.PreKeySignalMessage.fromBuffer(serialized.sublist(1)); - - if (!preKeyWhisperMessage.hasSignedPreKeyId() || - !preKeyWhisperMessage.hasBaseKey() || - !preKeyWhisperMessage.hasIdentityKey() || - !preKeyWhisperMessage.hasMessage()) { - throw InvalidMessageException('Incomplete message.'); - } - - this.serialized = serialized; - registrationId = preKeyWhisperMessage.registrationId; - preKeyId = preKeyWhisperMessage.hasPreKeyId() - ? Optional.of(preKeyWhisperMessage.preKeyId) - : const Optional.empty(); - signedPreKeyId = preKeyWhisperMessage.hasSignedPreKeyId() - ? preKeyWhisperMessage.signedPreKeyId - : -1; - baseKey = Curve.decodePoint( - Uint8List.fromList(preKeyWhisperMessage.baseKey), 0); - identityKey = IdentityKey(Curve.decodePoint( - Uint8List.fromList(preKeyWhisperMessage.identityKey), 0)); - message = SignalMessage.fromSerialized( - Uint8List.fromList(preKeyWhisperMessage.message)); - } on InvalidKeyException catch (e) { - throw InvalidMessageException(e.detailMessage); - } on LegacyMessageException catch (e) { - throw InvalidMessageException(e.detailMessage); - } - } - - PreKeySignalMessage.from(this._version, this.registrationId, this.preKeyId, - this.signedPreKeyId, this.baseKey, this.identityKey, this.message) { - final builder = signal_protos.PreKeySignalMessage.create() - ..signedPreKeyId = signedPreKeyId - ..baseKey = baseKey.serialize() - ..identityKey = identityKey.serialize() - ..message = message.serialize() - ..registrationId = registrationId; - - if (preKeyId.isPresent) { - builder.preKeyId = preKeyId.value; - } - - final versionBytes = [ - ByteUtil.intsToByteHighAndLow(_version, CiphertextMessage.currentVersion) - ]; - - final messageBytes = builder.toBuilder().writeToBuffer(); - serialized = Uint8List.fromList(versionBytes + messageBytes); - } - - late int _version; - late int registrationId; - late Optional preKeyId; - late int signedPreKeyId; - late ECPublicKey baseKey; - late IdentityKey identityKey; - late SignalMessage message; - late Uint8List serialized; - - int getMessageVersion() => _version; - - IdentityKey getIdentityKey() => identityKey; - - int getRegistrationId() => registrationId; - - Optional getPreKeyId() => preKeyId; - - int getSignedPreKeyId() => signedPreKeyId; - - ECPublicKey getBaseKey() => baseKey; - - SignalMessage getWhisperMessage() => message; - - @override - int getType() => CiphertextMessage.prekeyType; - - @override - Uint8List serialize() => serialized; -} diff --git a/libsignal_protocol_dart/lib/src/protocol/sender_key_distribution_message_wrapper.dart b/libsignal_protocol_dart/lib/src/protocol/sender_key_distribution_message_wrapper.dart deleted file mode 100644 index 14e4b1b..0000000 --- a/libsignal_protocol_dart/lib/src/protocol/sender_key_distribution_message_wrapper.dart +++ /dev/null @@ -1,87 +0,0 @@ -import 'dart:typed_data'; - -import 'package:protobuf/protobuf.dart'; - -import '../ecc/curve.dart'; -import '../ecc/ec_public_key.dart'; -import '../invalid_key_exception.dart'; -import '../invalid_message_exception.dart'; -import '../legacy_message_exception.dart'; -import '../state/whisper_text_protocol.pb.dart'; -import '../util/byte_util.dart'; -import 'ciphertext_message.dart'; - -class SenderKeyDistributionMessageWrapper extends CiphertextMessage { - SenderKeyDistributionMessageWrapper( - int id, int iteration, Uint8List chainKey, ECPublicKey signatureKey) { - final version = Uint8List.fromList([ - ByteUtil.intsToByteHighAndLow( - CiphertextMessage.currentVersion, CiphertextMessage.currentVersion) - ]); - final protobuf = SenderKeyDistributionMessage.create() - ..id = id - ..iteration = iteration - ..chainKey = List.from(chainKey) - ..signingKey = List.from(signatureKey.serialize()); - _id = id; - _iteration = iteration; - _chainKey = chainKey; - _signatureKey = signatureKey; - _serialized = ByteUtil.combine([version, protobuf.writeToBuffer()]); - } - - SenderKeyDistributionMessageWrapper.fromSerialized(Uint8List serialized) { - try { - final messageParts = - ByteUtil.splitTwo(serialized, 1, serialized.length - 1); - final version = messageParts[0][0]; - final message = messageParts[1]; - - if (ByteUtil.highBitsToInt(version) < CiphertextMessage.currentVersion) { - throw LegacyMessageException( - 'Legacy message: ${ByteUtil.highBitsToInt(version)}'); - } - if (ByteUtil.highBitsToInt(version) > CiphertextMessage.currentVersion) { - throw InvalidMessageException( - 'Unknown version: ${ByteUtil.highBitsToInt(version)}'); - } - - final distributionMessages = - SenderKeyDistributionMessage.fromBuffer(message); - if (!distributionMessages.hasId() || - !distributionMessages.hasIteration() || - !distributionMessages.hasChainKey() || - !distributionMessages.hasSigningKey()) { - throw InvalidMessageException('Incomplete message.'); - } - - _serialized = serialized; - _id = distributionMessages.id; - _iteration = distributionMessages.iteration; - _chainKey = Uint8List.fromList(distributionMessages.chainKey); - _signatureKey = Curve.decodePoint( - Uint8List.fromList(distributionMessages.signingKey), 0); - } on InvalidProtocolBufferException catch (e) { - throw InvalidMessageException(e.message); - } on InvalidKeyException catch (e) { - throw InvalidMessageException(e.detailMessage); - } - } - - late int _id; - late int _iteration; - late Uint8List _chainKey; - late ECPublicKey _signatureKey; - late Uint8List _serialized; - - @override - int getType() => CiphertextMessage.senderKeyDistributionType; - - @override - Uint8List serialize() => _serialized; - - int get iteration => _iteration; - Uint8List get chainKey => _chainKey; - ECPublicKey get signatureKey => _signatureKey; - int get id => _id; -} diff --git a/libsignal_protocol_dart/lib/src/protocol/sender_key_message.dart b/libsignal_protocol_dart/lib/src/protocol/sender_key_message.dart deleted file mode 100644 index 39b99c6..0000000 --- a/libsignal_protocol_dart/lib/src/protocol/sender_key_message.dart +++ /dev/null @@ -1,108 +0,0 @@ -import 'dart:typed_data'; - -import '../ecc/curve.dart'; -import '../ecc/ec_private_key.dart'; -import '../ecc/ec_public_key.dart'; -import '../invalid_key_exception.dart'; -import '../invalid_key_id_exception.dart'; -import '../invalid_message_exception.dart'; -import '../legacy_message_exception.dart'; -import '../state/whisper_text_protocol.pb.dart' as protocol; -import '../util/byte_util.dart'; -import 'ciphertext_message.dart'; - -class SenderKeyMessage extends CiphertextMessage { - SenderKeyMessage(int keyId, int iteration, Uint8List ciphertext, - ECPrivateKey signatureKey) { - final version = Uint8List.fromList([ - ByteUtil.intsToByteHighAndLow( - CiphertextMessage.currentVersion, CiphertextMessage.currentVersion) - ]); - final message = protocol.SenderKeyMessage.create() - ..id = keyId - ..iteration = iteration - ..ciphertext = ciphertext; - final messageList = message.writeToBuffer(); - final signature = - _getSignature(signatureKey, ByteUtil.combine([version, messageList])); - _serialized = ByteUtil.combine([version, messageList, signature]); - _messageVersion = CiphertextMessage.currentVersion; - _keyId = keyId; - _iteration = iteration; - _ciphertext = ciphertext; - } - - SenderKeyMessage.fromSerialized(Uint8List serialized) { - final messageParts = ByteUtil.split(serialized, 1, - serialized.length - 1 - signatureLength, signatureLength); - final version = messageParts[0][0]; - final message = messageParts[1]; - // ignore: unused_local_variable - final signature = messageParts[2]; - - if (ByteUtil.highBitsToInt(version) < 3) { - throw LegacyMessageException( - 'Legacy message: ${ByteUtil.highBitsToInt(version)}'); - } - - if (ByteUtil.highBitsToInt(version) > CiphertextMessage.currentVersion) { - throw InvalidMessageException( - 'Unknown version: ${ByteUtil.highBitsToInt(version)}'); - } - - final senderKeyMessage = protocol.SenderKeyMessage.fromBuffer(message); - - if (!senderKeyMessage.hasId() || - !senderKeyMessage.hasIteration() || - !senderKeyMessage.hasCiphertext()) { - throw InvalidMessageException('Incomplete message.'); - } - - _serialized = serialized; - _messageVersion = ByteUtil.highBitsToInt(version); - _keyId = senderKeyMessage.id; - _iteration = senderKeyMessage.iteration; - _ciphertext = Uint8List.fromList(senderKeyMessage.ciphertext); - } - - static const int signatureLength = 64; - - // ignore: unused_field - late int _messageVersion; - late int _keyId; - late int _iteration; - late Uint8List _ciphertext; - late Uint8List _serialized; - - Uint8List _getSignature(ECPrivateKey signatureKey, Uint8List serialized) { - try { - return Curve.calculateSignature(signatureKey, serialized); - } on InvalidKeyIdException catch (e) { - throw AssertionError(e); - } - } - - int get keyId => _keyId; - - int get iteration => _iteration; - - Uint8List get ciphertext => _ciphertext; - - void verifySignature(ECPublicKey signatureKey) { - try { - final parts = ByteUtil.splitTwo( - _serialized, _serialized.length - signatureLength, signatureLength); - if (!Curve.verifySignature(signatureKey, parts[0], parts[1])) { - throw InvalidMessageException('Invalid signature!'); - } - } on InvalidKeyException catch (e) { - throw InvalidMessageException(e.detailMessage); - } - } - - @override - int getType() => CiphertextMessage.senderKeyType; - - @override - Uint8List serialize() => _serialized; -} diff --git a/libsignal_protocol_dart/lib/src/protocol/signal_message.dart b/libsignal_protocol_dart/lib/src/protocol/signal_message.dart deleted file mode 100644 index dd526ea..0000000 --- a/libsignal_protocol_dart/lib/src/protocol/signal_message.dart +++ /dev/null @@ -1,141 +0,0 @@ -import 'dart:typed_data'; - -import 'package:convert/convert.dart'; -import 'package:crypto/crypto.dart'; -import 'package:protobuf/protobuf.dart'; - -import '../ecc/curve.dart'; -import '../ecc/ec_public_key.dart'; -import '../identity_key.dart'; -import '../invalid_key_exception.dart'; -import '../invalid_message_exception.dart'; -import '../legacy_message_exception.dart'; -import '../protocol/ciphertext_message.dart'; -import '../state/whisper_text_protocol.pb.dart' as signal_protos; -import '../util/byte_util.dart'; - -class SignalMessage extends CiphertextMessage { - SignalMessage( - int messageVersion, - Uint8List macKey, - ECPublicKey senderRatchetKey, - int counter, - int previousCounter, - Uint8List ciphertext, - IdentityKey senderIdentityKey, - IdentityKey? receiverIdentityKey) { - final version = Uint8List.fromList([ - ByteUtil.intsToByteHighAndLow( - messageVersion, CiphertextMessage.currentVersion) - ]); - - final m = signal_protos.SignalMessage.create() - ..ratchetKey = senderRatchetKey.serialize() - ..counter = counter - ..previousCounter = previousCounter - ..ciphertext = ciphertext; - final message = m.writeToBuffer(); - - final mac = _getMac(senderIdentityKey, receiverIdentityKey!, macKey, - ByteUtil.combine([version, message])); - - _serialized = ByteUtil.combine([version, message, mac]); - _senderRatchetKey = senderRatchetKey; - _counter = counter; - _previousCounter = previousCounter; - _ciphertext = ciphertext; - _messageVersion = messageVersion; - } - - SignalMessage.fromSerialized(Uint8List serialized) { - try { - final messageParts = ByteUtil.split( - serialized, 1, serialized.length - 1 - macLength, macLength); - final version = messageParts[0].first; - final message = messageParts[1]; - // ignore: unused_local_variable - final mac = messageParts[2]; - - if (ByteUtil.highBitsToInt(version) < CiphertextMessage.currentVersion) { - throw LegacyMessageException( - 'Legacy message: $ByteUtil.highBitsToInt(version)'); - } - - if (ByteUtil.highBitsToInt(version) > CiphertextMessage.currentVersion) { - throw InvalidMessageException( - 'Unknown version: $ByteUtil.highBitsToInt(version)'); - } - - final whisperMessage = signal_protos.SignalMessage.fromBuffer(message); - - if (!whisperMessage.hasCiphertext() || - !whisperMessage.hasCounter() || - !whisperMessage.hasRatchetKey()) { - throw InvalidMessageException('Incomplete message.'); - } - - _serialized = serialized; - _senderRatchetKey = - Curve.decodePoint(Uint8List.fromList(whisperMessage.ratchetKey), 0); - _messageVersion = ByteUtil.highBitsToInt(version); - _counter = whisperMessage.counter; - _previousCounter = whisperMessage.previousCounter; - _ciphertext = Uint8List.fromList(whisperMessage.ciphertext); - } on InvalidProtocolBufferException catch (e) { - throw InvalidMessageException(e.toString()); - } on InvalidKeyException catch (e) { - throw InvalidMessageException(e.detailMessage); - } - } - - static const int macLength = 8; - - late int _messageVersion; - late ECPublicKey _senderRatchetKey; - late int _counter; - // ignore: unused_field - late int _previousCounter; - late Uint8List _ciphertext; - late Uint8List _serialized; - - ECPublicKey getSenderRatchetKey() => _senderRatchetKey; - - int getMessageVersion() => _messageVersion; - - int getCounter() => _counter; - - Uint8List getBody() => _ciphertext; - - void verifyMac(IdentityKey senderIdentityKey, IdentityKey receiverIdentityKey, - Uint8List macKey) { - final parts = ByteUtil.splitTwo( - _serialized, _serialized.length - macLength, macLength); - final ourMac = - _getMac(senderIdentityKey, receiverIdentityKey, macKey, parts[0]); - final theirMac = parts[1]; - - if (Digest(ourMac) != Digest(theirMac)) { - throw InvalidMessageException('Bad Mac!'); - } - } - - Uint8List _getMac(IdentityKey senderIdentityKey, - IdentityKey receiverIdentityKey, Uint8List macKey, Uint8List serialized) { - final mac = Hmac(sha256, macKey); // HMAC-SHA256 - - final output = AccumulatorSink(); - mac.startChunkedConversion(output) - ..add(senderIdentityKey.publicKey.serialize()) - ..add(receiverIdentityKey.publicKey.serialize()) - ..add(serialized) - ..close(); - final fullMac = Uint8List.fromList(output.events.single.bytes); - return ByteUtil.trim(fullMac, macLength); - } - - @override - int getType() => CiphertextMessage.whisperType; - - @override - Uint8List serialize() => _serialized; -} diff --git a/libsignal_protocol_dart/lib/src/provisioning_cipher.dart b/libsignal_protocol_dart/lib/src/provisioning_cipher.dart deleted file mode 100644 index cee0141..0000000 --- a/libsignal_protocol_dart/lib/src/provisioning_cipher.dart +++ /dev/null @@ -1,109 +0,0 @@ -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:crypto/crypto.dart'; - -import 'cbc.dart'; -import 'ecc/curve.dart'; -import 'ecc/ec_public_key.dart'; -import 'eq.dart'; -import 'invalid_mac_exception.dart'; -import 'kdf/derived_root_secrets.dart'; -import 'kdf/hkdfv3.dart'; -import 'legacy_message_exception.dart'; -import 'util/byte_util.dart'; - -const String provision = 'Mixin Provisioning Message'; - -class ProvisionEnvelope { - ProvisionEnvelope(this.publicKey, this.body); - - ProvisionEnvelope.fromJson(Map json) - : publicKey = base64Decode(json['public_key'] as String), - body = base64Decode(json['body'] as String); - - final Uint8List publicKey; - final Uint8List body; - - Map toJson() => { - 'public_key': base64Encode(publicKey), - 'body': base64Encode(body), - }; -} - -Uint8List decrypt(String privateKey, String content) { - final ourPrivateKey = base64Decode(privateKey); - final envelopeDecode = base64Decode(content); - - final map = jsonDecode(String.fromCharCodes(envelopeDecode)); - final provisionEnvelope = - ProvisionEnvelope.fromJson(map as Map); - final publicKeyable = Curve.decodePoint(provisionEnvelope.publicKey, 0); - final message = provisionEnvelope.body; - if (message[0] != 1) { - throw LegacyMessageException('Invalid version'); - } - final iv = Uint8List.fromList(message.getRange(1, 16 + 1).toList()); - final mac = message.getRange(message.length - 32, message.length).toList(); - final ivAndCiphertext = - Uint8List.fromList(message.getRange(0, message.length - 32).toList()); - final cipherText = Uint8List.fromList( - message.getRange(16 + 1, message.length - 32).toList()); - final sharedSecret = Curve.calculateAgreement( - publicKeyable, Curve.decodePrivatePoint(ourPrivateKey)); - - final derivedSecretBytes = HKDFv3().deriveSecrets(sharedSecret, - Uint8List.fromList(utf8.encode(provision)), DerivedRootSecrets.size); - - final aesKey = - Uint8List.fromList(derivedSecretBytes.getRange(0, 32).toList()); - final macKey = Uint8List.fromList( - derivedSecretBytes.getRange(32, derivedSecretBytes.length).toList()); - - if (!verifyMAC(macKey, ivAndCiphertext, mac)) { - throw InvalidMacException("MAC doesn't match!"); - } - final plaintext = aesCbcDecrypt(aesKey, iv, cipherText); - return plaintext; -} - -bool verifyMAC(Uint8List key, Uint8List input, List mac) { - final hmacSha256 = Hmac(sha256, key); - final digest = hmacSha256.convert(input); - return eq(digest.bytes, mac); -} - -class ProvisioningCipher { - ProvisioningCipher(this._theirPublicKey); - - final ECPublicKey _theirPublicKey; - - Uint8List encrypt(Uint8List message) { - final ourKeyPair = Curve.generateKeyPair(); - final sharedSecret = - Curve.calculateAgreement(_theirPublicKey, ourKeyPair.privateKey); - final derivedSecret = HKDFv3().deriveSecrets( - sharedSecret, Uint8List.fromList(utf8.encode(provision)), 64); - final parts = ByteUtil.splitTwo(derivedSecret, 32, 32); - - final version = Uint8List.fromList([1]); - final ciphertext = getCiphertext(parts[0], message); - final mac = _getMac(parts[1], ByteUtil.combine([version, ciphertext])); - final body = ByteUtil.combine([version, ciphertext, mac]); - final envelope = ProvisionEnvelope(ourKeyPair.publicKey.serialize(), body); - final result = jsonEncode(envelope); - return Uint8List.fromList(utf8.encode(result)); - } - - Uint8List getCiphertext(Uint8List key, Uint8List message) { - final iv = Uint8List(16); - final m = aesCbcEncrypt(key, iv, message); - return Uint8List.fromList(iv + m); - } - - Uint8List _getMac(Uint8List key, Uint8List message) { - final hmacSha256 = Hmac(sha256, key); - final digest = hmacSha256.convert(message); - return Uint8List.fromList(digest.bytes); - } -} diff --git a/libsignal_protocol_dart/lib/src/ratchet/alice_signal_protocol_parameters.dart b/libsignal_protocol_dart/lib/src/ratchet/alice_signal_protocol_parameters.dart deleted file mode 100644 index 2ef531b..0000000 --- a/libsignal_protocol_dart/lib/src/ratchet/alice_signal_protocol_parameters.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:optional/optional.dart'; - -import '../ecc/ec_key_pair.dart'; -import '../ecc/ec_public_key.dart'; -import '../identity_key.dart'; -import '../identity_key_pair.dart'; - -class AliceSignalProtocolParameters { - AliceSignalProtocolParameters({ - required this.ourIdentityKey, - required this.ourBaseKey, - required this.theirIdentityKey, - required this.theirSignedPreKey, - required this.theirRatchetKey, - required this.theirOneTimePreKey, - }); - - final IdentityKeyPair ourIdentityKey; - final ECKeyPair ourBaseKey; - - final IdentityKey theirIdentityKey; - final ECPublicKey theirSignedPreKey; - final Optional theirOneTimePreKey; - final ECPublicKey theirRatchetKey; -} diff --git a/libsignal_protocol_dart/lib/src/ratchet/bob_signal_protocol_parameters.dart b/libsignal_protocol_dart/lib/src/ratchet/bob_signal_protocol_parameters.dart deleted file mode 100644 index 2ccb165..0000000 --- a/libsignal_protocol_dart/lib/src/ratchet/bob_signal_protocol_parameters.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'package:optional/optional.dart'; - -import '../ecc/ec_key_pair.dart'; -import '../ecc/ec_public_key.dart'; -import '../identity_key.dart'; -import '../identity_key_pair.dart'; - -class BobSignalProtocolParameters { - BobSignalProtocolParameters({ - required this.ourIdentityKey, - required this.ourSignedPreKey, - required this.ourRatchetKey, - required this.ourOneTimePreKey, - required this.theirIdentityKey, - required this.theirBaseKey, - }); - - final IdentityKeyPair ourIdentityKey; - final ECKeyPair ourSignedPreKey; - final Optional ourOneTimePreKey; - final ECKeyPair ourRatchetKey; - - final IdentityKey theirIdentityKey; - final ECPublicKey theirBaseKey; - - IdentityKeyPair getOurIdentityKey() => ourIdentityKey; - - ECKeyPair getOurSignedPreKey() => ourSignedPreKey; - - Optional getOurOneTimePreKey() => ourOneTimePreKey; - - IdentityKey getTheirIdentityKey() => theirIdentityKey; - - ECPublicKey getTheirBaseKey() => theirBaseKey; - - ECKeyPair getOurRatchetKey() => ourRatchetKey; -} diff --git a/libsignal_protocol_dart/lib/src/ratchet/chain_key.dart b/libsignal_protocol_dart/lib/src/ratchet/chain_key.dart deleted file mode 100644 index 9fc1186..0000000 --- a/libsignal_protocol_dart/lib/src/ratchet/chain_key.dart +++ /dev/null @@ -1,46 +0,0 @@ -import 'dart:convert'; -import 'dart:core'; -import 'dart:typed_data'; - -import 'package:crypto/crypto.dart'; -import '../kdf/derived_message_secrets.dart'; -import '../kdf/hkdf.dart'; -import '../ratchet/message_keys.dart'; - -class ChainKey { - ChainKey(this._kdf, this._key, this._index); - - static final Uint8List messageKeySeed = Uint8List.fromList([0x01]); - static final Uint8List chainKeySeed = Uint8List.fromList([0x02]); - - final HKDF _kdf; - final Uint8List _key; - final int _index; - - Uint8List get key => _key; - - int get index => _index; - - ChainKey getNextChainKey() { - final nextKey = _getBaseMaterial(chainKeySeed); - return ChainKey(_kdf, nextKey, _index + 1); - } - - MessageKeys getMessageKeys() { - final bytes = Uint8List.fromList(utf8.encode('WhisperMessageKeys')); - - final inputKeyMaterial = _getBaseMaterial(messageKeySeed); - final keyMaterialBytes = - _kdf.deriveSecrets(inputKeyMaterial, bytes, DerivedMessageSecrets.size); - final keyMaterial = DerivedMessageSecrets(keyMaterialBytes); - - return MessageKeys(keyMaterial.getCipherKey(), keyMaterial.getMacKey(), - keyMaterial.getIv(), _index); - } - - Uint8List _getBaseMaterial(Uint8List seed) { - final hmacSha256 = Hmac(sha256, _key); - final digest = hmacSha256.convert(seed); - return Uint8List.fromList(digest.bytes); - } -} diff --git a/libsignal_protocol_dart/lib/src/ratchet/message_keys.dart b/libsignal_protocol_dart/lib/src/ratchet/message_keys.dart deleted file mode 100644 index 8c0d1e1..0000000 --- a/libsignal_protocol_dart/lib/src/ratchet/message_keys.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'dart:typed_data'; - -class MessageKeys { - MessageKeys(this.cipherKey, this.macKey, this.iv, this.counter); - - final Uint8List cipherKey; - final Uint8List macKey; - final Uint8List iv; - final int counter; - - Uint8List getCipherKey() => cipherKey; - - Uint8List getMacKey() => macKey; - - Uint8List getIv() => iv; - - int getCounter() => counter; -} diff --git a/libsignal_protocol_dart/lib/src/ratchet/ratcheting_session.dart b/libsignal_protocol_dart/lib/src/ratchet/ratcheting_session.dart deleted file mode 100644 index 3b97872..0000000 --- a/libsignal_protocol_dart/lib/src/ratchet/ratcheting_session.dart +++ /dev/null @@ -1,151 +0,0 @@ -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:optional/optional.dart'; - -import '../ecc/curve.dart'; -import '../ecc/ec_key_pair.dart'; -import '../ecc/ec_public_key.dart'; -import '../kdf/hkdf.dart'; -import '../kdf/hkdfv3.dart'; -import '../protocol/ciphertext_message.dart'; -import '../ratchet/alice_signal_protocol_parameters.dart'; -import '../ratchet/bob_signal_protocol_parameters.dart'; -import '../ratchet/chain_key.dart'; -import '../ratchet/root_key.dart'; -import '../ratchet/symmetric_signal_protocol_parameters.dart'; -import '../state/session_state.dart'; -import '../util/byte_util.dart'; - -class RatchetingSession { - static void initializeSession( - SessionState sessionState, SymmetricSignalProtocolParameters parameters) { - if (isAlice(parameters.ourBaseKey.publicKey, parameters.theirBaseKey)) { - final aliceParameters = AliceSignalProtocolParameters( - ourBaseKey: parameters.ourBaseKey, - ourIdentityKey: parameters.ourIdentityKey, - theirRatchetKey: parameters.theirRatchetKey, - theirIdentityKey: parameters.theirIdentityKey, - theirSignedPreKey: parameters.theirBaseKey, - theirOneTimePreKey: const Optional.empty(), - ); - RatchetingSession.initializeSessionAlice(sessionState, aliceParameters); - } else { - final bobParameters = BobSignalProtocolParameters( - ourIdentityKey: parameters.ourIdentityKey, - ourRatchetKey: parameters.ourRatchetKey, - ourSignedPreKey: parameters.ourBaseKey, - ourOneTimePreKey: const Optional.empty(), - theirBaseKey: parameters.theirBaseKey, - theirIdentityKey: parameters.theirIdentityKey, - ); - - RatchetingSession.initializeSessionBob(sessionState, bobParameters); - } - } - - static void initializeSessionAlice( - SessionState sessionState, AliceSignalProtocolParameters parameters) { - try { - sessionState - ..sessionVersion = CiphertextMessage.currentVersion - ..remoteIdentityKey = parameters.theirIdentityKey - ..localIdentityKey = parameters.ourIdentityKey.getPublicKey(); - - final sendingRatchetKey = Curve.generateKeyPair(); - final secrets = [ - ...getDiscontinuityBytes(), - ...Curve.calculateAgreement(parameters.theirSignedPreKey, - parameters.ourIdentityKey.getPrivateKey()), - ...Curve.calculateAgreement(parameters.theirIdentityKey.publicKey, - parameters.ourBaseKey.privateKey), - ...Curve.calculateAgreement( - parameters.theirSignedPreKey, parameters.ourBaseKey.privateKey) - ]; - - if (parameters.theirOneTimePreKey.isPresent) { - secrets.addAll(Curve.calculateAgreement( - parameters.theirOneTimePreKey.value, - parameters.ourBaseKey.privateKey)); - } - - final derivedKeys = calculateDerivedKeys(Uint8List.fromList(secrets)); - final sendingChain = derivedKeys - .getRootKey() - .createChain(parameters.theirRatchetKey, sendingRatchetKey); - - sessionState - ..addReceiverChain( - parameters.theirRatchetKey, derivedKeys.getChainKey()) - ..setSenderChain(sendingRatchetKey, sendingChain.$2) - ..rootKey = sendingChain.$1; - } on Exception catch (e) { - throw AssertionError(e); - } - } - - static void initializeSessionBob( - SessionState sessionState, BobSignalProtocolParameters parameters) { - try { - sessionState - ..sessionVersion = CiphertextMessage.currentVersion - ..remoteIdentityKey = parameters.theirIdentityKey - ..localIdentityKey = parameters.ourIdentityKey.getPublicKey(); - - final secrets = [ - ...getDiscontinuityBytes(), - ...Curve.calculateAgreement(parameters.theirIdentityKey.publicKey, - parameters.ourSignedPreKey.privateKey), - ...Curve.calculateAgreement( - parameters.theirBaseKey, parameters.ourIdentityKey.getPrivateKey()), - ...Curve.calculateAgreement( - parameters.theirBaseKey, parameters.ourSignedPreKey.privateKey) - ]; - if (parameters.ourOneTimePreKey.isPresent) { - secrets.addAll(Curve.calculateAgreement(parameters.theirBaseKey, - parameters.ourOneTimePreKey.value.privateKey)); - } - - final derivedKeys = calculateDerivedKeys(Uint8List.fromList(secrets)); - - sessionState - ..setSenderChain(parameters.ourRatchetKey, derivedKeys.getChainKey()) - ..rootKey = derivedKeys.getRootKey(); - } on Exception catch (e) { - throw AssertionError(e); - } - } - - static Uint8List getDiscontinuityBytes() { - final discontinuity = Uint8List(32); - final len = discontinuity.length; - for (var i = 0; i < len; i++) { - discontinuity[i] = 0xFF; - } - return discontinuity; - } - - static DerivedKeys calculateDerivedKeys(Uint8List masterSecret) { - final HKDF kdf = HKDFv3(); - final bytes = Uint8List.fromList(utf8.encode('WhisperText')); - final derivedSecretBytes = kdf.deriveSecrets(masterSecret, bytes, 64); - final derivedSecrets = ByteUtil.splitTwo(derivedSecretBytes, 32, 32); - - return DerivedKeys( - RootKey(kdf, derivedSecrets[0]), ChainKey(kdf, derivedSecrets[1], 0)); - } - - static bool isAlice(ECPublicKey ourKey, ECPublicKey theirKey) => - ourKey.compareTo(theirKey) < 0; -} - -class DerivedKeys { - DerivedKeys(this._rootKey, this._chainKey); - - final RootKey _rootKey; - final ChainKey _chainKey; - - RootKey getRootKey() => _rootKey; - - ChainKey getChainKey() => _chainKey; -} diff --git a/libsignal_protocol_dart/lib/src/ratchet/root_key.dart b/libsignal_protocol_dart/lib/src/ratchet/root_key.dart deleted file mode 100644 index 9fcd1cd..0000000 --- a/libsignal_protocol_dart/lib/src/ratchet/root_key.dart +++ /dev/null @@ -1,33 +0,0 @@ -import 'dart:convert'; -import 'dart:typed_data'; - -import '../ecc/curve.dart'; -import '../ecc/ec_key_pair.dart'; -import '../ecc/ec_public_key.dart'; -import '../kdf/derived_root_secrets.dart'; -import '../kdf/hkdf.dart'; -import '../ratchet/chain_key.dart'; - -class RootKey { - RootKey(this._kdf, this._key); - - final HKDF _kdf; - final Uint8List _key; - - Uint8List getKeyBytes() => _key; - - (RootKey, ChainKey) createChain( - ECPublicKey theirRatchetKey, ECKeyPair ourRatchetKey) { - final sharedSecret = - Curve.calculateAgreement(theirRatchetKey, ourRatchetKey.privateKey); - final bytes = Uint8List.fromList(utf8.encode('WhisperRatchet')); - final derivedSecretBytes = - _kdf.deriveSecrets4(sharedSecret, _key, bytes, DerivedRootSecrets.size); - final derivedSecrets = DerivedRootSecrets(derivedSecretBytes); - - final newRootKey = RootKey(_kdf, derivedSecrets.getRootKey()); - final newChainKey = ChainKey(_kdf, derivedSecrets.getChainKey(), 0); - - return (newRootKey, newChainKey); - } -} diff --git a/libsignal_protocol_dart/lib/src/ratchet/symmetric_signal_protocol_parameters.dart b/libsignal_protocol_dart/lib/src/ratchet/symmetric_signal_protocol_parameters.dart deleted file mode 100644 index d90703b..0000000 --- a/libsignal_protocol_dart/lib/src/ratchet/symmetric_signal_protocol_parameters.dart +++ /dev/null @@ -1,23 +0,0 @@ -import '../ecc/ec_key_pair.dart'; -import '../ecc/ec_public_key.dart'; -import '../identity_key.dart'; -import '../identity_key_pair.dart'; - -class SymmetricSignalProtocolParameters { - SymmetricSignalProtocolParameters({ - required this.ourBaseKey, - required this.ourRatchetKey, - required this.ourIdentityKey, - required this.theirBaseKey, - required this.theirRatchetKey, - required this.theirIdentityKey, - }); - - final ECKeyPair ourBaseKey; - final ECKeyPair ourRatchetKey; - final IdentityKeyPair ourIdentityKey; - - final ECPublicKey theirBaseKey; - final ECPublicKey theirRatchetKey; - final IdentityKey theirIdentityKey; -} diff --git a/libsignal_protocol_dart/lib/src/session_builder.dart b/libsignal_protocol_dart/lib/src/session_builder.dart deleted file mode 100644 index b0ad558..0000000 --- a/libsignal_protocol_dart/lib/src/session_builder.dart +++ /dev/null @@ -1,156 +0,0 @@ -import 'package:optional/optional.dart'; - -import 'ecc/curve.dart'; -import 'ecc/ec_key_pair.dart'; -import 'invalid_key_exception.dart'; -import 'protocol/pre_key_signal_message.dart'; -import 'ratchet/alice_signal_protocol_parameters.dart'; -import 'ratchet/bob_signal_protocol_parameters.dart'; -import 'ratchet/ratcheting_session.dart'; -import 'signal_protocol_address.dart'; -import 'state/identity_key_store.dart'; -import 'state/pre_key_bundle.dart'; -import 'state/pre_key_store.dart'; -import 'state/session_record.dart'; -import 'state/session_store.dart'; -import 'state/signal_protocol_store.dart'; -import 'state/signed_pre_key_store.dart'; -import 'untrusted_identity_exception.dart'; -import 'util/log.dart' as $log; - -class SessionBuilder { - SessionBuilder(this._sessionStore, this._preKeyStore, this._signedPreKeyStore, - this._identityKeyStore, this._remoteAddress); - - SessionBuilder.fromSignalStore( - SignalProtocolStore store, SignalProtocolAddress remoteAddress) - : this(store, store, store, store, remoteAddress); - - static const String tag = 'SessionBuilder'; - - SessionStore _sessionStore; - PreKeyStore _preKeyStore; - SignedPreKeyStore _signedPreKeyStore; - IdentityKeyStore _identityKeyStore; - SignalProtocolAddress _remoteAddress; - - Future> process( - SessionRecord sessionRecord, PreKeySignalMessage message) async { - final theirIdentityKey = message.getIdentityKey(); - - if (!await _identityKeyStore.isTrustedIdentity( - _remoteAddress, theirIdentityKey, Direction.receiving)) { - throw UntrustedIdentityException( - _remoteAddress.getName(), theirIdentityKey); - } - - final unsignedPreKeyId = processV3(sessionRecord, message); - - await _identityKeyStore.saveIdentity(_remoteAddress, theirIdentityKey); - - return unsignedPreKeyId; - } - - Future> processV3( - SessionRecord sessionRecord, PreKeySignalMessage message) async { - if (sessionRecord.hasSessionState( - message.getMessageVersion(), message.getBaseKey().serialize())) { - $log.log( - "We've already setup a session for this V3 message, letting bundled message fall through..."); - return const Optional.empty(); - } - - final ourSignedPreKey = _signedPreKeyStore - .loadSignedPreKey(message.getSignedPreKeyId()) - .then((value) => value.getKeyPair()); - - late final Optional ourOneTimePreKey; - if (message.getPreKeyId().isPresent) { - ourOneTimePreKey = Optional.of(await _preKeyStore - .loadPreKey(message.getPreKeyId().value) - .then((value) => value.getKeyPair())); - } else { - ourOneTimePreKey = const Optional.empty(); - } - - if (!sessionRecord.isFresh()) sessionRecord.archiveCurrentState(); - - final parameters = BobSignalProtocolParameters( - theirBaseKey: message.getBaseKey(), - theirIdentityKey: message.getIdentityKey(), - ourIdentityKey: await _identityKeyStore.getIdentityKeyPair(), - ourSignedPreKey: await ourSignedPreKey, - ourRatchetKey: await ourSignedPreKey, - ourOneTimePreKey: ourOneTimePreKey, - ); - - RatchetingSession.initializeSessionBob( - sessionRecord.sessionState, parameters); - - sessionRecord.sessionState.localRegistrationId = - await _identityKeyStore.getLocalRegistrationId(); - sessionRecord.sessionState.remoteRegistrationId = - message.getRegistrationId(); - sessionRecord.sessionState.aliceBaseKey = message.getBaseKey().serialize(); - - if (message.getPreKeyId().isPresent) { - return message.getPreKeyId(); - } else { - return const Optional.empty(); - } - } - - Future processPreKeyBundle(PreKeyBundle preKey) async { - if (!await _identityKeyStore.isTrustedIdentity( - _remoteAddress, preKey.getIdentityKey(), Direction.sending)) { - throw UntrustedIdentityException( - _remoteAddress.getName(), preKey.getIdentityKey()); - } - - if (preKey.getSignedPreKey() != null && - !Curve.verifySignature( - preKey.getIdentityKey().publicKey, - preKey.getSignedPreKey()!.serialize(), - preKey.getSignedPreKeySignature())) { - throw InvalidKeyException('Invalid signature on device key!'); - } - - if (preKey.getSignedPreKey() == null) { - throw InvalidKeyException('No signed prekey!'); - } - - final sessionRecord = await _sessionStore.loadSession(_remoteAddress); - final ourBaseKey = Curve.generateKeyPair(); - final theirSignedPreKey = preKey.getSignedPreKey(); - final theirOneTimePreKey = Optional.ofNullable(preKey.getPreKey()); - final theirOneTimePreKeyId = theirOneTimePreKey.isPresent - ? Optional.ofNullable(preKey.getPreKeyId()) - : const Optional.empty(); - - final parameters = AliceSignalProtocolParameters( - ourBaseKey: ourBaseKey, - ourIdentityKey: await _identityKeyStore.getIdentityKeyPair(), - theirIdentityKey: preKey.getIdentityKey(), - theirSignedPreKey: theirSignedPreKey!, - theirRatchetKey: theirSignedPreKey, - theirOneTimePreKey: theirOneTimePreKey, - ); - - if (!sessionRecord.isFresh()) sessionRecord.archiveCurrentState(); - - RatchetingSession.initializeSessionAlice( - sessionRecord.sessionState, parameters); - - sessionRecord.sessionState.setUnacknowledgedPreKeyMessage( - theirOneTimePreKeyId, preKey.getSignedPreKeyId(), ourBaseKey.publicKey); - sessionRecord.sessionState.localRegistrationId = - await _identityKeyStore.getLocalRegistrationId(); - sessionRecord.sessionState.remoteRegistrationId = - preKey.getRegistrationId(); - sessionRecord.sessionState.aliceBaseKey = ourBaseKey.publicKey.serialize(); - - await _identityKeyStore.saveIdentity( - _remoteAddress, preKey.getIdentityKey()); - await _sessionStore.storeSession(_remoteAddress, sessionRecord); - } -} diff --git a/libsignal_protocol_dart/lib/src/session_cipher.dart b/libsignal_protocol_dart/lib/src/session_cipher.dart deleted file mode 100644 index 7a0fd37..0000000 --- a/libsignal_protocol_dart/lib/src/session_cipher.dart +++ /dev/null @@ -1,290 +0,0 @@ -import 'dart:collection'; -import 'dart:core'; -import 'dart:math'; -import 'dart:typed_data'; - -import 'cbc.dart'; -import 'decryption_callback.dart'; -import 'duplicate_message_exception.dart'; -import 'ecc/curve.dart'; -import 'ecc/ec_public_key.dart'; -import 'invalid_key_exception.dart'; -import 'invalid_message_exception.dart'; -import 'no_session_exception.dart'; -import 'protocol/ciphertext_message.dart'; -import 'protocol/pre_key_signal_message.dart'; -import 'protocol/signal_message.dart'; -import 'ratchet/chain_key.dart'; -import 'ratchet/message_keys.dart'; -import 'session_builder.dart'; -import 'signal_protocol_address.dart'; -import 'state/identity_key_store.dart'; -import 'state/pre_key_store.dart'; -import 'state/session_record.dart'; -import 'state/session_state.dart'; -import 'state/session_store.dart'; -import 'state/signal_protocol_store.dart'; -import 'state/signed_pre_key_store.dart'; -import 'untrusted_identity_exception.dart'; - -class SessionCipher { - SessionCipher( - this._sessionStore, - this._preKeyStore, - SignedPreKeyStore signedPreKeyStore, - this._identityKeyStore, - this._remoteAddress) { - _sessionBuilder = SessionBuilder(_sessionStore, _preKeyStore, - signedPreKeyStore, _identityKeyStore, _remoteAddress); - } - - SessionCipher.fromStore( - SignalProtocolStore store, SignalProtocolAddress remoteAddress) - : this(store, store, store, store, remoteAddress); - - static final Object sessionLock = Object(); - - SessionStore _sessionStore; - IdentityKeyStore _identityKeyStore; - late SessionBuilder _sessionBuilder; - PreKeyStore _preKeyStore; - SignalProtocolAddress _remoteAddress; - - Future encrypt(Uint8List paddedMessage) async { - final sessionRecord = await _sessionStore.loadSession(_remoteAddress); - final sessionState = sessionRecord.sessionState; - final chainKey = sessionState.getSenderChainKey(); - final messageKeys = chainKey.getMessageKeys(); - final senderEphemeral = sessionState.getSenderRatchetKey(); - final previousCounter = sessionState.previousCounter; - final sessionVersion = sessionState.getSessionVersion(); - - final ciphertextBody = getCiphertext(messageKeys, paddedMessage); - CiphertextMessage ciphertextMessage = SignalMessage( - sessionVersion, - messageKeys.getMacKey(), - senderEphemeral, - chainKey.index, - previousCounter, - ciphertextBody, - sessionState.getLocalIdentityKey(), - sessionState.getRemoteIdentityKey()); - if (sessionState.hasUnacknowledgedPreKeyMessage()) { - final items = sessionState.getUnacknowledgedPreKeyMessageItems(); - final localRegistrationId = sessionState.localRegistrationId; - - ciphertextMessage = PreKeySignalMessage.from( - sessionVersion, - localRegistrationId, - items.getPreKeyId(), - items.getSignedPreKeyId(), - items.getBaseKey(), - sessionState.getLocalIdentityKey(), - ciphertextMessage as SignalMessage); - } - - final nextChainKey = chainKey.getNextChainKey(); - sessionState.setSenderChainKey(nextChainKey); - - if (!await _identityKeyStore.isTrustedIdentity(_remoteAddress, - sessionState.getRemoteIdentityKey(), Direction.sending)) { - throw UntrustedIdentityException( - _remoteAddress.getName(), sessionState.getRemoteIdentityKey()); - } - - await _identityKeyStore.saveIdentity( - _remoteAddress, sessionState.getRemoteIdentityKey()); - await _sessionStore.storeSession(_remoteAddress, sessionRecord); - return ciphertextMessage; - } - - Future decrypt(PreKeySignalMessage ciphertext) async => - decryptWithCallback(ciphertext, () {}()); - - Future decryptWithCallback( - PreKeySignalMessage ciphertext, DecryptionCallback? callback) async { - final sessionRecord = await _sessionStore.loadSession(_remoteAddress); - final unsignedPreKeyId = - await _sessionBuilder.process(sessionRecord, ciphertext); - final plaintext = _decrypt(sessionRecord, ciphertext.getWhisperMessage()); - - if (callback != null) { - callback(plaintext); - } - - await _sessionStore.storeSession(_remoteAddress, sessionRecord); - - if (unsignedPreKeyId.isPresent) { - await _preKeyStore.removePreKey(unsignedPreKeyId.value); - } - - return plaintext; - } - - Future decryptFromSignal(SignalMessage cipherText) async => - decryptFromSignalWithCallback(cipherText, () {}()); - - Future decryptFromSignalWithCallback( - SignalMessage cipherText, DecryptionCallback? callback) async { - if (!await _sessionStore.containsSession(_remoteAddress)) { - throw NoSessionException('No session for: $_remoteAddress'); - } - - final sessionRecord = await _sessionStore.loadSession(_remoteAddress); - final plaintext = _decrypt(sessionRecord, cipherText); - - if (!await _identityKeyStore.isTrustedIdentity( - _remoteAddress, - sessionRecord.sessionState.getRemoteIdentityKey(), - Direction.receiving)) { - throw UntrustedIdentityException(_remoteAddress.getName(), - sessionRecord.sessionState.getRemoteIdentityKey()); - } - - await _identityKeyStore.saveIdentity( - _remoteAddress, sessionRecord.sessionState.getRemoteIdentityKey()); - - if (callback != null) { - callback(plaintext); - } - - await _sessionStore.storeSession(_remoteAddress, sessionRecord); - - return plaintext; - } - - Uint8List _decrypt(SessionRecord sessionRecord, SignalMessage cipherText) { - final previousStates = sessionRecord.previousSessionStates; - final exceptions = []; - - try { - final sessionState = - SessionState.fromSessionState(sessionRecord.sessionState); - final plaintext = _decryptFromState(sessionState, cipherText); - - sessionRecord.state = sessionState; - return plaintext; - } on InvalidMessageException catch (e) { - exceptions.add(e); - } - // ignore: deprecated_member_use - final pStates = HasNextIterator(previousStates.iterator); - while (pStates.hasNext) { - try { - final promotedState = SessionState.fromSessionState(pStates.next()); - final plaintext = _decryptFromState(promotedState, cipherText); - - previousStates.remove(promotedState); - sessionRecord.promoteState(promotedState); - - return plaintext; - } on InvalidMessageException catch (e) { - exceptions.add(e); - } - } - - throw InvalidMessageException('No valid sessions. $exceptions[0]'); - } - - Uint8List _decryptFromState( - SessionState sessionState, SignalMessage ciphertextMessage) { - if (!sessionState.hasSenderChain()) { - throw InvalidMessageException('Uninitialized session!'); - } - - if (ciphertextMessage.getMessageVersion() != - sessionState.getSessionVersion()) { - throw InvalidMessageException( - 'Message version $ciphertextMessage.getMessageVersion(), but session version $sessionState.getSessionVersion()'); - } - - final theirEphemeral = ciphertextMessage.getSenderRatchetKey(); - final counter = ciphertextMessage.getCounter(); - final chainKey = _getOrCreateChainKey(sessionState, theirEphemeral); - final messageKeys = _getOrCreateMessageKeys( - sessionState, theirEphemeral, chainKey!, counter); - - ciphertextMessage.verifyMac(sessionState.getRemoteIdentityKey()!, - sessionState.getLocalIdentityKey(), messageKeys!.getMacKey()); - - final plaintext = _getPlaintext(messageKeys, ciphertextMessage.getBody()); - - sessionState.clearUnacknowledgedPreKeyMessage(); - - return plaintext; - } - - Future getRemoteRegistrationId() async { - final record = await _sessionStore.loadSession(_remoteAddress); - return record.sessionState.remoteRegistrationId; - } - - Future getSessionVersion() async { - if (!await _sessionStore.containsSession(_remoteAddress)) { - // throw IllegalStateException("No session for ($_remoteAddress)!"); - } - - final record = await _sessionStore.loadSession(_remoteAddress); - return record.sessionState.getSessionVersion(); - } - - ChainKey? _getOrCreateChainKey( - SessionState sessionState, ECPublicKey theirEphemeral) { - try { - if (sessionState.hasReceiverChain(theirEphemeral)) { - return sessionState.getReceiverChainKey(theirEphemeral); - } else { - final rootKey = sessionState.getRootKey(); - final ourEphemeral = sessionState.getSenderRatchetKeyPair(); - final receiverChain = rootKey.createChain(theirEphemeral, ourEphemeral); - final ourNewEphemeral = Curve.generateKeyPair(); - final senderChain = - receiverChain.$1.createChain(theirEphemeral, ourNewEphemeral); - - sessionState - ..rootKey = senderChain.$1 - ..addReceiverChain(theirEphemeral, receiverChain.$2) - ..previousCounter = max(sessionState.getSenderChainKey().index - 1, 0) - ..setSenderChain(ourNewEphemeral, senderChain.$2); - - return receiverChain.$2; - } - } on InvalidKeyException { - rethrow; - } - } - - MessageKeys? _getOrCreateMessageKeys(SessionState sessionState, - ECPublicKey theirEphemeral, ChainKey chainKey, int counter) { - if (chainKey.index > counter) { - if (sessionState.hasMessageKeys(theirEphemeral, counter)) { - return sessionState.removeMessageKeys(theirEphemeral, counter); - } else { - throw DuplicateMessageException( - 'Received message with old counter: ${chainKey.index}, $counter'); - } - } - - if (counter - chainKey.index > 2000) { - throw InvalidMessageException('Over 2000 messages into the future!'); - } - - while (chainKey.index < counter) { - final messageKeys = chainKey.getMessageKeys(); - sessionState.setMessageKeys(theirEphemeral, messageKeys); - // ignore: parameter_assignments - chainKey = chainKey.getNextChainKey(); - } - - sessionState.setReceiverChainKey( - theirEphemeral, chainKey.getNextChainKey()); - return chainKey.getMessageKeys(); - } - - Uint8List getCiphertext(MessageKeys messageKeys, Uint8List plaintext) => - aesCbcEncrypt(messageKeys.getCipherKey(), messageKeys.getIv(), plaintext); - - Uint8List _getPlaintext(MessageKeys messageKeys, Uint8List cipherText) => - aesCbcDecrypt( - messageKeys.getCipherKey(), messageKeys.getIv(), cipherText); -} diff --git a/libsignal_protocol_dart/lib/src/signal_protocol_address.dart b/libsignal_protocol_dart/lib/src/signal_protocol_address.dart deleted file mode 100644 index f0dd6e9..0000000 --- a/libsignal_protocol_dart/lib/src/signal_protocol_address.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:meta/meta.dart'; - -@immutable -class SignalProtocolAddress { - const SignalProtocolAddress(this._name, this._deviceId); - - final String _name; - final int _deviceId; - - String getName() => _name; - - int getDeviceId() => _deviceId; - - @override - String toString() => '$_name:$_deviceId'; - - @override - bool operator ==(Object other) { - if (other is! SignalProtocolAddress) return false; - - return _name == other._name && _deviceId == other._deviceId; - } - - @override - int get hashCode => _name.hashCode ^ _deviceId; -} diff --git a/libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pb.dart b/libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pb.dart deleted file mode 100644 index cf629d8..0000000 --- a/libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pb.dart +++ /dev/null @@ -1,219 +0,0 @@ -import 'dart:core' as $core; -import 'dart:core'; - -import 'package:protobuf/protobuf.dart' as $pb; - -class LogicalFingerprint extends $pb.GeneratedMessage { - factory LogicalFingerprint({ - $core.List<$core.int>? content, - }) { - final _result = create(); - if (content != null) { - _result.content = content; - } - return _result; - } - - LogicalFingerprint._() : super(); - - factory LogicalFingerprint.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory LogicalFingerprint.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'LogicalFingerprint', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.List<$core.int>>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'content', - $pb.PbFieldType.OY) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - LogicalFingerprint clone() => LogicalFingerprint()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - LogicalFingerprint copyWith(void Function(LogicalFingerprint) updates) => - super.copyWith((message) => updates(message as LogicalFingerprint)) - as LogicalFingerprint; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static LogicalFingerprint create() => LogicalFingerprint._(); - - @override - LogicalFingerprint createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static LogicalFingerprint getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static LogicalFingerprint? _defaultInstance; - - @$pb.TagNumber(1) - $core.List<$core.int> get content => $_getN(0); - - @$pb.TagNumber(1) - set content($core.List<$core.int> v) { - $_setBytes(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasContent() => $_has(0); - - @$pb.TagNumber(1) - void clearContent() => clearField(1); -} - -class CombinedFingerprints extends $pb.GeneratedMessage { - factory CombinedFingerprints({ - $core.int? version, - LogicalFingerprint? localFingerprint, - LogicalFingerprint? remoteFingerprint, - }) { - final _result = create(); - if (version != null) { - _result.version = version; - } - if (localFingerprint != null) { - _result.localFingerprint = localFingerprint; - } - if (remoteFingerprint != null) { - _result.remoteFingerprint = remoteFingerprint; - } - return _result; - } - - CombinedFingerprints._() : super(); - - factory CombinedFingerprints.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory CombinedFingerprints.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'CombinedFingerprints', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'version', - $pb.PbFieldType.OU3) - ..aOM( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'localFingerprint', - protoName: 'localFingerprint', - subBuilder: LogicalFingerprint.create) - ..aOM( - 3, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'remoteFingerprint', - protoName: 'remoteFingerprint', - subBuilder: LogicalFingerprint.create) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - CombinedFingerprints clone() => - CombinedFingerprints()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - CombinedFingerprints copyWith(void Function(CombinedFingerprints) updates) => - super.copyWith((message) => updates(message as CombinedFingerprints)) - as CombinedFingerprints; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static CombinedFingerprints create() => CombinedFingerprints._(); - - @override - CombinedFingerprints createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static CombinedFingerprints getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static CombinedFingerprints? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get version => $_getIZ(0); - - @$pb.TagNumber(1) - set version($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasVersion() => $_has(0); - - @$pb.TagNumber(1) - void clearVersion() => clearField(1); - - @$pb.TagNumber(2) - LogicalFingerprint get localFingerprint => $_getN(1); - - @$pb.TagNumber(2) - set localFingerprint(LogicalFingerprint v) { - setField(2, v); - } - - @$pb.TagNumber(2) - $core.bool hasLocalFingerprint() => $_has(1); - - @$pb.TagNumber(2) - void clearLocalFingerprint() => clearField(2); - - @$pb.TagNumber(2) - LogicalFingerprint ensureLocalFingerprint() => $_ensure(1); - - @$pb.TagNumber(3) - LogicalFingerprint get remoteFingerprint => $_getN(2); - - @$pb.TagNumber(3) - set remoteFingerprint(LogicalFingerprint v) { - setField(3, v); - } - - @$pb.TagNumber(3) - $core.bool hasRemoteFingerprint() => $_has(2); - - @$pb.TagNumber(3) - void clearRemoteFingerprint() => clearField(3); - - @$pb.TagNumber(3) - LogicalFingerprint ensureRemoteFingerprint() => $_ensure(2); -} diff --git a/libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pbenum.dart b/libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pbenum.dart deleted file mode 100644 index 2427c36..0000000 --- a/libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pbenum.dart +++ /dev/null @@ -1,5 +0,0 @@ -// Generated code. Do not modify. -// source: FingerprintProtocol.proto -// -// @dart = 2.12 -// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields diff --git a/libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pbjson.dart b/libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pbjson.dart deleted file mode 100644 index 0b868c8..0000000 --- a/libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pbjson.dart +++ /dev/null @@ -1,43 +0,0 @@ -import 'dart:convert' as $convert; -import 'dart:core' as $core; -import 'dart:typed_data' as $typed_data; - -@$core.Deprecated('Use logicalFingerprintDescriptor instead') -const logicalFingerprint$json = { - '1': 'LogicalFingerprint', - '2': [ - {'1': 'content', '3': 1, '4': 1, '5': 12, '10': 'content'}, - ], -}; - -/// Descriptor for `LogicalFingerprint`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List logicalFingerprintDescriptor = - $convert.base64Decode( - 'ChJMb2dpY2FsRmluZ2VycHJpbnQSGAoHY29udGVudBgBIAEoDFIHY29udGVudA=='); -@$core.Deprecated('Use combinedFingerprintsDescriptor instead') -const sombinedFingerprints$json = { - '1': 'CombinedFingerprints', - '2': [ - {'1': 'version', '3': 1, '4': 1, '5': 13, '10': 'version'}, - { - '1': 'localFingerprint', - '3': 2, - '4': 1, - '5': 11, - '6': '.textsecure.LogicalFingerprint', - '10': 'localFingerprint' - }, - { - '1': 'remoteFingerprint', - '3': 3, - '4': 1, - '5': 11, - '6': '.textsecure.LogicalFingerprint', - '10': 'remoteFingerprint' - }, - ], -}; - -/// Descriptor for `CombinedFingerprints`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List combinedFingerprintsDescriptor = $convert.base64Decode( - 'ChRDb21iaW5lZEZpbmdlcnByaW50cxIYCgd2ZXJzaW9uGAEgASgNUgd2ZXJzaW9uEkoKEGxvY2FsRmluZ2VycHJpbnQYAiABKAsyHi50ZXh0c2VjdXJlLkxvZ2ljYWxGaW5nZXJwcmludFIQbG9jYWxGaW5nZXJwcmludBJMChFyZW1vdGVGaW5nZXJwcmludBgDIAEoCzIeLnRleHRzZWN1cmUuTG9naWNhbEZpbmdlcnByaW50UhFyZW1vdGVGaW5nZXJwcmludA=='); diff --git a/libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pbserver.dart b/libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pbserver.dart deleted file mode 100644 index a0f7ec9..0000000 --- a/libsignal_protocol_dart/lib/src/state/fingerprint_protocol.pbserver.dart +++ /dev/null @@ -1,7 +0,0 @@ -// Generated code. Do not modify. -// source: FingerprintProtocol.proto -// -// @dart = 2.12 -// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package - -export 'fingerprint_protocol.pb.dart'; diff --git a/libsignal_protocol_dart/lib/src/state/identity_key_store.dart b/libsignal_protocol_dart/lib/src/state/identity_key_store.dart deleted file mode 100644 index f542af6..0000000 --- a/libsignal_protocol_dart/lib/src/state/identity_key_store.dart +++ /dev/null @@ -1,20 +0,0 @@ -import '../identity_key.dart'; -import '../identity_key_pair.dart'; -import '../signal_protocol_address.dart'; - -enum Direction { sending, receiving } - -abstract class IdentityKeyStore { - Future getIdentityKeyPair(); - Future getLocalRegistrationId(); - Future saveIdentity( - SignalProtocolAddress address, - IdentityKey? identityKey, - ); - Future isTrustedIdentity( - SignalProtocolAddress address, - IdentityKey? identityKey, - Direction direction, - ); - Future getIdentity(SignalProtocolAddress address); -} diff --git a/libsignal_protocol_dart/lib/src/state/impl/in_memory_identity_key_store.dart b/libsignal_protocol_dart/lib/src/state/impl/in_memory_identity_key_store.dart deleted file mode 100644 index 8dc8c50..0000000 --- a/libsignal_protocol_dart/lib/src/state/impl/in_memory_identity_key_store.dart +++ /dev/null @@ -1,51 +0,0 @@ -import 'dart:collection'; - -import '../../eq.dart'; -import '../../identity_key.dart'; -import '../../identity_key_pair.dart'; -import '../../signal_protocol_address.dart'; -import '../identity_key_store.dart'; - -class InMemoryIdentityKeyStore extends IdentityKeyStore { - InMemoryIdentityKeyStore(this.identityKeyPair, this.localRegistrationId); - - final trustedKeys = HashMap(); - - final IdentityKeyPair identityKeyPair; - final int localRegistrationId; - - @override - Future getIdentity(SignalProtocolAddress address) async => - trustedKeys[address]!; - - @override - Future getIdentityKeyPair() async => identityKeyPair; - - @override - Future getLocalRegistrationId() async => localRegistrationId; - - @override - Future isTrustedIdentity(SignalProtocolAddress address, - IdentityKey? identityKey, Direction? direction) async { - final trusted = trustedKeys[address]; - if (identityKey == null) { - return false; - } - return trusted == null || eq(trusted.serialize(), identityKey.serialize()); - } - - @override - Future saveIdentity( - SignalProtocolAddress address, IdentityKey? identityKey) async { - final existing = trustedKeys[address]; - if (identityKey == null) { - return false; - } - if (identityKey != existing) { - trustedKeys[address] = identityKey; - return true; - } else { - return false; - } - } -} diff --git a/libsignal_protocol_dart/lib/src/state/impl/in_memory_pre_key_store.dart b/libsignal_protocol_dart/lib/src/state/impl/in_memory_pre_key_store.dart deleted file mode 100644 index 69c65b0..0000000 --- a/libsignal_protocol_dart/lib/src/state/impl/in_memory_pre_key_store.dart +++ /dev/null @@ -1,32 +0,0 @@ -import 'dart:collection'; -import 'dart:typed_data'; - -import '../../invalid_key_id_exception.dart'; -import '../pre_key_record.dart'; -import '../pre_key_store.dart'; - -class InMemoryPreKeyStore extends PreKeyStore { - final store = HashMap(); - - @override - Future containsPreKey(int preKeyId) async => - store.containsKey(preKeyId); - - @override - Future loadPreKey(int preKeyId) async { - if (!store.containsKey(preKeyId)) { - throw InvalidKeyIdException('No such prekeyrecord! - $preKeyId'); - } - return PreKeyRecord.fromBuffer(store[preKeyId]!); - } - - @override - Future removePreKey(int preKeyId) async { - store.remove(preKeyId); - } - - @override - Future storePreKey(int preKeyId, PreKeyRecord record) async { - store[preKeyId] = record.serialize(); - } -} diff --git a/libsignal_protocol_dart/lib/src/state/impl/in_memory_session_store.dart b/libsignal_protocol_dart/lib/src/state/impl/in_memory_session_store.dart deleted file mode 100644 index 9d2c057..0000000 --- a/libsignal_protocol_dart/lib/src/state/impl/in_memory_session_store.dart +++ /dev/null @@ -1,63 +0,0 @@ -import 'dart:collection'; -import 'dart:typed_data'; - -import '../../signal_protocol_address.dart'; -import '../session_record.dart'; -import '../session_store.dart'; - -class InMemorySessionStore extends SessionStore { - InMemorySessionStore(); - - HashMap sessions = - HashMap(); - - @override - Future containsSession(SignalProtocolAddress address) async => - sessions.containsKey(address); - - @override - Future deleteAllSessions(String name) async { - for (final k in sessions.keys.toList()) { - if (k.getName() == name) { - sessions.remove(k); - } - } - } - - @override - Future deleteSession(SignalProtocolAddress address) async { - sessions.remove(address); - } - - @override - Future> getSubDeviceSessions(String name) async { - final deviceIds = []; - - for (final key in sessions.keys) { - if (key.getName() == name && key.getDeviceId() != 1) { - deviceIds.add(key.getDeviceId()); - } - } - - return deviceIds; - } - - @override - Future loadSession(SignalProtocolAddress address) async { - try { - if (await containsSession(address)) { - return SessionRecord.fromSerialized(sessions[address]!); - } else { - return SessionRecord(); - } - } on Exception catch (e) { - throw AssertionError(e); - } - } - - @override - Future storeSession( - SignalProtocolAddress address, SessionRecord record) async { - sessions[address] = record.serialize(); - } -} diff --git a/libsignal_protocol_dart/lib/src/state/impl/in_memory_signal_protocol_store.dart b/libsignal_protocol_dart/lib/src/state/impl/in_memory_signal_protocol_store.dart deleted file mode 100644 index cb37a6d..0000000 --- a/libsignal_protocol_dart/lib/src/state/impl/in_memory_signal_protocol_store.dart +++ /dev/null @@ -1,119 +0,0 @@ -import 'dart:core'; - -import '../../identity_key.dart'; -import '../../identity_key_pair.dart'; -import '../../signal_protocol_address.dart'; -import '../identity_key_store.dart'; -import '../pre_key_record.dart'; -import '../session_record.dart'; -import '../signal_protocol_store.dart'; -import '../signed_pre_key_record.dart'; -import 'in_memory_identity_key_store.dart'; -import 'in_memory_pre_key_store.dart'; -import 'in_memory_session_store.dart'; -import 'in_memory_signed_pre_key_store.dart'; - -class InMemorySignalProtocolStore implements SignalProtocolStore { - InMemorySignalProtocolStore( - IdentityKeyPair identityKeyPair, int registrationId) { - _identityKeyStore = - InMemoryIdentityKeyStore(identityKeyPair, registrationId); - } - - final preKeyStore = InMemoryPreKeyStore(); - final sessionStore = InMemorySessionStore(); - final signedPreKeyStore = InMemorySignedPreKeyStore(); - - late IdentityKeyStore _identityKeyStore; - - @override - Future getIdentityKeyPair() async => - _identityKeyStore.getIdentityKeyPair(); - - @override - Future getLocalRegistrationId() async => - _identityKeyStore.getLocalRegistrationId(); - - @override - Future saveIdentity( - SignalProtocolAddress address, IdentityKey? identityKey) async => - _identityKeyStore.saveIdentity(address, identityKey); - - @override - Future isTrustedIdentity(SignalProtocolAddress address, - IdentityKey? identityKey, Direction direction) async => - _identityKeyStore.isTrustedIdentity(address, identityKey, direction); - - @override - Future getIdentity(SignalProtocolAddress address) async => - _identityKeyStore.getIdentity(address); - - @override - Future loadPreKey(int preKeyId) async => - preKeyStore.loadPreKey(preKeyId); - - @override - Future storePreKey(int preKeyId, PreKeyRecord record) async { - await preKeyStore.storePreKey(preKeyId, record); - } - - @override - Future containsPreKey(int preKeyId) async => - preKeyStore.containsPreKey(preKeyId); - - @override - Future removePreKey(int preKeyId) async { - await preKeyStore.removePreKey(preKeyId); - } - - @override - Future loadSession(SignalProtocolAddress address) async => - sessionStore.loadSession(address); - - @override - Future> getSubDeviceSessions(String name) async => - sessionStore.getSubDeviceSessions(name); - - @override - Future storeSession( - SignalProtocolAddress address, SessionRecord record) async { - await sessionStore.storeSession(address, record); - } - - @override - Future containsSession(SignalProtocolAddress address) async => - sessionStore.containsSession(address); - - @override - Future deleteSession(SignalProtocolAddress address) async { - await sessionStore.deleteSession(address); - } - - @override - Future deleteAllSessions(String name) async { - await sessionStore.deleteAllSessions(name); - } - - @override - Future loadSignedPreKey(int signedPreKeyId) async => - signedPreKeyStore.loadSignedPreKey(signedPreKeyId); - - @override - Future> loadSignedPreKeys() async => - signedPreKeyStore.loadSignedPreKeys(); - - @override - Future storeSignedPreKey( - int signedPreKeyId, SignedPreKeyRecord record) async { - await signedPreKeyStore.storeSignedPreKey(signedPreKeyId, record); - } - - @override - Future containsSignedPreKey(int signedPreKeyId) async => - signedPreKeyStore.containsSignedPreKey(signedPreKeyId); - - @override - Future removeSignedPreKey(int signedPreKeyId) async { - await signedPreKeyStore.removeSignedPreKey(signedPreKeyId); - } -} diff --git a/libsignal_protocol_dart/lib/src/state/impl/in_memory_signed_pre_key_store.dart b/libsignal_protocol_dart/lib/src/state/impl/in_memory_signed_pre_key_store.dart deleted file mode 100644 index 8a6f0f8..0000000 --- a/libsignal_protocol_dart/lib/src/state/impl/in_memory_signed_pre_key_store.dart +++ /dev/null @@ -1,43 +0,0 @@ -import 'dart:collection'; -import 'dart:typed_data'; - -import '../../invalid_key_id_exception.dart'; -import '../signed_pre_key_record.dart'; -import '../signed_pre_key_store.dart'; - -class InMemorySignedPreKeyStore extends SignedPreKeyStore { - final store = HashMap(); - - @override - Future loadSignedPreKey(int signedPreKeyId) async { - if (!store.containsKey(signedPreKeyId)) { - throw InvalidKeyIdException( - 'No such signedprekeyrecord! $signedPreKeyId'); - } - return SignedPreKeyRecord.fromSerialized(store[signedPreKeyId]!); - } - - @override - Future> loadSignedPreKeys() async { - final results = []; - for (final serialized in store.values) { - results.add(SignedPreKeyRecord.fromSerialized(serialized)); - } - return results; - } - - @override - Future storeSignedPreKey( - int signedPreKeyId, SignedPreKeyRecord record) async { - store[signedPreKeyId] = record.serialize(); - } - - @override - Future containsSignedPreKey(int signedPreKeyId) async => - store.containsKey(signedPreKeyId); - - @override - Future removeSignedPreKey(int signedPreKeyId) async { - store.remove(signedPreKeyId); - } -} diff --git a/libsignal_protocol_dart/lib/src/state/local_storage_protocol.pb.dart b/libsignal_protocol_dart/lib/src/state/local_storage_protocol.pb.dart deleted file mode 100644 index cadd73f..0000000 --- a/libsignal_protocol_dart/lib/src/state/local_storage_protocol.pb.dart +++ /dev/null @@ -1,2256 +0,0 @@ -import 'dart:core' as $core; -import 'dart:core'; - -import 'package:fixnum/fixnum.dart' as $fixnum; -import 'package:protobuf/protobuf.dart' as $pb; - -class SessionStructureChainChainKey extends $pb.GeneratedMessage { - factory SessionStructureChainChainKey({ - $core.int? index, - $core.List<$core.int>? key, - }) { - final _result = create(); - if (index != null) { - _result.index = index; - } - if (key != null) { - _result.key = key; - } - return _result; - } - - SessionStructureChainChainKey._() : super(); - - factory SessionStructureChainChainKey.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SessionStructureChainChainKey.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SessionStructure.Chain.ChainKey', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'index', - $pb.PbFieldType.OU3) - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'key', - $pb.PbFieldType.OY) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SessionStructureChainChainKey clone() => - SessionStructureChainChainKey()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SessionStructureChainChainKey copyWith( - void Function(SessionStructureChainChainKey) updates) => - super.copyWith( - (message) => updates(message as SessionStructureChainChainKey)) - as SessionStructureChainChainKey; // ignore: deprecated_member_use - - @override - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SessionStructureChainChainKey create() => - SessionStructureChainChainKey._(); - - @override - SessionStructureChainChainKey createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SessionStructureChainChainKey getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static SessionStructureChainChainKey? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get index => $_getIZ(0); - - @$pb.TagNumber(1) - set index($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasIndex() => $_has(0); - - @$pb.TagNumber(1) - void clearIndex() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get key => $_getN(1); - - @$pb.TagNumber(2) - set key($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasKey() => $_has(1); - - @$pb.TagNumber(2) - void clearKey() => clearField(2); -} - -class SessionStructureChainMessageKey extends $pb.GeneratedMessage { - factory SessionStructureChainMessageKey({ - $core.int? index, - $core.List<$core.int>? cipherKey, - $core.List<$core.int>? macKey, - $core.List<$core.int>? iv, - }) { - final _result = create(); - if (index != null) { - _result.index = index; - } - if (cipherKey != null) { - _result.cipherKey = cipherKey; - } - if (macKey != null) { - _result.macKey = macKey; - } - if (iv != null) { - _result.iv = iv; - } - return _result; - } - - SessionStructureChainMessageKey._() : super(); - - factory SessionStructureChainMessageKey.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SessionStructureChainMessageKey.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SessionStructure.Chain.MessageKey', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'index', - $pb.PbFieldType.OU3) - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'cipherKey', - $pb.PbFieldType.OY, - protoName: 'cipherKey') - ..a<$core.List<$core.int>>( - 3, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'macKey', - $pb.PbFieldType.OY, - protoName: 'macKey') - ..a<$core.List<$core.int>>( - 4, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'iv', - $pb.PbFieldType.OY) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SessionStructureChainMessageKey clone() => - SessionStructureChainMessageKey()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SessionStructureChainMessageKey copyWith( - void Function(SessionStructureChainMessageKey) updates) => - super.copyWith( - (message) => updates(message as SessionStructureChainMessageKey)) - as SessionStructureChainMessageKey; // ignore: deprecated_member_use - @override - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SessionStructureChainMessageKey create() => - SessionStructureChainMessageKey._(); - - @override - SessionStructureChainMessageKey createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SessionStructureChainMessageKey getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor( - create); - static SessionStructureChainMessageKey? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get index => $_getIZ(0); - - @$pb.TagNumber(1) - set index($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasIndex() => $_has(0); - - @$pb.TagNumber(1) - void clearIndex() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get cipherKey => $_getN(1); - - @$pb.TagNumber(2) - set cipherKey($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasCipherKey() => $_has(1); - - @$pb.TagNumber(2) - void clearCipherKey() => clearField(2); - - @$pb.TagNumber(3) - $core.List<$core.int> get macKey => $_getN(2); - - @$pb.TagNumber(3) - set macKey($core.List<$core.int> v) { - $_setBytes(2, v); - } - - @$pb.TagNumber(3) - $core.bool hasMacKey() => $_has(2); - - @$pb.TagNumber(3) - void clearMacKey() => clearField(3); - - @$pb.TagNumber(4) - $core.List<$core.int> get iv => $_getN(3); - - @$pb.TagNumber(4) - set iv($core.List<$core.int> v) { - $_setBytes(3, v); - } - - @$pb.TagNumber(4) - $core.bool hasIv() => $_has(3); - - @$pb.TagNumber(4) - void clearIv() => clearField(4); -} - -class SessionStructureChain extends $pb.GeneratedMessage { - factory SessionStructureChain({ - $core.List<$core.int>? senderRatchetKey, - $core.List<$core.int>? senderRatchetKeyPrivate, - SessionStructureChainChainKey? chainKey, - $core.Iterable? messageKeys, - }) { - final _result = create(); - if (senderRatchetKey != null) { - _result.senderRatchetKey = senderRatchetKey; - } - if (senderRatchetKeyPrivate != null) { - _result.senderRatchetKeyPrivate = senderRatchetKeyPrivate; - } - if (chainKey != null) { - _result.chainKey = chainKey; - } - if (messageKeys != null) { - _result.messageKeys.addAll(messageKeys); - } - return _result; - } - - SessionStructureChain._() : super(); - - factory SessionStructureChain.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SessionStructureChain.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SessionStructure.Chain', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.List<$core.int>>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'senderRatchetKey', - $pb.PbFieldType.OY, - protoName: 'senderRatchetKey') - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'senderRatchetKeyPrivate', - $pb.PbFieldType.OY, - protoName: 'senderRatchetKeyPrivate') - ..aOM( - 3, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'chainKey', - protoName: 'chainKey', - subBuilder: SessionStructureChainChainKey.create) - ..pc( - 4, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'messageKeys', - $pb.PbFieldType.PM, - protoName: 'messageKeys', - subBuilder: SessionStructureChainMessageKey.create) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SessionStructureChain clone() => - SessionStructureChain()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SessionStructureChain copyWith( - void Function(SessionStructureChain) updates) => - super.copyWith((message) => updates(message as SessionStructureChain)) - as SessionStructureChain; // ignore: deprecated_member_use - @override - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SessionStructureChain create() => SessionStructureChain._(); - - @override - SessionStructureChain createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SessionStructureChain getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static SessionStructureChain? _defaultInstance; - - @$pb.TagNumber(1) - $core.List<$core.int> get senderRatchetKey => $_getN(0); - - @$pb.TagNumber(1) - set senderRatchetKey($core.List<$core.int> v) { - $_setBytes(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasSenderRatchetKey() => $_has(0); - - @$pb.TagNumber(1) - void clearSenderRatchetKey() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get senderRatchetKeyPrivate => $_getN(1); - - @$pb.TagNumber(2) - set senderRatchetKeyPrivate($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasSenderRatchetKeyPrivate() => $_has(1); - - @$pb.TagNumber(2) - void clearSenderRatchetKeyPrivate() => clearField(2); - - @$pb.TagNumber(3) - SessionStructureChainChainKey get chainKey => $_getN(2); - - @$pb.TagNumber(3) - set chainKey(SessionStructureChainChainKey v) { - setField(3, v); - } - - @$pb.TagNumber(3) - $core.bool hasChainKey() => $_has(2); - - @$pb.TagNumber(3) - void clearChainKey() => clearField(3); - - @$pb.TagNumber(3) - SessionStructureChainChainKey ensureChainKey() => $_ensure(2); - - @$pb.TagNumber(4) - $core.List get messageKeys => $_getList(3); -} - -class SessionStructurePendingKeyExchange extends $pb.GeneratedMessage { - factory SessionStructurePendingKeyExchange({ - $core.int? sequence, - $core.List<$core.int>? localBaseKey, - $core.List<$core.int>? localBaseKeyPrivate, - $core.List<$core.int>? localRatchetKey, - $core.List<$core.int>? localRatchetKeyPrivate, - $core.List<$core.int>? localIdentityKey, - $core.List<$core.int>? localIdentityKeyPrivate, - }) { - final _result = create(); - if (sequence != null) { - _result.sequence = sequence; - } - if (localBaseKey != null) { - _result.localBaseKey = localBaseKey; - } - if (localBaseKeyPrivate != null) { - _result.localBaseKeyPrivate = localBaseKeyPrivate; - } - if (localRatchetKey != null) { - _result.localRatchetKey = localRatchetKey; - } - if (localRatchetKeyPrivate != null) { - _result.localRatchetKeyPrivate = localRatchetKeyPrivate; - } - if (localIdentityKey != null) { - _result.localIdentityKey = localIdentityKey; - } - if (localIdentityKeyPrivate != null) { - _result.localIdentityKeyPrivate = localIdentityKeyPrivate; - } - return _result; - } - - SessionStructurePendingKeyExchange._() : super(); - - factory SessionStructurePendingKeyExchange.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SessionStructurePendingKeyExchange.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SessionStructure.PendingKeyExchange', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'sequence', - $pb.PbFieldType.OU3) - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'localBaseKey', - $pb.PbFieldType.OY, - protoName: 'localBaseKey') - ..a<$core.List<$core.int>>( - 3, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'localBaseKeyPrivate', - $pb.PbFieldType.OY, - protoName: 'localBaseKeyPrivate') - ..a<$core.List<$core.int>>( - 4, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'localRatchetKey', - $pb.PbFieldType.OY, - protoName: 'localRatchetKey') - ..a<$core.List<$core.int>>( - 5, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'localRatchetKeyPrivate', - $pb.PbFieldType.OY, - protoName: 'localRatchetKeyPrivate') - ..a<$core.List<$core.int>>( - 7, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'localIdentityKey', - $pb.PbFieldType.OY, - protoName: 'localIdentityKey') - ..a<$core.List<$core.int>>( - 8, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'localIdentityKeyPrivate', - $pb.PbFieldType.OY, - protoName: 'localIdentityKeyPrivate') - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SessionStructurePendingKeyExchange clone() => - SessionStructurePendingKeyExchange()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SessionStructurePendingKeyExchange copyWith( - void Function(SessionStructurePendingKeyExchange) updates) => - super.copyWith((message) => - updates(message as SessionStructurePendingKeyExchange)) - as SessionStructurePendingKeyExchange; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SessionStructurePendingKeyExchange create() => - SessionStructurePendingKeyExchange._(); - - @override - SessionStructurePendingKeyExchange createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SessionStructurePendingKeyExchange getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor( - create); - static SessionStructurePendingKeyExchange? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get sequence => $_getIZ(0); - - @$pb.TagNumber(1) - set sequence($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasSequence() => $_has(0); - - @$pb.TagNumber(1) - void clearSequence() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get localBaseKey => $_getN(1); - - @$pb.TagNumber(2) - set localBaseKey($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasLocalBaseKey() => $_has(1); - - @$pb.TagNumber(2) - void clearLocalBaseKey() => clearField(2); - - @$pb.TagNumber(3) - $core.List<$core.int> get localBaseKeyPrivate => $_getN(2); - - @$pb.TagNumber(3) - set localBaseKeyPrivate($core.List<$core.int> v) { - $_setBytes(2, v); - } - - @$pb.TagNumber(3) - $core.bool hasLocalBaseKeyPrivate() => $_has(2); - - @$pb.TagNumber(3) - void clearLocalBaseKeyPrivate() => clearField(3); - - @$pb.TagNumber(4) - $core.List<$core.int> get localRatchetKey => $_getN(3); - - @$pb.TagNumber(4) - set localRatchetKey($core.List<$core.int> v) { - $_setBytes(3, v); - } - - @$pb.TagNumber(4) - $core.bool hasLocalRatchetKey() => $_has(3); - - @$pb.TagNumber(4) - void clearLocalRatchetKey() => clearField(4); - - @$pb.TagNumber(5) - $core.List<$core.int> get localRatchetKeyPrivate => $_getN(4); - - @$pb.TagNumber(5) - set localRatchetKeyPrivate($core.List<$core.int> v) { - $_setBytes(4, v); - } - - @$pb.TagNumber(5) - $core.bool hasLocalRatchetKeyPrivate() => $_has(4); - - @$pb.TagNumber(5) - void clearLocalRatchetKeyPrivate() => clearField(5); - - @$pb.TagNumber(7) - $core.List<$core.int> get localIdentityKey => $_getN(5); - - @$pb.TagNumber(7) - set localIdentityKey($core.List<$core.int> v) { - $_setBytes(5, v); - } - - @$pb.TagNumber(7) - $core.bool hasLocalIdentityKey() => $_has(5); - - @$pb.TagNumber(7) - void clearLocalIdentityKey() => clearField(7); - - @$pb.TagNumber(8) - $core.List<$core.int> get localIdentityKeyPrivate => $_getN(6); - - @$pb.TagNumber(8) - set localIdentityKeyPrivate($core.List<$core.int> v) { - $_setBytes(6, v); - } - - @$pb.TagNumber(8) - $core.bool hasLocalIdentityKeyPrivate() => $_has(6); - - @$pb.TagNumber(8) - void clearLocalIdentityKeyPrivate() => clearField(8); -} - -class SessionStructurePendingPreKey extends $pb.GeneratedMessage { - factory SessionStructurePendingPreKey({ - $core.int? preKeyId, - $core.List<$core.int>? baseKey, - $core.int? signedPreKeyId, - }) { - final _result = create(); - if (preKeyId != null) { - _result.preKeyId = preKeyId; - } - if (baseKey != null) { - _result.baseKey = baseKey; - } - if (signedPreKeyId != null) { - _result.signedPreKeyId = signedPreKeyId; - } - return _result; - } - - SessionStructurePendingPreKey._() : super(); - - factory SessionStructurePendingPreKey.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SessionStructurePendingPreKey.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SessionStructure.PendingPreKey', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'preKeyId', - $pb.PbFieldType.OU3, - protoName: 'preKeyId') - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'baseKey', - $pb.PbFieldType.OY, - protoName: 'baseKey') - ..a<$core.int>( - 3, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'signedPreKeyId', - $pb.PbFieldType.O3, - protoName: 'signedPreKeyId') - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SessionStructurePendingPreKey clone() => - SessionStructurePendingPreKey()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SessionStructurePendingPreKey copyWith( - void Function(SessionStructurePendingPreKey) updates) => - super.copyWith( - (message) => updates(message as SessionStructurePendingPreKey)) - as SessionStructurePendingPreKey; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SessionStructurePendingPreKey create() => - SessionStructurePendingPreKey._(); - - @override - SessionStructurePendingPreKey createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SessionStructurePendingPreKey getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static SessionStructurePendingPreKey? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get preKeyId => $_getIZ(0); - - @$pb.TagNumber(1) - set preKeyId($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasPreKeyId() => $_has(0); - - @$pb.TagNumber(1) - void clearPreKeyId() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get baseKey => $_getN(1); - - @$pb.TagNumber(2) - set baseKey($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasBaseKey() => $_has(1); - - @$pb.TagNumber(2) - void clearBaseKey() => clearField(2); - - @$pb.TagNumber(3) - $core.int get signedPreKeyId => $_getIZ(2); - - @$pb.TagNumber(3) - set signedPreKeyId($core.int v) { - $_setSignedInt32(2, v); - } - - @$pb.TagNumber(3) - $core.bool hasSignedPreKeyId() => $_has(2); - - @$pb.TagNumber(3) - void clearSignedPreKeyId() => clearField(3); -} - -class SessionStructure extends $pb.GeneratedMessage { - factory SessionStructure({ - $core.int? sessionVersion, - $core.List<$core.int>? localIdentityPublic, - $core.List<$core.int>? remoteIdentityPublic, - $core.List<$core.int>? rootKey, - $core.int? previousCounter, - SessionStructureChain? senderChain, - $core.Iterable? receiverChains, - SessionStructurePendingKeyExchange? pendingKeyExchange, - SessionStructurePendingPreKey? pendingPreKey, - $core.int? remoteRegistrationId, - $core.int? localRegistrationId, - $core.bool? needsRefresh, - $core.List<$core.int>? aliceBaseKey, - }) { - final _result = create(); - if (sessionVersion != null) { - _result.sessionVersion = sessionVersion; - } - if (localIdentityPublic != null) { - _result.localIdentityPublic = localIdentityPublic; - } - if (remoteIdentityPublic != null) { - _result.remoteIdentityPublic = remoteIdentityPublic; - } - if (rootKey != null) { - _result.rootKey = rootKey; - } - if (previousCounter != null) { - _result.previousCounter = previousCounter; - } - if (senderChain != null) { - _result.senderChain = senderChain; - } - if (receiverChains != null) { - _result.receiverChains.addAll(receiverChains); - } - if (pendingKeyExchange != null) { - _result.pendingKeyExchange = pendingKeyExchange; - } - if (pendingPreKey != null) { - _result.pendingPreKey = pendingPreKey; - } - if (remoteRegistrationId != null) { - _result.remoteRegistrationId = remoteRegistrationId; - } - if (localRegistrationId != null) { - _result.localRegistrationId = localRegistrationId; - } - if (needsRefresh != null) { - _result.needsRefresh = needsRefresh; - } - if (aliceBaseKey != null) { - _result.aliceBaseKey = aliceBaseKey; - } - return _result; - } - - SessionStructure._() : super(); - - factory SessionStructure.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SessionStructure.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SessionStructure', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'sessionVersion', - $pb.PbFieldType.OU3, - protoName: 'sessionVersion') - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'localIdentityPublic', - $pb.PbFieldType.OY, - protoName: 'localIdentityPublic') - ..a<$core.List<$core.int>>( - 3, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'remoteIdentityPublic', - $pb.PbFieldType.OY, - protoName: 'remoteIdentityPublic') - ..a<$core.List<$core.int>>( - 4, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'rootKey', - $pb.PbFieldType.OY, - protoName: 'rootKey') - ..a<$core.int>( - 5, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'previousCounter', - $pb.PbFieldType.OU3, - protoName: 'previousCounter') - ..aOM( - 6, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'senderChain', - protoName: 'senderChain', - subBuilder: SessionStructureChain.create) - ..pc( - 7, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'receiverChains', - $pb.PbFieldType.PM, - protoName: 'receiverChains', - subBuilder: SessionStructureChain.create) - ..aOM( - 8, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'pendingKeyExchange', - protoName: 'pendingKeyExchange', - subBuilder: SessionStructurePendingKeyExchange.create) - ..aOM( - 9, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'pendingPreKey', - protoName: 'pendingPreKey', - subBuilder: SessionStructurePendingPreKey.create) - ..a<$core.int>( - 10, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'remoteRegistrationId', - $pb.PbFieldType.OU3, - protoName: 'remoteRegistrationId') - ..a<$core.int>( - 11, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'localRegistrationId', - $pb.PbFieldType.OU3, - protoName: 'localRegistrationId') - ..aOB( - 12, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'needsRefresh', - protoName: 'needsRefresh') - ..a<$core.List<$core.int>>( - 13, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'aliceBaseKey', - $pb.PbFieldType.OY, - protoName: 'aliceBaseKey') - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SessionStructure clone() => SessionStructure()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SessionStructure copyWith(void Function(SessionStructure) updates) => - super.copyWith((message) => updates(message as SessionStructure)) - as SessionStructure; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SessionStructure create() => SessionStructure._(); - - @override - SessionStructure createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SessionStructure getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static SessionStructure? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get sessionVersion => $_getIZ(0); - - @$pb.TagNumber(1) - set sessionVersion($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasSessionVersion() => $_has(0); - - @$pb.TagNumber(1) - void clearSessionVersion() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get localIdentityPublic => $_getN(1); - - @$pb.TagNumber(2) - set localIdentityPublic($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasLocalIdentityPublic() => $_has(1); - - @$pb.TagNumber(2) - void clearLocalIdentityPublic() => clearField(2); - - @$pb.TagNumber(3) - $core.List<$core.int> get remoteIdentityPublic => $_getN(2); - - @$pb.TagNumber(3) - set remoteIdentityPublic($core.List<$core.int> v) { - $_setBytes(2, v); - } - - @$pb.TagNumber(3) - $core.bool hasRemoteIdentityPublic() => $_has(2); - - @$pb.TagNumber(3) - void clearRemoteIdentityPublic() => clearField(3); - - @$pb.TagNumber(4) - $core.List<$core.int> get rootKey => $_getN(3); - - @$pb.TagNumber(4) - set rootKey($core.List<$core.int> v) { - $_setBytes(3, v); - } - - @$pb.TagNumber(4) - $core.bool hasRootKey() => $_has(3); - - @$pb.TagNumber(4) - void clearRootKey() => clearField(4); - - @$pb.TagNumber(5) - $core.int get previousCounter => $_getIZ(4); - - @$pb.TagNumber(5) - set previousCounter($core.int v) { - $_setUnsignedInt32(4, v); - } - - @$pb.TagNumber(5) - $core.bool hasPreviousCounter() => $_has(4); - - @$pb.TagNumber(5) - void clearPreviousCounter() => clearField(5); - - @$pb.TagNumber(6) - SessionStructureChain get senderChain => $_getN(5); - - @$pb.TagNumber(6) - set senderChain(SessionStructureChain v) { - setField(6, v); - } - - @$pb.TagNumber(6) - $core.bool hasSenderChain() => $_has(5); - - @$pb.TagNumber(6) - void clearSenderChain() => clearField(6); - - @$pb.TagNumber(6) - SessionStructureChain ensureSenderChain() => $_ensure(5); - - @$pb.TagNumber(7) - $core.List get receiverChains => $_getList(6); - - @$pb.TagNumber(8) - SessionStructurePendingKeyExchange get pendingKeyExchange => $_getN(7); - - @$pb.TagNumber(8) - set pendingKeyExchange(SessionStructurePendingKeyExchange v) { - setField(8, v); - } - - @$pb.TagNumber(8) - $core.bool hasPendingKeyExchange() => $_has(7); - - @$pb.TagNumber(8) - void clearPendingKeyExchange() => clearField(8); - - @$pb.TagNumber(8) - SessionStructurePendingKeyExchange ensurePendingKeyExchange() => $_ensure(7); - - @$pb.TagNumber(9) - SessionStructurePendingPreKey get pendingPreKey => $_getN(8); - - @$pb.TagNumber(9) - set pendingPreKey(SessionStructurePendingPreKey v) { - setField(9, v); - } - - @$pb.TagNumber(9) - $core.bool hasPendingPreKey() => $_has(8); - - @$pb.TagNumber(9) - void clearPendingPreKey() => clearField(9); - - @$pb.TagNumber(9) - SessionStructurePendingPreKey ensurePendingPreKey() => $_ensure(8); - - @$pb.TagNumber(10) - $core.int get remoteRegistrationId => $_getIZ(9); - - @$pb.TagNumber(10) - set remoteRegistrationId($core.int v) { - $_setUnsignedInt32(9, v); - } - - @$pb.TagNumber(10) - $core.bool hasRemoteRegistrationId() => $_has(9); - - @$pb.TagNumber(10) - void clearRemoteRegistrationId() => clearField(10); - - @$pb.TagNumber(11) - $core.int get localRegistrationId => $_getIZ(10); - - @$pb.TagNumber(11) - set localRegistrationId($core.int v) { - $_setUnsignedInt32(10, v); - } - - @$pb.TagNumber(11) - $core.bool hasLocalRegistrationId() => $_has(10); - - @$pb.TagNumber(11) - void clearLocalRegistrationId() => clearField(11); - - @$pb.TagNumber(12) - $core.bool get needsRefresh => $_getBF(11); - - @$pb.TagNumber(12) - set needsRefresh($core.bool v) { - $_setBool(11, v); - } - - @$pb.TagNumber(12) - $core.bool hasNeedsRefresh() => $_has(11); - - @$pb.TagNumber(12) - void clearNeedsRefresh() => clearField(12); - - @$pb.TagNumber(13) - $core.List<$core.int> get aliceBaseKey => $_getN(12); - - @$pb.TagNumber(13) - set aliceBaseKey($core.List<$core.int> v) { - $_setBytes(12, v); - } - - @$pb.TagNumber(13) - $core.bool hasAliceBaseKey() => $_has(12); - - @$pb.TagNumber(13) - void clearAliceBaseKey() => clearField(13); -} - -class RecordStructure extends $pb.GeneratedMessage { - factory RecordStructure({ - SessionStructure? currentSession, - $core.Iterable? previousSessions, - }) { - final _result = create(); - if (currentSession != null) { - _result.currentSession = currentSession; - } - if (previousSessions != null) { - _result.previousSessions.addAll(previousSessions); - } - return _result; - } - - RecordStructure._() : super(); - - factory RecordStructure.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory RecordStructure.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'RecordStructure', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..aOM( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'currentSession', - protoName: 'currentSession', - subBuilder: SessionStructure.create) - ..pc( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'previousSessions', - $pb.PbFieldType.PM, - protoName: 'previousSessions', - subBuilder: SessionStructure.create) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - RecordStructure clone() => RecordStructure()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - RecordStructure copyWith(void Function(RecordStructure) updates) => - super.copyWith((message) => updates(message as RecordStructure)) - as RecordStructure; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static RecordStructure create() => RecordStructure._(); - - @override - RecordStructure createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static RecordStructure getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static RecordStructure? _defaultInstance; - - @$pb.TagNumber(1) - SessionStructure get currentSession => $_getN(0); - - @$pb.TagNumber(1) - set currentSession(SessionStructure v) { - setField(1, v); - } - - @$pb.TagNumber(1) - $core.bool hasCurrentSession() => $_has(0); - - @$pb.TagNumber(1) - void clearCurrentSession() => clearField(1); - - @$pb.TagNumber(1) - SessionStructure ensureCurrentSession() => $_ensure(0); - - @$pb.TagNumber(2) - $core.List get previousSessions => $_getList(1); -} - -class PreKeyRecordStructure extends $pb.GeneratedMessage { - factory PreKeyRecordStructure({ - $core.int? id, - $core.List<$core.int>? publicKey, - $core.List<$core.int>? privateKey, - }) { - final _result = create(); - if (id != null) { - _result.id = id; - } - if (publicKey != null) { - _result.publicKey = publicKey; - } - if (privateKey != null) { - _result.privateKey = privateKey; - } - return _result; - } - - PreKeyRecordStructure._() : super(); - - factory PreKeyRecordStructure.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory PreKeyRecordStructure.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'PreKeyRecordStructure', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'id', - $pb.PbFieldType.OU3) - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'publicKey', - $pb.PbFieldType.OY, - protoName: 'publicKey') - ..a<$core.List<$core.int>>( - 3, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'privateKey', - $pb.PbFieldType.OY, - protoName: 'privateKey') - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - PreKeyRecordStructure clone() => - PreKeyRecordStructure()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - PreKeyRecordStructure copyWith( - void Function(PreKeyRecordStructure) updates) => - super.copyWith((message) => updates(message as PreKeyRecordStructure)) - as PreKeyRecordStructure; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static PreKeyRecordStructure create() => PreKeyRecordStructure._(); - - @override - PreKeyRecordStructure createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static PreKeyRecordStructure getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static PreKeyRecordStructure? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get id => $_getIZ(0); - - @$pb.TagNumber(1) - set id($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasId() => $_has(0); - - @$pb.TagNumber(1) - void clearId() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get publicKey => $_getN(1); - - @$pb.TagNumber(2) - set publicKey($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasPublicKey() => $_has(1); - - @$pb.TagNumber(2) - void clearPublicKey() => clearField(2); - - @$pb.TagNumber(3) - $core.List<$core.int> get privateKey => $_getN(2); - - @$pb.TagNumber(3) - set privateKey($core.List<$core.int> v) { - $_setBytes(2, v); - } - - @$pb.TagNumber(3) - $core.bool hasPrivateKey() => $_has(2); - - @$pb.TagNumber(3) - void clearPrivateKey() => clearField(3); -} - -class SignedPreKeyRecordStructure extends $pb.GeneratedMessage { - factory SignedPreKeyRecordStructure({ - $core.int? id, - $core.List<$core.int>? publicKey, - $core.List<$core.int>? privateKey, - $core.List<$core.int>? signature, - $fixnum.Int64? timestamp, - }) { - final _result = create(); - if (id != null) { - _result.id = id; - } - if (publicKey != null) { - _result.publicKey = publicKey; - } - if (privateKey != null) { - _result.privateKey = privateKey; - } - if (signature != null) { - _result.signature = signature; - } - if (timestamp != null) { - _result.timestamp = timestamp; - } - return _result; - } - - SignedPreKeyRecordStructure._() : super(); - - factory SignedPreKeyRecordStructure.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SignedPreKeyRecordStructure.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SignedPreKeyRecordStructure', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'id', - $pb.PbFieldType.OU3) - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'publicKey', - $pb.PbFieldType.OY, - protoName: 'publicKey') - ..a<$core.List<$core.int>>( - 3, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'privateKey', - $pb.PbFieldType.OY, - protoName: 'privateKey') - ..a<$core.List<$core.int>>( - 4, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'signature', - $pb.PbFieldType.OY) - ..a<$fixnum.Int64>( - 5, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'timestamp', - $pb.PbFieldType.OF6, - defaultOrMaker: $fixnum.Int64.ZERO) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SignedPreKeyRecordStructure clone() => - SignedPreKeyRecordStructure()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SignedPreKeyRecordStructure copyWith( - void Function(SignedPreKeyRecordStructure) updates) => - super.copyWith( - (message) => updates(message as SignedPreKeyRecordStructure)) - as SignedPreKeyRecordStructure; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SignedPreKeyRecordStructure create() => - SignedPreKeyRecordStructure._(); - - @override - SignedPreKeyRecordStructure createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SignedPreKeyRecordStructure getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static SignedPreKeyRecordStructure? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get id => $_getIZ(0); - - @$pb.TagNumber(1) - set id($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasId() => $_has(0); - - @$pb.TagNumber(1) - void clearId() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get publicKey => $_getN(1); - - @$pb.TagNumber(2) - set publicKey($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasPublicKey() => $_has(1); - - @$pb.TagNumber(2) - void clearPublicKey() => clearField(2); - - @$pb.TagNumber(3) - $core.List<$core.int> get privateKey => $_getN(2); - - @$pb.TagNumber(3) - set privateKey($core.List<$core.int> v) { - $_setBytes(2, v); - } - - @$pb.TagNumber(3) - $core.bool hasPrivateKey() => $_has(2); - - @$pb.TagNumber(3) - void clearPrivateKey() => clearField(3); - - @$pb.TagNumber(4) - $core.List<$core.int> get signature => $_getN(3); - - @$pb.TagNumber(4) - set signature($core.List<$core.int> v) { - $_setBytes(3, v); - } - - @$pb.TagNumber(4) - $core.bool hasSignature() => $_has(3); - - @$pb.TagNumber(4) - void clearSignature() => clearField(4); - - @$pb.TagNumber(5) - $fixnum.Int64 get timestamp => $_getI64(4); - - @$pb.TagNumber(5) - set timestamp($fixnum.Int64 v) { - $_setInt64(4, v); - } - - @$pb.TagNumber(5) - $core.bool hasTimestamp() => $_has(4); - - @$pb.TagNumber(5) - void clearTimestamp() => clearField(5); -} - -class IdentityKeyPairStructure extends $pb.GeneratedMessage { - factory IdentityKeyPairStructure({ - $core.List<$core.int>? publicKey, - $core.List<$core.int>? privateKey, - }) { - final _result = create(); - if (publicKey != null) { - _result.publicKey = publicKey; - } - if (privateKey != null) { - _result.privateKey = privateKey; - } - return _result; - } - - IdentityKeyPairStructure._() : super(); - - factory IdentityKeyPairStructure.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory IdentityKeyPairStructure.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'IdentityKeyPairStructure', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.List<$core.int>>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'publicKey', - $pb.PbFieldType.OY, - protoName: 'publicKey') - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'privateKey', - $pb.PbFieldType.OY, - protoName: 'privateKey') - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - IdentityKeyPairStructure clone() => - IdentityKeyPairStructure()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - IdentityKeyPairStructure copyWith( - void Function(IdentityKeyPairStructure) updates) => - super.copyWith((message) => updates(message as IdentityKeyPairStructure)) - as IdentityKeyPairStructure; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static IdentityKeyPairStructure create() => IdentityKeyPairStructure._(); - - @override - IdentityKeyPairStructure createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static IdentityKeyPairStructure getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static IdentityKeyPairStructure? _defaultInstance; - - @$pb.TagNumber(1) - $core.List<$core.int> get publicKey => $_getN(0); - - @$pb.TagNumber(1) - set publicKey($core.List<$core.int> v) { - $_setBytes(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasPublicKey() => $_has(0); - - @$pb.TagNumber(1) - void clearPublicKey() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get privateKey => $_getN(1); - - @$pb.TagNumber(2) - set privateKey($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasPrivateKey() => $_has(1); - - @$pb.TagNumber(2) - void clearPrivateKey() => clearField(2); -} - -class SenderKeyStateStructureSenderChainKey extends $pb.GeneratedMessage { - factory SenderKeyStateStructureSenderChainKey({ - $core.int? iteration, - $core.List<$core.int>? seed, - }) { - final _result = create(); - if (iteration != null) { - _result.iteration = iteration; - } - if (seed != null) { - _result.seed = seed; - } - return _result; - } - - SenderKeyStateStructureSenderChainKey._() : super(); - - factory SenderKeyStateStructureSenderChainKey.fromBuffer( - $core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SenderKeyStateStructureSenderChainKey.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SenderKeyStateStructure.SenderChainKey', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'iteration', - $pb.PbFieldType.OU3) - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'seed', - $pb.PbFieldType.OY) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SenderKeyStateStructureSenderChainKey clone() => - SenderKeyStateStructureSenderChainKey()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SenderKeyStateStructureSenderChainKey copyWith( - void Function(SenderKeyStateStructureSenderChainKey) updates) => - super.copyWith((message) => - updates(message as SenderKeyStateStructureSenderChainKey)) - as SenderKeyStateStructureSenderChainKey; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SenderKeyStateStructureSenderChainKey create() => - SenderKeyStateStructureSenderChainKey._(); - - @override - SenderKeyStateStructureSenderChainKey createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SenderKeyStateStructureSenderChainKey getDefault() => - _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor< - SenderKeyStateStructureSenderChainKey>(create); - static SenderKeyStateStructureSenderChainKey? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get iteration => $_getIZ(0); - - @$pb.TagNumber(1) - set iteration($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasIteration() => $_has(0); - - @$pb.TagNumber(1) - void clearIteration() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get seed => $_getN(1); - - @$pb.TagNumber(2) - set seed($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasSeed() => $_has(1); - - @$pb.TagNumber(2) - void clearSeed() => clearField(2); -} - -class SenderKeyStateStructureSenderMessageKey extends $pb.GeneratedMessage { - factory SenderKeyStateStructureSenderMessageKey({ - $core.int? iteration, - $core.List<$core.int>? seed, - }) { - final _result = create(); - if (iteration != null) { - _result.iteration = iteration; - } - if (seed != null) { - _result.seed = seed; - } - return _result; - } - - SenderKeyStateStructureSenderMessageKey._() : super(); - - factory SenderKeyStateStructureSenderMessageKey.fromBuffer( - $core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SenderKeyStateStructureSenderMessageKey.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SenderKeyStateStructure.SenderMessageKey', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'iteration', - $pb.PbFieldType.OU3) - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'seed', - $pb.PbFieldType.OY) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SenderKeyStateStructureSenderMessageKey clone() => - SenderKeyStateStructureSenderMessageKey()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SenderKeyStateStructureSenderMessageKey copyWith( - void Function(SenderKeyStateStructureSenderMessageKey) updates) => - super.copyWith((message) => - updates(message as SenderKeyStateStructureSenderMessageKey)) - as SenderKeyStateStructureSenderMessageKey; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SenderKeyStateStructureSenderMessageKey create() => - SenderKeyStateStructureSenderMessageKey._(); - - @override - SenderKeyStateStructureSenderMessageKey createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SenderKeyStateStructureSenderMessageKey getDefault() => - _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor< - SenderKeyStateStructureSenderMessageKey>(create); - static SenderKeyStateStructureSenderMessageKey? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get iteration => $_getIZ(0); - - @$pb.TagNumber(1) - set iteration($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasIteration() => $_has(0); - - @$pb.TagNumber(1) - void clearIteration() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get seed => $_getN(1); - - @$pb.TagNumber(2) - set seed($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasSeed() => $_has(1); - - @$pb.TagNumber(2) - void clearSeed() => clearField(2); -} - -class SenderKeyStateStructureSenderSigningKey extends $pb.GeneratedMessage { - factory SenderKeyStateStructureSenderSigningKey({ - $core.List<$core.int>? public, - $core.List<$core.int>? private, - }) { - final _result = create(); - if (public != null) { - _result.public = public; - } - if (private != null) { - _result.private = private; - } - return _result; - } - - SenderKeyStateStructureSenderSigningKey._() : super(); - - factory SenderKeyStateStructureSenderSigningKey.fromBuffer( - $core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SenderKeyStateStructureSenderSigningKey.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SenderKeyStateStructure.SenderSigningKey', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.List<$core.int>>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'public', - $pb.PbFieldType.OY) - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'private', - $pb.PbFieldType.OY) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SenderKeyStateStructureSenderSigningKey clone() => - SenderKeyStateStructureSenderSigningKey()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SenderKeyStateStructureSenderSigningKey copyWith( - void Function(SenderKeyStateStructureSenderSigningKey) updates) => - super.copyWith((message) => - updates(message as SenderKeyStateStructureSenderSigningKey)) - as SenderKeyStateStructureSenderSigningKey; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SenderKeyStateStructureSenderSigningKey create() => - SenderKeyStateStructureSenderSigningKey._(); - - @override - SenderKeyStateStructureSenderSigningKey createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SenderKeyStateStructureSenderSigningKey getDefault() => - _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor< - SenderKeyStateStructureSenderSigningKey>(create); - static SenderKeyStateStructureSenderSigningKey? _defaultInstance; - - @$pb.TagNumber(1) - $core.List<$core.int> get public => $_getN(0); - - @$pb.TagNumber(1) - set public($core.List<$core.int> v) { - $_setBytes(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasPublic() => $_has(0); - - @$pb.TagNumber(1) - void clearPublic() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get private => $_getN(1); - - @$pb.TagNumber(2) - set private($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasPrivate() => $_has(1); - - @$pb.TagNumber(2) - void clearPrivate() => clearField(2); -} - -class SenderKeyStateStructure extends $pb.GeneratedMessage { - factory SenderKeyStateStructure({ - $core.int? senderKeyId, - SenderKeyStateStructureSenderChainKey? senderChainKey, - SenderKeyStateStructureSenderSigningKey? senderSigningKey, - $core.Iterable? senderMessageKeys, - }) { - final _result = create(); - if (senderKeyId != null) { - _result.senderKeyId = senderKeyId; - } - if (senderChainKey != null) { - _result.senderChainKey = senderChainKey; - } - if (senderSigningKey != null) { - _result.senderSigningKey = senderSigningKey; - } - if (senderMessageKeys != null) { - _result.senderMessageKeys.addAll(senderMessageKeys); - } - return _result; - } - - SenderKeyStateStructure._() : super(); - - factory SenderKeyStateStructure.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SenderKeyStateStructure.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SenderKeyStateStructure', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'senderKeyId', - $pb.PbFieldType.OU3, - protoName: 'senderKeyId') - ..aOM( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'senderChainKey', - protoName: 'senderChainKey', - subBuilder: SenderKeyStateStructureSenderChainKey.create) - ..aOM( - 3, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'senderSigningKey', - protoName: 'senderSigningKey', - subBuilder: SenderKeyStateStructureSenderSigningKey.create) - ..pc( - 4, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'senderMessageKeys', - $pb.PbFieldType.PM, - protoName: 'senderMessageKeys', - subBuilder: SenderKeyStateStructureSenderMessageKey.create) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SenderKeyStateStructure clone() => - SenderKeyStateStructure()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SenderKeyStateStructure copyWith( - void Function(SenderKeyStateStructure) updates) => - super.copyWith((message) => updates(message as SenderKeyStateStructure)) - as SenderKeyStateStructure; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SenderKeyStateStructure create() => SenderKeyStateStructure._(); - - @override - SenderKeyStateStructure createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SenderKeyStateStructure getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static SenderKeyStateStructure? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get senderKeyId => $_getIZ(0); - - @$pb.TagNumber(1) - set senderKeyId($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasSenderKeyId() => $_has(0); - - @$pb.TagNumber(1) - void clearSenderKeyId() => clearField(1); - - @$pb.TagNumber(2) - SenderKeyStateStructureSenderChainKey get senderChainKey => $_getN(1); - - @$pb.TagNumber(2) - set senderChainKey(SenderKeyStateStructureSenderChainKey v) { - setField(2, v); - } - - @$pb.TagNumber(2) - $core.bool hasSenderChainKey() => $_has(1); - - @$pb.TagNumber(2) - void clearSenderChainKey() => clearField(2); - - @$pb.TagNumber(2) - SenderKeyStateStructureSenderChainKey ensureSenderChainKey() => $_ensure(1); - - @$pb.TagNumber(3) - SenderKeyStateStructureSenderSigningKey get senderSigningKey => $_getN(2); - - @$pb.TagNumber(3) - set senderSigningKey(SenderKeyStateStructureSenderSigningKey v) { - setField(3, v); - } - - @$pb.TagNumber(3) - $core.bool hasSenderSigningKey() => $_has(2); - - @$pb.TagNumber(3) - void clearSenderSigningKey() => clearField(3); - - @$pb.TagNumber(3) - SenderKeyStateStructureSenderSigningKey ensureSenderSigningKey() => - $_ensure(2); - - @$pb.TagNumber(4) - $core.List get senderMessageKeys => - $_getList(3); -} - -class SenderKeyRecordStructure extends $pb.GeneratedMessage { - factory SenderKeyRecordStructure({ - $core.Iterable? senderKeyStates, - }) { - final _result = create(); - if (senderKeyStates != null) { - _result.senderKeyStates.addAll(senderKeyStates); - } - return _result; - } - - SenderKeyRecordStructure._() : super(); - - factory SenderKeyRecordStructure.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SenderKeyRecordStructure.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SenderKeyRecordStructure', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..pc( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'senderKeyStates', - $pb.PbFieldType.PM, - protoName: 'senderKeyStates', - subBuilder: SenderKeyStateStructure.create) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SenderKeyRecordStructure clone() => - SenderKeyRecordStructure()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SenderKeyRecordStructure copyWith( - void Function(SenderKeyRecordStructure) updates) => - super.copyWith((message) => updates(message as SenderKeyRecordStructure)) - as SenderKeyRecordStructure; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SenderKeyRecordStructure create() => SenderKeyRecordStructure._(); - - @override - SenderKeyRecordStructure createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SenderKeyRecordStructure getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static SenderKeyRecordStructure? _defaultInstance; - - @$pb.TagNumber(1) - $core.List get senderKeyStates => $_getList(0); -} diff --git a/libsignal_protocol_dart/lib/src/state/local_storage_protocol.pbenum.dart b/libsignal_protocol_dart/lib/src/state/local_storage_protocol.pbenum.dart deleted file mode 100644 index 8ad5fc0..0000000 --- a/libsignal_protocol_dart/lib/src/state/local_storage_protocol.pbenum.dart +++ /dev/null @@ -1,5 +0,0 @@ -// Generated code. Do not modify. -// source: LocalStorageProtocol.proto -// -// @dart = 2.12 -// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields diff --git a/libsignal_protocol_dart/lib/src/state/local_storage_protocol.pbjson.dart b/libsignal_protocol_dart/lib/src/state/local_storage_protocol.pbjson.dart deleted file mode 100644 index 1a900a4..0000000 --- a/libsignal_protocol_dart/lib/src/state/local_storage_protocol.pbjson.dart +++ /dev/null @@ -1,348 +0,0 @@ -import 'dart:convert' as $convert; -import 'dart:core' as $core; -import 'dart:typed_data' as $typed_data; - -@$core.Deprecated('Use sessionStructureDescriptor instead') -const sessionStructure$json = { - '1': 'SessionStructure', - '2': [ - {'1': 'sessionVersion', '3': 1, '4': 1, '5': 13, '10': 'sessionVersion'}, - { - '1': 'localIdentityPublic', - '3': 2, - '4': 1, - '5': 12, - '10': 'localIdentityPublic' - }, - { - '1': 'remoteIdentityPublic', - '3': 3, - '4': 1, - '5': 12, - '10': 'remoteIdentityPublic' - }, - {'1': 'rootKey', '3': 4, '4': 1, '5': 12, '10': 'rootKey'}, - {'1': 'previousCounter', '3': 5, '4': 1, '5': 13, '10': 'previousCounter'}, - { - '1': 'senderChain', - '3': 6, - '4': 1, - '5': 11, - '6': '.textsecure.SessionStructure.Chain', - '10': 'senderChain' - }, - { - '1': 'receiverChains', - '3': 7, - '4': 3, - '5': 11, - '6': '.textsecure.SessionStructure.Chain', - '10': 'receiverChains' - }, - { - '1': 'pendingKeyExchange', - '3': 8, - '4': 1, - '5': 11, - '6': '.textsecure.SessionStructure.PendingKeyExchange', - '10': 'pendingKeyExchange' - }, - { - '1': 'pendingPreKey', - '3': 9, - '4': 1, - '5': 11, - '6': '.textsecure.SessionStructure.PendingPreKey', - '10': 'pendingPreKey' - }, - { - '1': 'remoteRegistrationId', - '3': 10, - '4': 1, - '5': 13, - '10': 'remoteRegistrationId' - }, - { - '1': 'localRegistrationId', - '3': 11, - '4': 1, - '5': 13, - '10': 'localRegistrationId' - }, - {'1': 'needsRefresh', '3': 12, '4': 1, '5': 8, '10': 'needsRefresh'}, - {'1': 'aliceBaseKey', '3': 13, '4': 1, '5': 12, '10': 'aliceBaseKey'}, - ], - '3': [ - sessionStructureChain$json, - sessionStructurePendingKeyExchange$json, - sessionStructurePendingPreKey$json - ], -}; - -@$core.Deprecated('Use sessionStructureDescriptor instead') -const sessionStructureChain$json = { - '1': 'Chain', - '2': [ - { - '1': 'senderRatchetKey', - '3': 1, - '4': 1, - '5': 12, - '10': 'senderRatchetKey' - }, - { - '1': 'senderRatchetKeyPrivate', - '3': 2, - '4': 1, - '5': 12, - '10': 'senderRatchetKeyPrivate' - }, - { - '1': 'chainKey', - '3': 3, - '4': 1, - '5': 11, - '6': '.textsecure.SessionStructure.Chain.ChainKey', - '10': 'chainKey' - }, - { - '1': 'messageKeys', - '3': 4, - '4': 3, - '5': 11, - '6': '.textsecure.SessionStructure.Chain.MessageKey', - '10': 'messageKeys' - }, - ], - '3': [ - sessionStructureChainChainKey$json, - sessionStructureChainMessageKey$json - ], -}; - -@$core.Deprecated('Use sessionStructureDescriptor instead') -const sessionStructureChainChainKey$json = { - '1': 'ChainKey', - '2': [ - {'1': 'index', '3': 1, '4': 1, '5': 13, '10': 'index'}, - {'1': 'key', '3': 2, '4': 1, '5': 12, '10': 'key'}, - ], -}; - -@$core.Deprecated('Use sessionStructureDescriptor instead') -const sessionStructureChainMessageKey$json = { - '1': 'MessageKey', - '2': [ - {'1': 'index', '3': 1, '4': 1, '5': 13, '10': 'index'}, - {'1': 'cipherKey', '3': 2, '4': 1, '5': 12, '10': 'cipherKey'}, - {'1': 'macKey', '3': 3, '4': 1, '5': 12, '10': 'macKey'}, - {'1': 'iv', '3': 4, '4': 1, '5': 12, '10': 'iv'}, - ], -}; - -@$core.Deprecated('Use sessionStructureDescriptor instead') -const sessionStructurePendingKeyExchange$json = { - '1': 'PendingKeyExchange', - '2': [ - {'1': 'sequence', '3': 1, '4': 1, '5': 13, '10': 'sequence'}, - {'1': 'localBaseKey', '3': 2, '4': 1, '5': 12, '10': 'localBaseKey'}, - { - '1': 'localBaseKeyPrivate', - '3': 3, - '4': 1, - '5': 12, - '10': 'localBaseKeyPrivate' - }, - {'1': 'localRatchetKey', '3': 4, '4': 1, '5': 12, '10': 'localRatchetKey'}, - { - '1': 'localRatchetKeyPrivate', - '3': 5, - '4': 1, - '5': 12, - '10': 'localRatchetKeyPrivate' - }, - { - '1': 'localIdentityKey', - '3': 7, - '4': 1, - '5': 12, - '10': 'localIdentityKey' - }, - { - '1': 'localIdentityKeyPrivate', - '3': 8, - '4': 1, - '5': 12, - '10': 'localIdentityKeyPrivate' - }, - ], -}; - -@$core.Deprecated('Use sessionStructureDescriptor instead') -const sessionStructurePendingPreKey$json = { - '1': 'PendingPreKey', - '2': [ - {'1': 'preKeyId', '3': 1, '4': 1, '5': 13, '10': 'preKeyId'}, - {'1': 'signedPreKeyId', '3': 3, '4': 1, '5': 5, '10': 'signedPreKeyId'}, - {'1': 'baseKey', '3': 2, '4': 1, '5': 12, '10': 'baseKey'}, - ], -}; - -/// Descriptor for `SessionStructure`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List sessionStructureDescriptor = $convert.base64Decode( - 'ChBTZXNzaW9uU3RydWN0dXJlEiYKDnNlc3Npb25WZXJzaW9uGAEgASgNUg5zZXNzaW9uVmVyc2lvbhIwChNsb2NhbElkZW50aXR5UHVibGljGAIgASgMUhNsb2NhbElkZW50aXR5UHVibGljEjIKFHJlbW90ZUlkZW50aXR5UHVibGljGAMgASgMUhRyZW1vdGVJZGVudGl0eVB1YmxpYxIYCgdyb290S2V5GAQgASgMUgdyb290S2V5EigKD3ByZXZpb3VzQ291bnRlchgFIAEoDVIPcHJldmlvdXNDb3VudGVyEkQKC3NlbmRlckNoYWluGAYgASgLMiIudGV4dHNlY3VyZS5TZXNzaW9uU3RydWN0dXJlLkNoYWluUgtzZW5kZXJDaGFpbhJKCg5yZWNlaXZlckNoYWlucxgHIAMoCzIiLnRleHRzZWN1cmUuU2Vzc2lvblN0cnVjdHVyZS5DaGFpblIOcmVjZWl2ZXJDaGFpbnMSXwoScGVuZGluZ0tleUV4Y2hhbmdlGAggASgLMi8udGV4dHNlY3VyZS5TZXNzaW9uU3RydWN0dXJlLlBlbmRpbmdLZXlFeGNoYW5nZVIScGVuZGluZ0tleUV4Y2hhbmdlElAKDXBlbmRpbmdQcmVLZXkYCSABKAsyKi50ZXh0c2VjdXJlLlNlc3Npb25TdHJ1Y3R1cmUuUGVuZGluZ1ByZUtleVINcGVuZGluZ1ByZUtleRIyChRyZW1vdGVSZWdpc3RyYXRpb25JZBgKIAEoDVIUcmVtb3RlUmVnaXN0cmF0aW9uSWQSMAoTbG9jYWxSZWdpc3RyYXRpb25JZBgLIAEoDVITbG9jYWxSZWdpc3RyYXRpb25JZBIiCgxuZWVkc1JlZnJlc2gYDCABKAhSDG5lZWRzUmVmcmVzaBIiCgxhbGljZUJhc2VLZXkYDSABKAxSDGFsaWNlQmFzZUtleRqlAwoFQ2hhaW4SKgoQc2VuZGVyUmF0Y2hldEtleRgBIAEoDFIQc2VuZGVyUmF0Y2hldEtleRI4ChdzZW5kZXJSYXRjaGV0S2V5UHJpdmF0ZRgCIAEoDFIXc2VuZGVyUmF0Y2hldEtleVByaXZhdGUSRwoIY2hhaW5LZXkYAyABKAsyKy50ZXh0c2VjdXJlLlNlc3Npb25TdHJ1Y3R1cmUuQ2hhaW4uQ2hhaW5LZXlSCGNoYWluS2V5Ek8KC21lc3NhZ2VLZXlzGAQgAygLMi0udGV4dHNlY3VyZS5TZXNzaW9uU3RydWN0dXJlLkNoYWluLk1lc3NhZ2VLZXlSC21lc3NhZ2VLZXlzGjIKCENoYWluS2V5EhQKBWluZGV4GAEgASgNUgVpbmRleBIQCgNrZXkYAiABKAxSA2tleRpoCgpNZXNzYWdlS2V5EhQKBWluZGV4GAEgASgNUgVpbmRleBIcCgljaXBoZXJLZXkYAiABKAxSCWNpcGhlcktleRIWCgZtYWNLZXkYAyABKAxSBm1hY0tleRIOCgJpdhgEIAEoDFICaXYazgIKElBlbmRpbmdLZXlFeGNoYW5nZRIaCghzZXF1ZW5jZRgBIAEoDVIIc2VxdWVuY2USIgoMbG9jYWxCYXNlS2V5GAIgASgMUgxsb2NhbEJhc2VLZXkSMAoTbG9jYWxCYXNlS2V5UHJpdmF0ZRgDIAEoDFITbG9jYWxCYXNlS2V5UHJpdmF0ZRIoCg9sb2NhbFJhdGNoZXRLZXkYBCABKAxSD2xvY2FsUmF0Y2hldEtleRI2ChZsb2NhbFJhdGNoZXRLZXlQcml2YXRlGAUgASgMUhZsb2NhbFJhdGNoZXRLZXlQcml2YXRlEioKEGxvY2FsSWRlbnRpdHlLZXkYByABKAxSEGxvY2FsSWRlbnRpdHlLZXkSOAoXbG9jYWxJZGVudGl0eUtleVByaXZhdGUYCCABKAxSF2xvY2FsSWRlbnRpdHlLZXlQcml2YXRlGm0KDVBlbmRpbmdQcmVLZXkSGgoIcHJlS2V5SWQYASABKA1SCHByZUtleUlkEiYKDnNpZ25lZFByZUtleUlkGAMgASgFUg5zaWduZWRQcmVLZXlJZBIYCgdiYXNlS2V5GAIgASgMUgdiYXNlS2V5'); -@$core.Deprecated('Use recordStructureDescriptor instead') -const recordStructure$json = { - '1': 'RecordStructure', - '2': [ - { - '1': 'currentSession', - '3': 1, - '4': 1, - '5': 11, - '6': '.textsecure.SessionStructure', - '10': 'currentSession' - }, - { - '1': 'previousSessions', - '3': 2, - '4': 3, - '5': 11, - '6': '.textsecure.SessionStructure', - '10': 'previousSessions' - }, - ], -}; - -/// Descriptor for `RecordStructure`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List recordStructureDescriptor = $convert.base64Decode( - 'Cg9SZWNvcmRTdHJ1Y3R1cmUSRAoOY3VycmVudFNlc3Npb24YASABKAsyHC50ZXh0c2VjdXJlLlNlc3Npb25TdHJ1Y3R1cmVSDmN1cnJlbnRTZXNzaW9uEkgKEHByZXZpb3VzU2Vzc2lvbnMYAiADKAsyHC50ZXh0c2VjdXJlLlNlc3Npb25TdHJ1Y3R1cmVSEHByZXZpb3VzU2Vzc2lvbnM='); -@$core.Deprecated('Use preKeyRecordStructureDescriptor instead') -const preKeyRecordStructure$json = { - '1': 'PreKeyRecordStructure', - '2': [ - {'1': 'id', '3': 1, '4': 1, '5': 13, '10': 'id'}, - {'1': 'publicKey', '3': 2, '4': 1, '5': 12, '10': 'publicKey'}, - {'1': 'privateKey', '3': 3, '4': 1, '5': 12, '10': 'privateKey'}, - ], -}; - -/// Descriptor for `PreKeyRecordStructure`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List preKeyRecordStructureDescriptor = $convert.base64Decode( - 'ChVQcmVLZXlSZWNvcmRTdHJ1Y3R1cmUSDgoCaWQYASABKA1SAmlkEhwKCXB1YmxpY0tleRgCIAEoDFIJcHVibGljS2V5Eh4KCnByaXZhdGVLZXkYAyABKAxSCnByaXZhdGVLZXk='); -@$core.Deprecated('Use signedPreKeyRecordStructureDescriptor instead') -const signedPreKeyRecordStructure$json = { - '1': 'SignedPreKeyRecordStructure', - '2': [ - {'1': 'id', '3': 1, '4': 1, '5': 13, '10': 'id'}, - {'1': 'publicKey', '3': 2, '4': 1, '5': 12, '10': 'publicKey'}, - {'1': 'privateKey', '3': 3, '4': 1, '5': 12, '10': 'privateKey'}, - {'1': 'signature', '3': 4, '4': 1, '5': 12, '10': 'signature'}, - {'1': 'timestamp', '3': 5, '4': 1, '5': 6, '10': 'timestamp'}, - ], -}; - -/// Descriptor for `SignedPreKeyRecordStructure`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List signedPreKeyRecordStructureDescriptor = - $convert.base64Decode( - 'ChtTaWduZWRQcmVLZXlSZWNvcmRTdHJ1Y3R1cmUSDgoCaWQYASABKA1SAmlkEhwKCXB1YmxpY0tleRgCIAEoDFIJcHVibGljS2V5Eh4KCnByaXZhdGVLZXkYAyABKAxSCnByaXZhdGVLZXkSHAoJc2lnbmF0dXJlGAQgASgMUglzaWduYXR1cmUSHAoJdGltZXN0YW1wGAUgASgGUgl0aW1lc3RhbXA='); -@$core.Deprecated('Use identityKeyPairStructureDescriptor instead') -const identityKeyPairStructure$json = { - '1': 'IdentityKeyPairStructure', - '2': [ - {'1': 'publicKey', '3': 1, '4': 1, '5': 12, '10': 'publicKey'}, - {'1': 'privateKey', '3': 2, '4': 1, '5': 12, '10': 'privateKey'}, - ], -}; - -/// Descriptor for `IdentityKeyPairStructure`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List identityKeyPairStructureDescriptor = - $convert.base64Decode( - 'ChhJZGVudGl0eUtleVBhaXJTdHJ1Y3R1cmUSHAoJcHVibGljS2V5GAEgASgMUglwdWJsaWNLZXkSHgoKcHJpdmF0ZUtleRgCIAEoDFIKcHJpdmF0ZUtleQ=='); -@$core.Deprecated('Use senderKeyStateStructureDescriptor instead') -const senderKeyStateStructure$json = { - '1': 'SenderKeyStateStructure', - '2': [ - {'1': 'senderKeyId', '3': 1, '4': 1, '5': 13, '10': 'senderKeyId'}, - { - '1': 'senderChainKey', - '3': 2, - '4': 1, - '5': 11, - '6': '.textsecure.SenderKeyStateStructure.SenderChainKey', - '10': 'senderChainKey' - }, - { - '1': 'senderSigningKey', - '3': 3, - '4': 1, - '5': 11, - '6': '.textsecure.SenderKeyStateStructure.SenderSigningKey', - '10': 'senderSigningKey' - }, - { - '1': 'senderMessageKeys', - '3': 4, - '4': 3, - '5': 11, - '6': '.textsecure.SenderKeyStateStructure.SenderMessageKey', - '10': 'senderMessageKeys' - }, - ], - '3': [ - senderKeyStateStructureSenderChainKey$json, - senderKeyStateStructureSenderMessageKey$json, - senderKeyStateStructureSenderSigningKey$json - ], -}; - -@$core.Deprecated('Use senderKeyStateStructureDescriptor instead') -const senderKeyStateStructureSenderChainKey$json = { - '1': 'SenderChainKey', - '2': [ - {'1': 'iteration', '3': 1, '4': 1, '5': 13, '10': 'iteration'}, - {'1': 'seed', '3': 2, '4': 1, '5': 12, '10': 'seed'}, - ], -}; - -@$core.Deprecated('Use senderKeyStateStructureDescriptor instead') -const senderKeyStateStructureSenderMessageKey$json = { - '1': 'SenderMessageKey', - '2': [ - {'1': 'iteration', '3': 1, '4': 1, '5': 13, '10': 'iteration'}, - {'1': 'seed', '3': 2, '4': 1, '5': 12, '10': 'seed'}, - ], -}; - -@$core.Deprecated('Use senderKeyStateStructureDescriptor instead') -const senderKeyStateStructureSenderSigningKey$json = { - '1': 'SenderSigningKey', - '2': [ - {'1': 'public', '3': 1, '4': 1, '5': 12, '10': 'public'}, - {'1': 'private', '3': 2, '4': 1, '5': 12, '10': 'private'}, - ], -}; - -/// Descriptor for `SenderKeyStateStructure`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List senderKeyStateStructureDescriptor = - $convert.base64Decode( - 'ChdTZW5kZXJLZXlTdGF0ZVN0cnVjdHVyZRIgCgtzZW5kZXJLZXlJZBgBIAEoDVILc2VuZGVyS2V5SWQSWgoOc2VuZGVyQ2hhaW5LZXkYAiABKAsyMi50ZXh0c2VjdXJlLlNlbmRlcktleVN0YXRlU3RydWN0dXJlLlNlbmRlckNoYWluS2V5Ug5zZW5kZXJDaGFpbktleRJgChBzZW5kZXJTaWduaW5nS2V5GAMgASgLMjQudGV4dHNlY3VyZS5TZW5kZXJLZXlTdGF0ZVN0cnVjdHVyZS5TZW5kZXJTaWduaW5nS2V5UhBzZW5kZXJTaWduaW5nS2V5EmIKEXNlbmRlck1lc3NhZ2VLZXlzGAQgAygLMjQudGV4dHNlY3VyZS5TZW5kZXJLZXlTdGF0ZVN0cnVjdHVyZS5TZW5kZXJNZXNzYWdlS2V5UhFzZW5kZXJNZXNzYWdlS2V5cxpCCg5TZW5kZXJDaGFpbktleRIcCglpdGVyYXRpb24YASABKA1SCWl0ZXJhdGlvbhISCgRzZWVkGAIgASgMUgRzZWVkGkQKEFNlbmRlck1lc3NhZ2VLZXkSHAoJaXRlcmF0aW9uGAEgASgNUglpdGVyYXRpb24SEgoEc2VlZBgCIAEoDFIEc2VlZBpEChBTZW5kZXJTaWduaW5nS2V5EhYKBnB1YmxpYxgBIAEoDFIGcHVibGljEhgKB3ByaXZhdGUYAiABKAxSB3ByaXZhdGU='); -@$core.Deprecated('Use senderKeyRecordStructureDescriptor instead') -const senderKeyRecordStructure$json = { - '1': 'SenderKeyRecordStructure', - '2': [ - { - '1': 'senderKeyStates', - '3': 1, - '4': 3, - '5': 11, - '6': '.textsecure.SenderKeyStateStructure', - '10': 'senderKeyStates' - }, - ], -}; - -/// Descriptor for `SenderKeyRecordStructure`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List senderKeyRecordStructureDescriptor = - $convert.base64Decode( - 'ChhTZW5kZXJLZXlSZWNvcmRTdHJ1Y3R1cmUSTQoPc2VuZGVyS2V5U3RhdGVzGAEgAygLMiMudGV4dHNlY3VyZS5TZW5kZXJLZXlTdGF0ZVN0cnVjdHVyZVIPc2VuZGVyS2V5U3RhdGVz'); diff --git a/libsignal_protocol_dart/lib/src/state/local_storage_protocol.pbserver.dart b/libsignal_protocol_dart/lib/src/state/local_storage_protocol.pbserver.dart deleted file mode 100644 index b4dccdd..0000000 --- a/libsignal_protocol_dart/lib/src/state/local_storage_protocol.pbserver.dart +++ /dev/null @@ -1,7 +0,0 @@ -// Generated code. Do not modify. -// source: LocalStorageProtocol.proto -// -// @dart = 2.12 -// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package - -export 'local_storage_protocol.pb.dart'; diff --git a/libsignal_protocol_dart/lib/src/state/pre_key_bundle.dart b/libsignal_protocol_dart/lib/src/state/pre_key_bundle.dart deleted file mode 100644 index 6b0fe5e..0000000 --- a/libsignal_protocol_dart/lib/src/state/pre_key_bundle.dart +++ /dev/null @@ -1,45 +0,0 @@ -import 'dart:typed_data'; - -import '../ecc/ec_public_key.dart'; -import '../identity_key.dart'; - -class PreKeyBundle { - PreKeyBundle( - this._registrationId, - this._deviceId, - this._preKeyId, - this._preKeyPublic, - this._signedPreKeyId, - this._signedPreKeyPublic, - this._signedPreKeySignature, - this._identityKey); - - final int _registrationId; - - final int _deviceId; - - final int? _preKeyId; - final ECPublicKey? _preKeyPublic; - - final int _signedPreKeyId; - final ECPublicKey? _signedPreKeyPublic; - final Uint8List? _signedPreKeySignature; - - final IdentityKey _identityKey; - - int getDeviceId() => _deviceId; - - int? getPreKeyId() => _preKeyId; - - ECPublicKey? getPreKey() => _preKeyPublic; - - int getSignedPreKeyId() => _signedPreKeyId; - - ECPublicKey? getSignedPreKey() => _signedPreKeyPublic; - - Uint8List? getSignedPreKeySignature() => _signedPreKeySignature; - - IdentityKey getIdentityKey() => _identityKey; - - int getRegistrationId() => _registrationId; -} diff --git a/libsignal_protocol_dart/lib/src/state/pre_key_record.dart b/libsignal_protocol_dart/lib/src/state/pre_key_record.dart deleted file mode 100644 index 6635b7c..0000000 --- a/libsignal_protocol_dart/lib/src/state/pre_key_record.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'dart:typed_data'; -import '../ecc/curve.dart'; -import '../ecc/ec_key_pair.dart'; -import '../invalid_key_exception.dart'; -import 'local_storage_protocol.pb.dart'; - -class PreKeyRecord { - PreKeyRecord(int id, ECKeyPair keyPair) { - _structure = PreKeyRecordStructure.create() - ..id = id - ..publicKey = keyPair.publicKey.serialize() - ..privateKey = keyPair.privateKey.serialize() - ..toBuilder(); - } - - PreKeyRecord.fromBuffer(Uint8List serialized) { - _structure = PreKeyRecordStructure.fromBuffer(serialized); - } - - late PreKeyRecordStructure _structure; - - int get id => _structure.id; - - ECKeyPair getKeyPair() { - try { - final publicKey = - Curve.decodePoint(Uint8List.fromList(_structure.publicKey), 0); - final privateKey = - Curve.decodePrivatePoint(Uint8List.fromList(_structure.privateKey)); - return ECKeyPair(publicKey, privateKey); - } on InvalidKeyException catch (e) { - throw AssertionError(e); - } - } - - Uint8List serialize() => _structure.writeToBuffer(); -} diff --git a/libsignal_protocol_dart/lib/src/state/pre_key_store.dart b/libsignal_protocol_dart/lib/src/state/pre_key_store.dart deleted file mode 100644 index b88c78f..0000000 --- a/libsignal_protocol_dart/lib/src/state/pre_key_store.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'pre_key_record.dart'; - -abstract mixin class PreKeyStore { - Future loadPreKey( - int preKeyId); // throws InvalidKeyIdException; - - Future storePreKey(int preKeyId, PreKeyRecord record); - - Future containsPreKey(int preKeyId); - - Future removePreKey(int preKeyId); -} diff --git a/libsignal_protocol_dart/lib/src/state/session_record.dart b/libsignal_protocol_dart/lib/src/state/session_record.dart deleted file mode 100644 index 6f0694c..0000000 --- a/libsignal_protocol_dart/lib/src/state/session_record.dart +++ /dev/null @@ -1,86 +0,0 @@ -import 'dart:collection'; -import 'dart:typed_data'; - -import '../eq.dart'; -import 'local_storage_protocol.pb.dart'; -import 'session_state.dart'; - -class SessionRecord { - SessionRecord() { - _fresh = true; - } - - SessionRecord.fromSessionState(SessionState sessionState) { - _sessionState = sessionState; - _fresh = false; - } - - SessionRecord.fromSerialized(Uint8List serialized) { - final record = RecordStructure.fromBuffer(serialized); - _sessionState = SessionState.fromStructure(record.currentSession); - _fresh = false; - - for (final previousStructure in record.previousSessions) { - _previousStates.add(SessionState.fromStructure(previousStructure)); - } - } - - static const int archivedStatesMaxLength = 40; - var _sessionState = SessionState(); - final _previousStates = LinkedList(); - bool _fresh = false; - - bool hasSessionState(int version, Uint8List aliceBaseKey) { - if (_sessionState.getSessionVersion() == version && - eq(aliceBaseKey, _sessionState.aliceBaseKey)) { - return true; - } - - for (final state in _previousStates) { - if (state.getSessionVersion() == version && - eq(aliceBaseKey, _sessionState.aliceBaseKey)) { - return true; - } - } - return false; - } - - SessionState get sessionState => _sessionState; - - LinkedList get previousSessionStates => _previousStates; - - void removePreviousSessionStates() { - _previousStates.clear(); - } - - bool isFresh() => _fresh; - - void archiveCurrentState() { - promoteState(SessionState()); - } - - void promoteState(SessionState promotedState) { - _previousStates.addFirst(_sessionState); - _sessionState = promotedState; - - if (_previousStates.length > archivedStatesMaxLength) { - _previousStates.remove(_previousStates.last); - } - } - - set state(SessionState sessionState) { - _sessionState = sessionState; - } - - Uint8List serialize() { - final previousStructures = []; - for (final previousState in _previousStates) { - previousStructures.add(previousState.structure); - } - final record = RecordStructure.create() - ..currentSession = _sessionState.structure - ..previousSessions.addAll(previousStructures); - - return record.toBuilder().writeToBuffer(); - } -} diff --git a/libsignal_protocol_dart/lib/src/state/session_state.dart b/libsignal_protocol_dart/lib/src/state/session_state.dart deleted file mode 100644 index f5f7a4a..0000000 --- a/libsignal_protocol_dart/lib/src/state/session_state.dart +++ /dev/null @@ -1,399 +0,0 @@ -import 'dart:collection'; -import 'dart:typed_data'; - -import 'package:optional/optional.dart'; - -import '../ecc/curve.dart'; -import '../ecc/ec_key_pair.dart'; -import '../ecc/ec_public_key.dart'; -import '../entry.dart'; -import '../eq.dart'; -import '../identity_key.dart'; -import '../identity_key_pair.dart'; -import '../invalid_key_exception.dart'; -import '../kdf/hkdf.dart'; -import '../ratchet/chain_key.dart'; -import '../ratchet/message_keys.dart'; -import '../ratchet/root_key.dart'; -import '../util/log.dart' as $log; -import 'local_storage_protocol.pb.dart'; - -base class SessionState extends LinkedListEntry { - SessionState() { - _sessionStructure = SessionStructure.create(); - } - - SessionState.fromStructure(SessionStructure sessionStructure) { - _sessionStructure = sessionStructure; - } - - SessionState.fromSessionState(SessionState copy) { - _sessionStructure = copy.structure; - } - - static const int maxMessageKeys = 2000; - - late SessionStructure _sessionStructure; - - SessionStructure get structure => _sessionStructure; - - Uint8List get aliceBaseKey => - Uint8List.fromList(_sessionStructure.aliceBaseKey); - - set aliceBaseKey(Uint8List aliceBaseKey) { - _sessionStructure.aliceBaseKey = aliceBaseKey; - } - - set sessionVersion(int version) => _sessionStructure.sessionVersion = version; - - int getSessionVersion() { - final sessionVersion = _sessionStructure.sessionVersion; - if (sessionVersion == 0) { - return 2; - } else { - return sessionVersion; - } - } - - set remoteIdentityKey(IdentityKey identityKey) => - _sessionStructure.remoteIdentityPublic = identityKey.serialize(); - - set localIdentityKey(IdentityKey identityKey) => - _sessionStructure.localIdentityPublic = identityKey.serialize(); - - IdentityKey? getRemoteIdentityKey() { - try { - if (!_sessionStructure.hasRemoteIdentityPublic()) { - return null; - } - return IdentityKey.fromBytes( - Uint8List.fromList(_sessionStructure.remoteIdentityPublic), 0); - } on InvalidKeyException catch (e) { - $log.log(e); - return null; - } - } - - IdentityKey getLocalIdentityKey() { - try { - return IdentityKey.fromBytes( - Uint8List.fromList(_sessionStructure.localIdentityPublic), 0); - } on InvalidKeyException catch (e) { - throw AssertionError(e); - } - } - - int get previousCounter => _sessionStructure.previousCounter; - - set previousCounter(int previousCounter) => - _sessionStructure.previousCounter = previousCounter; - - RootKey getRootKey() => RootKey(HKDF.createFor(getSessionVersion()), - Uint8List.fromList(_sessionStructure.rootKey)); - - set rootKey(RootKey rootKey) => - _sessionStructure.rootKey = rootKey.getKeyBytes(); - - ECPublicKey getSenderRatchetKey() { - try { - return Curve.decodePoint( - Uint8List.fromList(_sessionStructure.senderChain.senderRatchetKey), - 0); - } on InvalidKeyException catch (e) { - throw AssertionError(e); - } - } - - ECKeyPair getSenderRatchetKeyPair() { - final publicKey = getSenderRatchetKey(); - final privateKey = Curve.decodePrivatePoint(Uint8List.fromList( - _sessionStructure.senderChain.senderRatchetKeyPrivate)); - return ECKeyPair(publicKey, privateKey); - } - - bool hasReceiverChain(ECPublicKey senderEphemeral) => - _getReceiverChain(senderEphemeral) != null; - - bool hasSenderChain() => _sessionStructure.hasSenderChain(); - - (SessionStructureChain, int)? _getReceiverChain(ECPublicKey senderEphemeral) { - final receiverChains = _sessionStructure.receiverChains; - var index = 0; - - for (final receiverChain in receiverChains) { - try { - final chainSenderRatchetKey = Curve.decodePoint( - Uint8List.fromList(receiverChain.senderRatchetKey), 0); - - if (eq( - chainSenderRatchetKey.serialize(), senderEphemeral.serialize())) { - return (receiverChain, index); - } - } on InvalidKeyException catch (e) { - $log.log(e); - } - index++; - } - - return null; - } - - ChainKey? getReceiverChainKey(ECPublicKey senderEphemeral) { - final receiverChainAndIndex = _getReceiverChain(senderEphemeral); - final receiverChain = receiverChainAndIndex?.$1; - - if (receiverChain == null) { - return null; - } else { - return ChainKey( - HKDF.createFor(getSessionVersion()), - Uint8List.fromList(receiverChain.chainKey.key), - receiverChain.chainKey.index); - } - } - - void addReceiverChain(ECPublicKey senderRatchetKey, ChainKey chainKey) { - final chainKeyStructure = SessionStructureChainChainKey.create() - ..key = chainKey.key; - - final chain = SessionStructureChain.create() - ..chainKey = chainKeyStructure - ..senderRatchetKey = senderRatchetKey.serialize(); - - _sessionStructure.receiverChains.add(chain); - - if (_sessionStructure.receiverChains.length > 5) { - _sessionStructure.receiverChains.removeAt(0); - } - } - - void setSenderChain(ECKeyPair senderRatchetKeyPair, ChainKey chainKey) { - final chainKeyStructure = SessionStructureChainChainKey.create() - ..key = chainKey.key - ..index = chainKey.index; - - final senderChain = SessionStructureChain.create() - ..senderRatchetKey = senderRatchetKeyPair.publicKey.serialize() - ..senderRatchetKeyPrivate = senderRatchetKeyPair.privateKey.serialize() - ..chainKey = chainKeyStructure; - _sessionStructure.senderChain = senderChain; - } - - ChainKey getSenderChainKey() { - final chainKeyStructure = _sessionStructure.senderChain.chainKey; - return ChainKey(HKDF.createFor(getSessionVersion()), - Uint8List.fromList(chainKeyStructure.key), chainKeyStructure.index); - } - - void setSenderChainKey(ChainKey nextChainKey) { - final chainKey = SessionStructureChainChainKey.create() - ..key = nextChainKey.key - ..index = nextChainKey.index; - - _sessionStructure.senderChain.chainKey = chainKey; - } - - bool hasMessageKeys(ECPublicKey senderEphemeral, int counter) { - final chainAndIndex = _getReceiverChain(senderEphemeral); - if (chainAndIndex == null) { - return false; - } - final chain = chainAndIndex.$1; - - final messageKeyList = chain.messageKeys; - for (final messageKey in messageKeyList) { - if (messageKey.index == counter) { - return true; - } - } - return false; - } - - MessageKeys? removeMessageKeys(ECPublicKey senderEphemeral, int counter) { - final chainAndIndex = _getReceiverChain(senderEphemeral); - if (chainAndIndex == null) { - return null; - } - final chain = chainAndIndex.$1; - - final messageKeyList = LinkedList>(); - chain.messageKeys.forEach((element) { - messageKeyList.add(Entry(element)); - }); - final messageKeyIterator = messageKeyList.iterator; - MessageKeys? result; - while (messageKeyIterator.moveNext()) { - final entry = messageKeyIterator.current; - final messageKey = entry.value; - if (messageKey.index == counter) { - final cipherKey = Uint8List.fromList(messageKey.cipherKey); - final macKey = Uint8List.fromList(messageKey.macKey); - final iv = Uint8List.fromList(messageKey.iv); - final index = messageKey.index; - result = MessageKeys(cipherKey, macKey, iv, index); - - messageKeyList.remove(entry); - break; - } - } - - chain.messageKeys.clear(); - messageKeyList.forEach((entry) { - chain.messageKeys.add(entry.value); - }); - - _sessionStructure.receiverChains - .setAll(chainAndIndex.$2, [chain]); - return result; - } - - void setMessageKeys(ECPublicKey senderEphemeral, MessageKeys messageKeys) { - final chainAndIndex = _getReceiverChain(senderEphemeral); - if (chainAndIndex == null) { - return; - } - final chain = chainAndIndex.$1; - final messageKeyStructure = SessionStructureChainMessageKey.create() - ..cipherKey = Uint8List.fromList(messageKeys.getCipherKey()) - ..macKey = Uint8List.fromList(messageKeys.getMacKey()) - ..index = messageKeys.getCounter() - ..iv = Uint8List.fromList(messageKeys.getIv()); - - chain.messageKeys.add(messageKeyStructure); - - if (chain.messageKeys.length > maxMessageKeys) { - chain.messageKeys.removeAt(0); - } - - _sessionStructure.receiverChains - .setAll(chainAndIndex.$2, [chain]); - } - - void setReceiverChainKey(ECPublicKey senderEphemeral, ChainKey chainKey) { - final chainAndIndex = _getReceiverChain(senderEphemeral); - final chain = chainAndIndex!.$1; - - final chainKeyStructure = SessionStructureChainChainKey.create() - ..key = chainKey.key - ..index = chainKey.index; - - chain.chainKey = chainKeyStructure; - _sessionStructure.receiverChains - .setAll(chainAndIndex.$2, [chain]); - } - - void setPendingKeyExchange(int sequence, ECKeyPair ourBaseKey, - ECKeyPair ourRatchetKey, IdentityKeyPair ourIdentityKey) { - final structure = SessionStructurePendingKeyExchange.create() - ..sequence = sequence - ..localBaseKey = ourBaseKey.publicKey.serialize() - ..localBaseKeyPrivate = ourBaseKey.privateKey.serialize() - ..localRatchetKey = ourRatchetKey.publicKey.serialize() - ..localRatchetKeyPrivate = ourRatchetKey.privateKey.serialize() - ..localIdentityKey = ourIdentityKey.getPublicKey().serialize() - ..localIdentityKeyPrivate = ourIdentityKey.getPrivateKey().serialize(); - - _sessionStructure.pendingKeyExchange = structure; - } - - int getPendingKeyExchangeSequence() => - _sessionStructure.pendingKeyExchange.sequence; - - ECKeyPair getPendingKeyExchangeBaseKey() { - final publicKey = Curve.decodePoint( - Uint8List.fromList(_sessionStructure.pendingKeyExchange.localBaseKey), - 0); - - final privateKey = Curve.decodePrivatePoint(Uint8List.fromList( - _sessionStructure.pendingKeyExchange.localBaseKeyPrivate)); - - return ECKeyPair(publicKey, privateKey); - } - - ECKeyPair getPendingKeyExchangeRatchetKey() { - final publicKey = Curve.decodePointList( - _sessionStructure.pendingKeyExchange.localRatchetKey, 0); - - final privateKey = Curve.decodePrivatePoint(Uint8List.fromList( - _sessionStructure.pendingKeyExchange.localRatchetKeyPrivate)); - - return ECKeyPair(publicKey, privateKey); - } - - IdentityKeyPair getPendingKeyExchangeIdentityKey() { - final publicKey = IdentityKey.fromBytes( - Uint8List.fromList( - _sessionStructure.pendingKeyExchange.localIdentityKey), - 0); - final privateKey = Curve.decodePrivatePoint(Uint8List.fromList( - _sessionStructure.pendingKeyExchange.localIdentityKeyPrivate)); - return IdentityKeyPair(publicKey, privateKey); - } - - bool hasPendingKeyExchange() => _sessionStructure.hasPendingKeyExchange(); - - void setUnacknowledgedPreKeyMessage( - Optional preKeyId, int signedPreKeyId, ECPublicKey baseKey) { - final pending = SessionStructurePendingPreKey.create() - ..signedPreKeyId = signedPreKeyId - ..baseKey = baseKey.serialize(); - - if (preKeyId.isPresent) { - pending.preKeyId = preKeyId.value; - } - - _sessionStructure.pendingPreKey = pending; - } - - bool hasUnacknowledgedPreKeyMessage() => _sessionStructure.hasPendingPreKey(); - - UnacknowledgedPreKeyMessageItems getUnacknowledgedPreKeyMessageItems() { - try { - Optional preKeyId; - - if (_sessionStructure.pendingPreKey.hasPreKeyId()) { - preKeyId = Optional.of(_sessionStructure.pendingPreKey.preKeyId); - } else { - preKeyId = const Optional.empty(); - } - - return UnacknowledgedPreKeyMessageItems( - preKeyId, - _sessionStructure.pendingPreKey.signedPreKeyId, - Curve.decodePointList(_sessionStructure.pendingPreKey.baseKey, 0)); - } on InvalidKeyException catch (e) { - throw AssertionError(e); - } - } - - void clearUnacknowledgedPreKeyMessage() { - _sessionStructure.clearPendingPreKey(); - } - - set remoteRegistrationId(int registrationId) => - _sessionStructure..remoteRegistrationId = registrationId; - - int get remoteRegistrationId => _sessionStructure.remoteRegistrationId; - - set localRegistrationId(int registrationId) => - _sessionStructure.localRegistrationId = registrationId; - - int get localRegistrationId => _sessionStructure.localRegistrationId; - - Uint8List serialize() => _sessionStructure.writeToBuffer(); -} - -class UnacknowledgedPreKeyMessageItems { - UnacknowledgedPreKeyMessageItems( - this._preKeyId, this._signedPreKeyId, this._baseKey); - - final Optional _preKeyId; - final int _signedPreKeyId; - final ECPublicKey _baseKey; - - Optional getPreKeyId() => _preKeyId; - - int getSignedPreKeyId() => _signedPreKeyId; - - ECPublicKey getBaseKey() => _baseKey; -} diff --git a/libsignal_protocol_dart/lib/src/state/session_store.dart b/libsignal_protocol_dart/lib/src/state/session_store.dart deleted file mode 100644 index dce4ee8..0000000 --- a/libsignal_protocol_dart/lib/src/state/session_store.dart +++ /dev/null @@ -1,18 +0,0 @@ -import '../signal_protocol_address.dart'; - -import 'session_record.dart'; - -abstract mixin class SessionStore { - Future loadSession(SignalProtocolAddress address); - - Future> getSubDeviceSessions(String name); - - Future storeSession( - SignalProtocolAddress address, SessionRecord record); - - Future containsSession(SignalProtocolAddress address); - - Future deleteSession(SignalProtocolAddress address); - - Future deleteAllSessions(String name); -} diff --git a/libsignal_protocol_dart/lib/src/state/signal_protocol_store.dart b/libsignal_protocol_dart/lib/src/state/signal_protocol_store.dart deleted file mode 100644 index ad8312d..0000000 --- a/libsignal_protocol_dart/lib/src/state/signal_protocol_store.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'identity_key_store.dart'; -import 'pre_key_store.dart'; -import 'session_store.dart'; -import 'signed_pre_key_store.dart'; - -abstract class SignalProtocolStore extends IdentityKeyStore - with PreKeyStore, SessionStore, SignedPreKeyStore {} diff --git a/libsignal_protocol_dart/lib/src/state/signed_pre_key_record.dart b/libsignal_protocol_dart/lib/src/state/signed_pre_key_record.dart deleted file mode 100644 index 50e68cc..0000000 --- a/libsignal_protocol_dart/lib/src/state/signed_pre_key_record.dart +++ /dev/null @@ -1,45 +0,0 @@ -import 'dart:typed_data'; - -import 'package:fixnum/fixnum.dart'; -import '../ecc/curve.dart'; -import '../ecc/ec_key_pair.dart'; -import '../invalid_key_exception.dart'; -import 'local_storage_protocol.pb.dart'; - -class SignedPreKeyRecord { - SignedPreKeyRecord( - int id, Int64 timestamp, ECKeyPair keyPair, Uint8List signature) { - _structure = SignedPreKeyRecordStructure.create() - ..id = id - ..timestamp = timestamp - ..publicKey = keyPair.publicKey.serialize() - ..privateKey = keyPair.privateKey.serialize() - ..signature = signature; - } - - SignedPreKeyRecord.fromSerialized(Uint8List serialized) { - _structure = SignedPreKeyRecordStructure.fromBuffer(serialized); - } - - late SignedPreKeyRecordStructure _structure; - - int get id => _structure.id; - - Int64 get timestamp => _structure.timestamp; - - ECKeyPair getKeyPair() { - try { - final publicKey = Curve.decodePointList(_structure.publicKey, 0); - final privateKey = - Curve.decodePrivatePoint(Uint8List.fromList(_structure.privateKey)); - - return ECKeyPair(publicKey, privateKey); - } on InvalidKeyException catch (e) { - throw AssertionError(e); - } - } - - Uint8List get signature => Uint8List.fromList(_structure.signature); - - Uint8List serialize() => _structure.writeToBuffer(); -} diff --git a/libsignal_protocol_dart/lib/src/state/signed_pre_key_store.dart b/libsignal_protocol_dart/lib/src/state/signed_pre_key_store.dart deleted file mode 100644 index 2374e9e..0000000 --- a/libsignal_protocol_dart/lib/src/state/signed_pre_key_store.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'signed_pre_key_record.dart'; - -abstract mixin class SignedPreKeyStore { - Future loadSignedPreKey( - int signedPreKeyId, - ); //throws InvalidKeyIdException; - - Future> loadSignedPreKeys(); - - Future storeSignedPreKey(int signedPreKeyId, SignedPreKeyRecord record); - - Future containsSignedPreKey(int signedPreKeyId); - - Future removeSignedPreKey(int signedPreKeyId); -} diff --git a/libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pb.dart b/libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pb.dart deleted file mode 100644 index 6d1ac37..0000000 --- a/libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pb.dart +++ /dev/null @@ -1,938 +0,0 @@ -import 'dart:core' as $core; -import 'dart:core'; - -import 'package:protobuf/protobuf.dart' as $pb; - -class SignalMessage extends $pb.GeneratedMessage { - factory SignalMessage({ - $core.List<$core.int>? ratchetKey, - $core.int? counter, - $core.int? previousCounter, - $core.List<$core.int>? ciphertext, - }) { - final _result = create(); - if (ratchetKey != null) { - _result.ratchetKey = ratchetKey; - } - if (counter != null) { - _result.counter = counter; - } - if (previousCounter != null) { - _result.previousCounter = previousCounter; - } - if (ciphertext != null) { - _result.ciphertext = ciphertext; - } - return _result; - } - - SignalMessage._() : super(); - - factory SignalMessage.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SignalMessage.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SignalMessage', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.List<$core.int>>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'ratchetKey', - $pb.PbFieldType.OY, - protoName: 'ratchetKey') - ..a<$core.int>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'counter', - $pb.PbFieldType.OU3) - ..a<$core.int>( - 3, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'previousCounter', - $pb.PbFieldType.OU3, - protoName: 'previousCounter') - ..a<$core.List<$core.int>>( - 4, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'ciphertext', - $pb.PbFieldType.OY) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SignalMessage clone() => SignalMessage()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SignalMessage copyWith(void Function(SignalMessage) updates) => - super.copyWith((message) => updates(message as SignalMessage)) - as SignalMessage; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SignalMessage create() => SignalMessage._(); - - @override - SignalMessage createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SignalMessage getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static SignalMessage? _defaultInstance; - - @$pb.TagNumber(1) - $core.List<$core.int> get ratchetKey => $_getN(0); - - @$pb.TagNumber(1) - set ratchetKey($core.List<$core.int> v) { - $_setBytes(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasRatchetKey() => $_has(0); - - @$pb.TagNumber(1) - void clearRatchetKey() => clearField(1); - - @$pb.TagNumber(2) - $core.int get counter => $_getIZ(1); - - @$pb.TagNumber(2) - set counter($core.int v) { - $_setUnsignedInt32(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasCounter() => $_has(1); - - @$pb.TagNumber(2) - void clearCounter() => clearField(2); - - @$pb.TagNumber(3) - $core.int get previousCounter => $_getIZ(2); - - @$pb.TagNumber(3) - set previousCounter($core.int v) { - $_setUnsignedInt32(2, v); - } - - @$pb.TagNumber(3) - $core.bool hasPreviousCounter() => $_has(2); - - @$pb.TagNumber(3) - void clearPreviousCounter() => clearField(3); - - @$pb.TagNumber(4) - $core.List<$core.int> get ciphertext => $_getN(3); - - @$pb.TagNumber(4) - set ciphertext($core.List<$core.int> v) { - $_setBytes(3, v); - } - - @$pb.TagNumber(4) - $core.bool hasCiphertext() => $_has(3); - - @$pb.TagNumber(4) - void clearCiphertext() => clearField(4); -} - -class PreKeySignalMessage extends $pb.GeneratedMessage { - factory PreKeySignalMessage({ - $core.int? preKeyId, - $core.List<$core.int>? baseKey, - $core.List<$core.int>? identityKey, - $core.List<$core.int>? message, - $core.int? registrationId, - $core.int? signedPreKeyId, - }) { - final _result = create(); - if (preKeyId != null) { - _result.preKeyId = preKeyId; - } - if (baseKey != null) { - _result.baseKey = baseKey; - } - if (identityKey != null) { - _result.identityKey = identityKey; - } - if (message != null) { - _result.message = message; - } - if (registrationId != null) { - _result.registrationId = registrationId; - } - if (signedPreKeyId != null) { - _result.signedPreKeyId = signedPreKeyId; - } - return _result; - } - - PreKeySignalMessage._() : super(); - - factory PreKeySignalMessage.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory PreKeySignalMessage.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'PreKeySignalMessage', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'preKeyId', - $pb.PbFieldType.OU3, - protoName: 'preKeyId') - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'baseKey', - $pb.PbFieldType.OY, - protoName: 'baseKey') - ..a<$core.List<$core.int>>( - 3, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'identityKey', - $pb.PbFieldType.OY, - protoName: 'identityKey') - ..a<$core.List<$core.int>>( - 4, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'message', - $pb.PbFieldType.OY) - ..a<$core.int>( - 5, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'registrationId', - $pb.PbFieldType.OU3, - protoName: 'registrationId') - ..a<$core.int>( - 6, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'signedPreKeyId', - $pb.PbFieldType.OU3, - protoName: 'signedPreKeyId') - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - PreKeySignalMessage clone() => PreKeySignalMessage()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - PreKeySignalMessage copyWith(void Function(PreKeySignalMessage) updates) => - super.copyWith((message) => updates(message as PreKeySignalMessage)) - as PreKeySignalMessage; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static PreKeySignalMessage create() => PreKeySignalMessage._(); - - @override - PreKeySignalMessage createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static PreKeySignalMessage getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static PreKeySignalMessage? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get preKeyId => $_getIZ(0); - - @$pb.TagNumber(1) - set preKeyId($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasPreKeyId() => $_has(0); - - @$pb.TagNumber(1) - void clearPreKeyId() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get baseKey => $_getN(1); - - @$pb.TagNumber(2) - set baseKey($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasBaseKey() => $_has(1); - - @$pb.TagNumber(2) - void clearBaseKey() => clearField(2); - - @$pb.TagNumber(3) - $core.List<$core.int> get identityKey => $_getN(2); - - @$pb.TagNumber(3) - set identityKey($core.List<$core.int> v) { - $_setBytes(2, v); - } - - @$pb.TagNumber(3) - $core.bool hasIdentityKey() => $_has(2); - - @$pb.TagNumber(3) - void clearIdentityKey() => clearField(3); - - @$pb.TagNumber(4) - $core.List<$core.int> get message => $_getN(3); - - @$pb.TagNumber(4) - set message($core.List<$core.int> v) { - $_setBytes(3, v); - } - - @$pb.TagNumber(4) - $core.bool hasMessage() => $_has(3); - - @$pb.TagNumber(4) - void clearMessage() => clearField(4); - - @$pb.TagNumber(5) - $core.int get registrationId => $_getIZ(4); - - @$pb.TagNumber(5) - set registrationId($core.int v) { - $_setUnsignedInt32(4, v); - } - - @$pb.TagNumber(5) - $core.bool hasRegistrationId() => $_has(4); - - @$pb.TagNumber(5) - void clearRegistrationId() => clearField(5); - - @$pb.TagNumber(6) - $core.int get signedPreKeyId => $_getIZ(5); - - @$pb.TagNumber(6) - set signedPreKeyId($core.int v) { - $_setUnsignedInt32(5, v); - } - - @$pb.TagNumber(6) - $core.bool hasSignedPreKeyId() => $_has(5); - - @$pb.TagNumber(6) - void clearSignedPreKeyId() => clearField(6); -} - -class KeyExchangeMessage extends $pb.GeneratedMessage { - factory KeyExchangeMessage({ - $core.int? id, - $core.List<$core.int>? baseKey, - $core.List<$core.int>? ratchetKey, - $core.List<$core.int>? identityKey, - $core.List<$core.int>? baseKeySignature, - }) { - final _result = create(); - if (id != null) { - _result.id = id; - } - if (baseKey != null) { - _result.baseKey = baseKey; - } - if (ratchetKey != null) { - _result.ratchetKey = ratchetKey; - } - if (identityKey != null) { - _result.identityKey = identityKey; - } - if (baseKeySignature != null) { - _result.baseKeySignature = baseKeySignature; - } - return _result; - } - - KeyExchangeMessage._() : super(); - - factory KeyExchangeMessage.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory KeyExchangeMessage.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'KeyExchangeMessage', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'id', - $pb.PbFieldType.OU3) - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'baseKey', - $pb.PbFieldType.OY, - protoName: 'baseKey') - ..a<$core.List<$core.int>>( - 3, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'ratchetKey', - $pb.PbFieldType.OY, - protoName: 'ratchetKey') - ..a<$core.List<$core.int>>( - 4, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'identityKey', - $pb.PbFieldType.OY, - protoName: 'identityKey') - ..a<$core.List<$core.int>>( - 5, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'baseKeySignature', - $pb.PbFieldType.OY, - protoName: 'baseKeySignature') - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - KeyExchangeMessage clone() => KeyExchangeMessage()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - KeyExchangeMessage copyWith(void Function(KeyExchangeMessage) updates) => - super.copyWith((message) => updates(message as KeyExchangeMessage)) - as KeyExchangeMessage; // ignore: deprecated_member_use - - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static KeyExchangeMessage create() => KeyExchangeMessage._(); - - @override - KeyExchangeMessage createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static KeyExchangeMessage getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static KeyExchangeMessage? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get id => $_getIZ(0); - - @$pb.TagNumber(1) - set id($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasId() => $_has(0); - - @$pb.TagNumber(1) - void clearId() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get baseKey => $_getN(1); - - @$pb.TagNumber(2) - set baseKey($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasBaseKey() => $_has(1); - - @$pb.TagNumber(2) - void clearBaseKey() => clearField(2); - - @$pb.TagNumber(3) - $core.List<$core.int> get ratchetKey => $_getN(2); - - @$pb.TagNumber(3) - set ratchetKey($core.List<$core.int> v) { - $_setBytes(2, v); - } - - @$pb.TagNumber(3) - $core.bool hasRatchetKey() => $_has(2); - - @$pb.TagNumber(3) - void clearRatchetKey() => clearField(3); - - @$pb.TagNumber(4) - $core.List<$core.int> get identityKey => $_getN(3); - - @$pb.TagNumber(4) - set identityKey($core.List<$core.int> v) { - $_setBytes(3, v); - } - - @$pb.TagNumber(4) - $core.bool hasIdentityKey() => $_has(3); - - @$pb.TagNumber(4) - void clearIdentityKey() => clearField(4); - - @$pb.TagNumber(5) - $core.List<$core.int> get baseKeySignature => $_getN(4); - - @$pb.TagNumber(5) - set baseKeySignature($core.List<$core.int> v) { - $_setBytes(4, v); - } - - @$pb.TagNumber(5) - $core.bool hasBaseKeySignature() => $_has(4); - - @$pb.TagNumber(5) - void clearBaseKeySignature() => clearField(5); -} - -class SenderKeyMessage extends $pb.GeneratedMessage { - factory SenderKeyMessage({ - $core.int? id, - $core.int? iteration, - $core.List<$core.int>? ciphertext, - }) { - final _result = create(); - if (id != null) { - _result.id = id; - } - if (iteration != null) { - _result.iteration = iteration; - } - if (ciphertext != null) { - _result.ciphertext = ciphertext; - } - return _result; - } - - SenderKeyMessage._() : super(); - - factory SenderKeyMessage.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SenderKeyMessage.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SenderKeyMessage', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'id', - $pb.PbFieldType.OU3) - ..a<$core.int>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'iteration', - $pb.PbFieldType.OU3) - ..a<$core.List<$core.int>>( - 3, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'ciphertext', - $pb.PbFieldType.OY) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SenderKeyMessage clone() => SenderKeyMessage()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SenderKeyMessage copyWith(void Function(SenderKeyMessage) updates) => - super.copyWith((message) => updates(message as SenderKeyMessage)) - as SenderKeyMessage; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SenderKeyMessage create() => SenderKeyMessage._(); - - @override - SenderKeyMessage createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SenderKeyMessage getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static SenderKeyMessage? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get id => $_getIZ(0); - - @$pb.TagNumber(1) - set id($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasId() => $_has(0); - - @$pb.TagNumber(1) - void clearId() => clearField(1); - - @$pb.TagNumber(2) - $core.int get iteration => $_getIZ(1); - - @$pb.TagNumber(2) - set iteration($core.int v) { - $_setUnsignedInt32(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasIteration() => $_has(1); - - @$pb.TagNumber(2) - void clearIteration() => clearField(2); - - @$pb.TagNumber(3) - $core.List<$core.int> get ciphertext => $_getN(2); - - @$pb.TagNumber(3) - set ciphertext($core.List<$core.int> v) { - $_setBytes(2, v); - } - - @$pb.TagNumber(3) - $core.bool hasCiphertext() => $_has(2); - - @$pb.TagNumber(3) - void clearCiphertext() => clearField(3); -} - -class SenderKeyDistributionMessage extends $pb.GeneratedMessage { - factory SenderKeyDistributionMessage({ - $core.int? id, - $core.int? iteration, - $core.List<$core.int>? chainKey, - $core.List<$core.int>? signingKey, - }) { - final _result = create(); - if (id != null) { - _result.id = id; - } - if (iteration != null) { - _result.iteration = iteration; - } - if (chainKey != null) { - _result.chainKey = chainKey; - } - if (signingKey != null) { - _result.signingKey = signingKey; - } - return _result; - } - - SenderKeyDistributionMessage._() : super(); - - factory SenderKeyDistributionMessage.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory SenderKeyDistributionMessage.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'SenderKeyDistributionMessage', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'id', - $pb.PbFieldType.OU3) - ..a<$core.int>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'iteration', - $pb.PbFieldType.OU3) - ..a<$core.List<$core.int>>( - 3, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'chainKey', - $pb.PbFieldType.OY, - protoName: 'chainKey') - ..a<$core.List<$core.int>>( - 4, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'signingKey', - $pb.PbFieldType.OY, - protoName: 'signingKey') - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - SenderKeyDistributionMessage clone() => - SenderKeyDistributionMessage()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - SenderKeyDistributionMessage copyWith( - void Function(SenderKeyDistributionMessage) updates) => - super.copyWith( - (message) => updates(message as SenderKeyDistributionMessage)) - as SenderKeyDistributionMessage; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static SenderKeyDistributionMessage create() => - SenderKeyDistributionMessage._(); - - @override - SenderKeyDistributionMessage createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static SenderKeyDistributionMessage getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static SenderKeyDistributionMessage? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get id => $_getIZ(0); - - @$pb.TagNumber(1) - set id($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasId() => $_has(0); - - @$pb.TagNumber(1) - void clearId() => clearField(1); - - @$pb.TagNumber(2) - $core.int get iteration => $_getIZ(1); - - @$pb.TagNumber(2) - set iteration($core.int v) { - $_setUnsignedInt32(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasIteration() => $_has(1); - - @$pb.TagNumber(2) - void clearIteration() => clearField(2); - - @$pb.TagNumber(3) - $core.List<$core.int> get chainKey => $_getN(2); - - @$pb.TagNumber(3) - set chainKey($core.List<$core.int> v) { - $_setBytes(2, v); - } - - @$pb.TagNumber(3) - $core.bool hasChainKey() => $_has(2); - - @$pb.TagNumber(3) - void clearChainKey() => clearField(3); - - @$pb.TagNumber(4) - $core.List<$core.int> get signingKey => $_getN(3); - - @$pb.TagNumber(4) - set signingKey($core.List<$core.int> v) { - $_setBytes(3, v); - } - - @$pb.TagNumber(4) - $core.bool hasSigningKey() => $_has(3); - - @$pb.TagNumber(4) - void clearSigningKey() => clearField(4); -} - -class DeviceConsistencyCodeMessage extends $pb.GeneratedMessage { - factory DeviceConsistencyCodeMessage({ - $core.int? generation, - $core.List<$core.int>? signature, - }) { - final _result = create(); - if (generation != null) { - _result.generation = generation; - } - if (signature != null) { - _result.signature = signature; - } - return _result; - } - - DeviceConsistencyCodeMessage._() : super(); - - factory DeviceConsistencyCodeMessage.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - - factory DeviceConsistencyCodeMessage.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - const $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'DeviceConsistencyCodeMessage', - package: const $pb.PackageName( - $core.bool.fromEnvironment('protobuf.omit_message_names') - ? '' - : 'textsecure'), - createEmptyInstance: create) - ..a<$core.int>( - 1, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'generation', - $pb.PbFieldType.OU3) - ..a<$core.List<$core.int>>( - 2, - const $core.bool.fromEnvironment('protobuf.omit_field_names') - ? '' - : 'signature', - $pb.PbFieldType.OY) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - @override - DeviceConsistencyCodeMessage clone() => - DeviceConsistencyCodeMessage()..mergeFromMessage(this); - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - @override - DeviceConsistencyCodeMessage copyWith( - void Function(DeviceConsistencyCodeMessage) updates) => - super.copyWith( - (message) => updates(message as DeviceConsistencyCodeMessage)) - as DeviceConsistencyCodeMessage; // ignore: deprecated_member_use - @override - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static DeviceConsistencyCodeMessage create() => - DeviceConsistencyCodeMessage._(); - - @override - DeviceConsistencyCodeMessage createEmptyInstance() => create(); - - @$core.pragma('dart2js:noInline') - static DeviceConsistencyCodeMessage getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static DeviceConsistencyCodeMessage? _defaultInstance; - - @$pb.TagNumber(1) - $core.int get generation => $_getIZ(0); - - @$pb.TagNumber(1) - set generation($core.int v) { - $_setUnsignedInt32(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasGeneration() => $_has(0); - - @$pb.TagNumber(1) - void clearGeneration() => clearField(1); - - @$pb.TagNumber(2) - $core.List<$core.int> get signature => $_getN(1); - - @$pb.TagNumber(2) - set signature($core.List<$core.int> v) { - $_setBytes(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasSignature() => $_has(1); - - @$pb.TagNumber(2) - void clearSignature() => clearField(2); -} diff --git a/libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pbenum.dart b/libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pbenum.dart deleted file mode 100644 index 74caa45..0000000 --- a/libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pbenum.dart +++ /dev/null @@ -1,5 +0,0 @@ -// Generated code. Do not modify. -// source: WhisperTextProtocol.proto -// -// @dart = 2.12 -// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields diff --git a/libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pbjson.dart b/libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pbjson.dart deleted file mode 100644 index 18ccbc3..0000000 --- a/libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pbjson.dart +++ /dev/null @@ -1,96 +0,0 @@ -import 'dart:convert' as $convert; -import 'dart:core' as $core; -import 'dart:typed_data' as $typed_data; - -@$core.Deprecated('Use signalMessageDescriptor instead') -const signalMessage$json = { - '1': 'SignalMessage', - '2': [ - {'1': 'ratchetKey', '3': 1, '4': 1, '5': 12, '10': 'ratchetKey'}, - {'1': 'counter', '3': 2, '4': 1, '5': 13, '10': 'counter'}, - {'1': 'previousCounter', '3': 3, '4': 1, '5': 13, '10': 'previousCounter'}, - {'1': 'ciphertext', '3': 4, '4': 1, '5': 12, '10': 'ciphertext'}, - ], -}; - -/// Descriptor for `SignalMessage`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List signalMessageDescriptor = $convert.base64Decode( - 'Cg1TaWduYWxNZXNzYWdlEh4KCnJhdGNoZXRLZXkYASABKAxSCnJhdGNoZXRLZXkSGAoHY291bnRlchgCIAEoDVIHY291bnRlchIoCg9wcmV2aW91c0NvdW50ZXIYAyABKA1SD3ByZXZpb3VzQ291bnRlchIeCgpjaXBoZXJ0ZXh0GAQgASgMUgpjaXBoZXJ0ZXh0'); -@$core.Deprecated('Use preKeySignalMessageDescriptor instead') -const preKeySignalMessage$json = { - '1': 'PreKeySignalMessage', - '2': [ - {'1': 'registrationId', '3': 5, '4': 1, '5': 13, '10': 'registrationId'}, - {'1': 'preKeyId', '3': 1, '4': 1, '5': 13, '10': 'preKeyId'}, - {'1': 'signedPreKeyId', '3': 6, '4': 1, '5': 13, '10': 'signedPreKeyId'}, - {'1': 'baseKey', '3': 2, '4': 1, '5': 12, '10': 'baseKey'}, - {'1': 'identityKey', '3': 3, '4': 1, '5': 12, '10': 'identityKey'}, - {'1': 'message', '3': 4, '4': 1, '5': 12, '10': 'message'}, - ], -}; - -/// Descriptor for `PreKeySignalMessage`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List preKeySignalMessageDescriptor = $convert.base64Decode( - 'ChNQcmVLZXlTaWduYWxNZXNzYWdlEiYKDnJlZ2lzdHJhdGlvbklkGAUgASgNUg5yZWdpc3RyYXRpb25JZBIaCghwcmVLZXlJZBgBIAEoDVIIcHJlS2V5SWQSJgoOc2lnbmVkUHJlS2V5SWQYBiABKA1SDnNpZ25lZFByZUtleUlkEhgKB2Jhc2VLZXkYAiABKAxSB2Jhc2VLZXkSIAoLaWRlbnRpdHlLZXkYAyABKAxSC2lkZW50aXR5S2V5EhgKB21lc3NhZ2UYBCABKAxSB21lc3NhZ2U='); -@$core.Deprecated('Use keyExchangeMessageDescriptor instead') -const keyExchangeMessage$json = { - '1': 'KeyExchangeMessage', - '2': [ - {'1': 'id', '3': 1, '4': 1, '5': 13, '10': 'id'}, - {'1': 'baseKey', '3': 2, '4': 1, '5': 12, '10': 'baseKey'}, - {'1': 'ratchetKey', '3': 3, '4': 1, '5': 12, '10': 'ratchetKey'}, - {'1': 'identityKey', '3': 4, '4': 1, '5': 12, '10': 'identityKey'}, - { - '1': 'baseKeySignature', - '3': 5, - '4': 1, - '5': 12, - '10': 'baseKeySignature' - }, - ], -}; - -/// Descriptor for `KeyExchangeMessage`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List keyExchangeMessageDescriptor = $convert.base64Decode( - 'ChJLZXlFeGNoYW5nZU1lc3NhZ2USDgoCaWQYASABKA1SAmlkEhgKB2Jhc2VLZXkYAiABKAxSB2Jhc2VLZXkSHgoKcmF0Y2hldEtleRgDIAEoDFIKcmF0Y2hldEtleRIgCgtpZGVudGl0eUtleRgEIAEoDFILaWRlbnRpdHlLZXkSKgoQYmFzZUtleVNpZ25hdHVyZRgFIAEoDFIQYmFzZUtleVNpZ25hdHVyZQ=='); -@$core.Deprecated('Use senderKeyMessageDescriptor instead') -const senderKeyMessage$json = { - '1': 'SenderKeyMessage', - '2': [ - {'1': 'id', '3': 1, '4': 1, '5': 13, '10': 'id'}, - {'1': 'iteration', '3': 2, '4': 1, '5': 13, '10': 'iteration'}, - {'1': 'ciphertext', '3': 3, '4': 1, '5': 12, '10': 'ciphertext'}, - ], -}; - -/// Descriptor for `SenderKeyMessage`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List senderKeyMessageDescriptor = $convert.base64Decode( - 'ChBTZW5kZXJLZXlNZXNzYWdlEg4KAmlkGAEgASgNUgJpZBIcCglpdGVyYXRpb24YAiABKA1SCWl0ZXJhdGlvbhIeCgpjaXBoZXJ0ZXh0GAMgASgMUgpjaXBoZXJ0ZXh0'); -@$core.Deprecated('Use senderKeyDistributionMessageDescriptor instead') -const senderKeyDistributionMessage$json = { - '1': 'SenderKeyDistributionMessage', - '2': [ - {'1': 'id', '3': 1, '4': 1, '5': 13, '10': 'id'}, - {'1': 'iteration', '3': 2, '4': 1, '5': 13, '10': 'iteration'}, - {'1': 'chainKey', '3': 3, '4': 1, '5': 12, '10': 'chainKey'}, - {'1': 'signingKey', '3': 4, '4': 1, '5': 12, '10': 'signingKey'}, - ], -}; - -/// Descriptor for `SenderKeyDistributionMessage`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List senderKeyDistributionMessageDescriptor = - $convert.base64Decode( - 'ChxTZW5kZXJLZXlEaXN0cmlidXRpb25NZXNzYWdlEg4KAmlkGAEgASgNUgJpZBIcCglpdGVyYXRpb24YAiABKA1SCWl0ZXJhdGlvbhIaCghjaGFpbktleRgDIAEoDFIIY2hhaW5LZXkSHgoKc2lnbmluZ0tleRgEIAEoDFIKc2lnbmluZ0tleQ=='); -@$core.Deprecated('Use deviceConsistencyCodeMessageDescriptor instead') -const deviceConsistencyCodeMessage$json = { - '1': 'DeviceConsistencyCodeMessage', - '2': [ - {'1': 'generation', '3': 1, '4': 1, '5': 13, '10': 'generation'}, - {'1': 'signature', '3': 2, '4': 1, '5': 12, '10': 'signature'}, - ], -}; - -/// Descriptor for `DeviceConsistencyCodeMessage`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List deviceConsistencyCodeMessageDescriptor = - $convert.base64Decode( - 'ChxEZXZpY2VDb25zaXN0ZW5jeUNvZGVNZXNzYWdlEh4KCmdlbmVyYXRpb24YASABKA1SCmdlbmVyYXRpb24SHAoJc2lnbmF0dXJlGAIgASgMUglzaWduYXR1cmU='); diff --git a/libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pbserver.dart b/libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pbserver.dart deleted file mode 100644 index 1705a8b..0000000 --- a/libsignal_protocol_dart/lib/src/state/whisper_text_protocol.pbserver.dart +++ /dev/null @@ -1,7 +0,0 @@ -// Generated code. Do not modify. -// source: WhisperTextProtocol.proto -// -// @dart = 2.12 -// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package - -export 'whisper_text_protocol.pb.dart'; diff --git a/libsignal_protocol_dart/lib/src/untrusted_identity_exception.dart b/libsignal_protocol_dart/lib/src/untrusted_identity_exception.dart deleted file mode 100644 index 702a6b1..0000000 --- a/libsignal_protocol_dart/lib/src/untrusted_identity_exception.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'identity_key.dart'; - -class UntrustedIdentityException implements Exception { - UntrustedIdentityException(this.name, this.key); - - final String name; - final IdentityKey? key; -} diff --git a/libsignal_protocol_dart/lib/src/util/byte_util.dart b/libsignal_protocol_dart/lib/src/util/byte_util.dart deleted file mode 100644 index 52b0325..0000000 --- a/libsignal_protocol_dart/lib/src/util/byte_util.dart +++ /dev/null @@ -1,86 +0,0 @@ -import 'dart:typed_data'; - -import 'package:adaptive_number/adaptive_number.dart'; -import 'package:convert/convert.dart'; - -class ByteUtil { - static Uint8List combine(List elements) { - final results = []; - elements.forEach(results.addAll); - return Uint8List.fromList(results); - } - - static Uint8List shortToByteArray(int value) { - final bytes = Uint8List(2); - bytes[0] = value >> 8; - bytes[1] = value; - return bytes; - } - - static Uint8List intToByteArray(int value) { - final bytes = Uint8List(4); - bytes[0] = value >> 24; - bytes[1] = value >> 16; - bytes[2] = value >> 8; - bytes[3] = value; - return bytes; - } - - static Uint8List trim(Uint8List input, int length) => - input.sublist(0, length); - - static List splitTwo( - Uint8List input, int firstLength, int secondLength) { - final first = input.sublist(0, firstLength); - final second = input.sublist(firstLength, firstLength + secondLength); - return [first, second]; - } - - static List split( - Uint8List input, int firstLength, int secondLength, int thirdLength) { - if (firstLength < 0 || - secondLength < 0 || - thirdLength < 0 || - input.length < firstLength + secondLength + thirdLength) { - throw Exception('Input too small: ${hex.encode(input)}'); - } - final first = input.sublist(0, firstLength); - final second = input.sublist(firstLength, firstLength + secondLength); - final third = input.sublist( - firstLength + secondLength, firstLength + secondLength + thirdLength); - return [first, second, third]; - } - - static int intsToByteHighAndLow(int highValue, int lowValue) => - ((highValue << 4) | lowValue) & 0xFF; - - static int highBitsToInt(int value) => (value & 0xFF) >> 4; - - static int lowBitsToInt(int value) => value & 0xF; - - static int highBitsToMedium(int value) => value >> 12; - - static int lowBitsToMedium(int value) => value & 0xFFF; - - static int byteArray5ToLong(Uint8List bytes, int offset) { - final v1 = (Number(bytes[offset]) & Number(0xff)) << 32; - final v2 = (Number(bytes[offset + 1]) & Number(0xff)) << 24; - final v3 = (Number(bytes[offset + 2]) & Number(0xff)) << 16; - final v4 = (Number(bytes[offset + 3]) & Number(0xff)) << 8; - final v5 = Number(bytes[offset + 4]) & Number(0xff); - return (v1 | v2 | v3 | v4 | v5).intValue; - } - - static int compare(Uint8List left, Uint8List right) { - for (var i = 0, j = 0; i < left.length && j < right.length; i++, j++) { - final a = left[i] & 0xff; - final b = right[j] & 0xff; - - if (a != b) { - return a - b; - } - } - - return left.length - right.length; - } -} diff --git a/libsignal_protocol_dart/lib/src/util/identity_key_comparator.dart b/libsignal_protocol_dart/lib/src/util/identity_key_comparator.dart deleted file mode 100644 index dccd3af..0000000 --- a/libsignal_protocol_dart/lib/src/util/identity_key_comparator.dart +++ /dev/null @@ -1,5 +0,0 @@ -import '../identity_key.dart'; -import 'byte_util.dart'; - -int identityKeyComparator(IdentityKey a, IdentityKey b) => - ByteUtil.compare(a.publicKey.serialize(), b.publicKey.serialize()); diff --git a/libsignal_protocol_dart/lib/src/util/key_helper.dart b/libsignal_protocol_dart/lib/src/util/key_helper.dart deleted file mode 100644 index 6ea8555..0000000 --- a/libsignal_protocol_dart/lib/src/util/key_helper.dart +++ /dev/null @@ -1,69 +0,0 @@ -import 'dart:math'; -import 'dart:typed_data'; - -import 'package:fixnum/fixnum.dart'; - -import '../ecc/curve.dart'; -import '../ecc/ec_key_pair.dart'; -import '../identity_key.dart'; -import '../identity_key_pair.dart'; -import '../state/pre_key_record.dart'; -import '../state/signed_pre_key_record.dart'; -import 'medium.dart'; - -IdentityKeyPair generateIdentityKeyPair() { - final keyPair = Curve.generateKeyPair(); - final publicKey = IdentityKey(keyPair.publicKey); - return IdentityKeyPair(publicKey, keyPair.privateKey); -} - -IdentityKeyPair generateIdentityKeyPairFromPrivate(List private) { - final keyPair = Curve.generateKeyPairFromPrivate(private); - final publicKey = IdentityKey(keyPair.publicKey); - return IdentityKeyPair(publicKey, keyPair.privateKey); -} - -int integerMax = 0x7fffffff; - -// ignore: avoid_positional_boolean_parameters -int generateRegistrationId(bool extendedRange) { - if (extendedRange) { - return _random.nextInt(integerMax - 1) + 1; - } else { - return _random.nextInt(16380) + 1; - } -} - -List generatePreKeys(int start, int count) { - final results = []; - // ignore: parameter_assignments - start--; - for (var i = 0; i < count; i++) { - results.add(PreKeyRecord( - ((start + i).remainder(maxValue - 1)) + 1, Curve.generateKeyPair())); - } - return results; -} - -SignedPreKeyRecord generateSignedPreKey( - IdentityKeyPair identityKeyPair, int signedPreKeyId) { - final keyPair = Curve.generateKeyPair(); - final signature = Curve.calculateSignature( - identityKeyPair.getPrivateKey(), keyPair.publicKey.serialize()); - - return SignedPreKeyRecord(signedPreKeyId, - Int64(DateTime.now().millisecondsSinceEpoch), keyPair, signature); -} - -ECKeyPair generateSenderSigningKey() => Curve.generateKeyPair(); - -Uint8List generateSenderKey() => generateRandomBytes(); - -int generateSenderKeyId() => _random.nextInt(integerMax); - -final Random _random = Random.secure(); - -Uint8List generateRandomBytes([int length = 32]) { - final values = List.generate(length, (i) => _random.nextInt(256)); - return Uint8List.fromList(values); -} diff --git a/libsignal_protocol_dart/lib/src/util/log.dart b/libsignal_protocol_dart/lib/src/util/log.dart deleted file mode 100644 index 1fb28a8..0000000 --- a/libsignal_protocol_dart/lib/src/util/log.dart +++ /dev/null @@ -1,8 +0,0 @@ -bool enabled = false; - -void log(Object? object) { - if (enabled) { - // ignore: avoid_print - print(object); - } -} diff --git a/libsignal_protocol_dart/lib/src/util/medium.dart b/libsignal_protocol_dart/lib/src/util/medium.dart deleted file mode 100644 index 95ce4df..0000000 --- a/libsignal_protocol_dart/lib/src/util/medium.dart +++ /dev/null @@ -1 +0,0 @@ -const int maxValue = 0xFFFFFF; diff --git a/libsignal_protocol_dart/pubspec.yaml b/libsignal_protocol_dart/pubspec.yaml deleted file mode 100644 index 573f8db..0000000 --- a/libsignal_protocol_dart/pubspec.yaml +++ /dev/null @@ -1,28 +0,0 @@ -name: libsignal_protocol_dart -description: Signal Protocol libray for Dart native and Flutter, pure Dart implementation of the the Signal Protocol -version: 0.8.0 -repository: https://github.com/MixinNetwork/libsignal_protocol_dart -topics: - - crypto - -environment: - sdk: '>=3.4.0 <4.0.0' - - -dependencies: - adaptive_number: ^1.0.0 - collection: ^1.19.0 - convert: ^3.1.2 - crypto: ^3.0.6 - ed25519_edwards: ^0.3.1 - fixnum: ^1.1.1 - meta: ^1.16.0 - optional: ^6.1.0+1 - pointycastle: ^4.0.0 - protobuf: ^6.0.0 - x25519: ^0.1.1 - - -dev_dependencies: - test: ^1.25.8 - very_good_analysis: ^10.2.0 diff --git a/optional/LICENSE b/optional/LICENSE deleted file mode 100644 index de74683..0000000 --- a/optional/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2014, Juan Antonio Ramírez -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the -following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following -disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following -disclaimer in the documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/optional/lib/optional.dart b/optional/lib/optional.dart deleted file mode 100644 index 321da3c..0000000 --- a/optional/lib/optional.dart +++ /dev/null @@ -1,10 +0,0 @@ -/// An implementation of the Optional type. -library optional; - -export 'optional_internal.dart' - show - Optional, - OptionalExtension, - OptionalIterableExtension, - NoValuePresentError, - empty; diff --git a/optional/lib/optional_internal.dart b/optional/lib/optional_internal.dart deleted file mode 100644 index 03b1e8e..0000000 --- a/optional/lib/optional_internal.dart +++ /dev/null @@ -1,98 +0,0 @@ -library optional_internal; - -import 'dart:async'; -import 'package:collection/collection.dart'; - -part 'src/absent.dart'; -part 'src/present.dart'; -part 'src/novaluepresent.dart'; -part 'src/extension.dart'; - -/// A constant, absent Optional. -const Optional empty = _Absent(); - -/// A container object which may contain a non-null value. -/// -/// Offers several methods which depend on the presence or absence of a contained value. -abstract class Optional implements Iterable { - /// Creates a new Optional with the given non-null value. - /// - /// Throws [ArgumentError] if value is null. - factory Optional.of(T value) { - if (value == null) { - throw ArgumentError('value must be non-null'); - } else { - return _Present(value); - } - } - - /// Creates a new Optional with the given value, if non-null. Otherwise, returns an empty Optional. - factory Optional.ofNullable(T? value) { - if (value == null) { - return empty.cast(); - } else { - return _Present(value); - } - } - - /// Creates an empty Optional. - const factory Optional.empty() = _Absent._internal; - - /// The value associated with this Optional, if any. - /// - /// Throws [NoValuePresentError] if no value is present. - T get value; - - /// Whether the Optional has a value. - bool get isPresent; - - /// Returns an Optional with this Optional's value, if there is a value present and it matches the predicate. Otherwise, returns an empty Optional. - Optional filter(bool Function(T) predicate); - - /// Returns an Optional provided by applying the mapper to this Optional's value, if present. Otherwise, returns an empty Optional. - Optional flatMap(Optional Function(T) mapper); - - /// Returns an Optional containing the result of applying the mapper to this Optional's value, if present. Otherwise, returns an empty Optional. - /// - /// If the mapper returns a null value, returns an empty Optional. - @override - Optional map(R Function(T) mapper); - - /// Returns this Optional's value, if present. Otherwise, returns other. - T orElse(T other); - - /// Returns this Optional's value, if present, as nullable. Otherwise, returns other. - T? orElseNullable(T? other); - - /// Returns this Optional's value, if present, as nullable. Otherwise, returns null. - T? get orElseNull; - - /// Returns this Optional's value, if present. Otherwise, returns the result of calling supply(). - T orElseGet(T Function() supply); - - /// Returns this Optional's value, if present, as nullable. Otherwise, returns the result of calling supply(). - T? orElseGetNullable(T? Function() supply); - - /// Returns this Optional's value, if present. Otherwise, returns the result of calling supply() asynchronously. - Future orElseGetAsync(Future Function() supply); - - /// Returns this Optional's value, if present, as nullable. Otherwise, returns the result of calling supply() asynchronously. - Future orElseGetNullableAsync(Future Function() supply); - - /// Returns this Optional's value, if present. Otherwise, throws the result of calling supplyError(). - T orElseThrow(Object Function() supplyError); - - /// Invokes consume() with this Optional's value, if present. Otherwise, if orElse is passed, invokes it, otherwise does nothing. - void ifPresent(void Function(T) consume, {void Function() orElse}); - - /// The hashCode of this Optional's value, if present. Otherwise, 0. - @override - int get hashCode; - - @override - bool operator ==(Object other); - - /// Returns a view of this Optional as an Optional with an [R] value - @override - Optional cast(); -} diff --git a/optional/lib/src/absent.dart b/optional/lib/src/absent.dart deleted file mode 100644 index dce71e4..0000000 --- a/optional/lib/src/absent.dart +++ /dev/null @@ -1,78 +0,0 @@ -part of optional_internal; - -class _Absent extends Iterable implements Optional { - const _Absent(); - - const _Absent._internal(); - - @override - T get value => throw NoValuePresentError(); - - @override - int get length => 0; - - @override - bool get isPresent => false; - - @override - Optional filter(bool Function(T) predicate) => empty.cast(); - - @override - Optional flatMap(Optional Function(T) mapper) => empty.cast(); - - @override - Optional map(R Function(T) mapper) => empty.cast(); - - @override - bool contains(Object? val) => false; - - @override - T orElse(T other) => other; - - @override - T? orElseNullable(T? other) => other; - - @override - T? get orElseNull => null; - - @override - T orElseGet(T Function() supply) => supply(); - - @override - T? orElseGetNullable(T? Function() supply) => supply(); - - @override - Future orElseGetAsync(Future Function() supply) => supply(); - - @override - Future orElseGetNullableAsync(Future Function() supply) async => - supply(); - - @override - T orElseThrow(Object Function() supplyError) => throw supplyError(); - - @override - void ifPresent(void Function(T) consume, {void Function()? orElse}) => - orElse == null ? null : orElse(); - - @override - int get hashCode => 0; - - @override - bool operator ==(Object other) => other is _Absent; - - @override - String toString() => 'Optional[empty]'; - - @override - Optional cast() => _Absent(); - - @override - bool get isEmpty => true; - - @override - bool get isNotEmpty => false; - - @override - Iterator get iterator => UnmodifiableSetView.empty().iterator; -} diff --git a/optional/lib/src/extension.dart b/optional/lib/src/extension.dart deleted file mode 100644 index 5dce547..0000000 --- a/optional/lib/src/extension.dart +++ /dev/null @@ -1,125 +0,0 @@ -part of optional_internal; - -extension OptionalExtension on T { - /// Returns an Optional with `this` as its value - Optional get toOptional => Optional.of(this); -} - -/// Extensions that apply to all iterables. -extension OptionalIterableExtension on Iterable { - /// The first element satisfying [test], or `Optional.empty()` if there are none. - Optional firstWhereOptional(bool Function(T element) test) { - for (var element in this) { - if (test(element)) return Optional.of(element); - } - return Optional.empty(); - } - - /// The first element whose value and index satisfies [test]. - /// - /// Returns `Optional.empty()` if there are no element and index satisfying [test]. - Optional firstWhereIndexedOptional( - bool Function(int index, T element) test) { - var index = 0; - for (var element in this) { - if (test(index++, element)) return Optional.of(element); - } - return Optional.empty(); - } - - /// The first element, or `Optional.empty()` if the iterable is empty. - Optional get firstOptional { - var iterator = this.iterator; - if (iterator.moveNext()) return Optional.of(iterator.current); - return Optional.empty(); - } - - /// The last element satisfying [test], or `Optional.empty()` if there are none. - Optional lastWhereOptional(bool Function(T element) test) { - T? result; - for (var element in this) { - if (test(element)) result = element; - } - return Optional.ofNullable(result); - } - - /// The last element whose index and value satisfies [test]. - /// - /// Returns `Optional.empty()` if no element and index satisfies [test]. - Optional lastWhereIndexedOptional( - bool Function(int index, T element) test) { - T? result; - var index = 0; - for (var element in this) { - if (test(index++, element)) result = element; - } - return Optional.ofNullable(result); - } - - /// The last element, or `Optional.empty()` if the iterable is empty. - Optional get lastOptional { - if (isEmpty) return Optional.empty(); - return Optional.of(last); - } - - /// The single element satisfying [test]. - /// - /// Returns `Optional.empty()` if there are either no elements - /// or more than one element satisfying [test]. - /// - /// **Notice**: This behavior differs from [Iterable.singleWhere] - /// which always throws if there are more than one match, - /// and only calls the `orElse` function on zero matchs. - Optional singleWhereOptional(bool Function(T element) test) { - T? result; - var found = false; - for (var element in this) { - if (test(element)) { - if (!found) { - result = element; - found = true; - } else { - return Optional.empty(); - } - } - } - return Optional.ofNullable(result); - } - - /// The single element satisfying [test]. - /// - /// Returns `Optional.empty()` if there are either none - /// or more than one element and index satisfying [test]. - Optional singleWhereIndexedOptional( - bool Function(int index, T element) test) { - T? result; - var found = false; - var index = 0; - for (var element in this) { - if (test(index++, element)) { - if (!found) { - result = element; - found = true; - } else { - return Optional.empty(); - } - } - } - return Optional.ofNullable(result); - } - - /// The single element of the iterable, or `Optional.empty()`. - /// - /// The value is `Optional.empty()` if the iterable is empty - /// or it contains more than one element. - Optional get singleOptional { - var iterator = this.iterator; - if (iterator.moveNext()) { - var result = iterator.current; - if (!iterator.moveNext()) { - return Optional.of(result); - } - } - return Optional.empty(); - } -} diff --git a/optional/lib/src/novaluepresent.dart b/optional/lib/src/novaluepresent.dart deleted file mode 100644 index 9030961..0000000 --- a/optional/lib/src/novaluepresent.dart +++ /dev/null @@ -1,7 +0,0 @@ -part of optional_internal; - -/// Error thrown when attempting to operate on an empty Optional's value. -class NoValuePresentError extends StateError { - /// Creates a new NoValuePresentError with a message reading "no value present" - NoValuePresentError() : super('no value present'); -} diff --git a/optional/lib/src/present.dart b/optional/lib/src/present.dart deleted file mode 100644 index db39b2c..0000000 --- a/optional/lib/src/present.dart +++ /dev/null @@ -1,85 +0,0 @@ -part of optional_internal; - -class _Present extends Iterable implements Optional { - const _Present(this._value); - - final T _value; - - @override - T get value => _value; - - @override - int get length => 1; - - @override - bool get isPresent => true; - - @override - Optional filter(bool Function(T) predicate) { - if (predicate(_value)) { - return this; - } else { - return empty.cast(); - } - } - - @override - Optional flatMap(Optional Function(T) mapper) => mapper(_value); - - @override - Optional map(R Function(T) mapper) => - Optional.ofNullable(mapper(_value)); - - @override - bool contains(Object? val) => _value == val; - - @override - T orElse(T other) => _value; - - @override - T? orElseNullable(T? other) => _value; - - @override - T? get orElseNull => _value; - - @override - T orElseGet(T Function() supply) => _value; - - @override - T? orElseGetNullable(T? Function() supply) => _value; - - @override - Future orElseGetAsync(Future Function() supply) async => _value; - - @override - Future orElseGetNullableAsync(Future Function() supply) async => - _value; - - @override - T orElseThrow(Object Function() supplyError) => _value; - - @override - void ifPresent(void Function(T) consume, {void Function()? orElse}) => - consume(_value); - - @override - int get hashCode => _value.hashCode; - - @override - bool operator ==(Object other) => other is _Present && other._value == _value; - - @override - String toString() => 'Optional[value: $_value]'; - - @override - Optional cast() => _Present(value as R); - - @override - bool get isEmpty => false; - - @override - bool get isNotEmpty => true; - - @override - Iterator get iterator => UnmodifiableSetView({_value}).iterator; -} diff --git a/optional/pubspec.yaml b/optional/pubspec.yaml deleted file mode 100644 index 605e5b1..0000000 --- a/optional/pubspec.yaml +++ /dev/null @@ -1,15 +0,0 @@ -name: optional -version: 6.1.0+1 -description: An implementation of the Optional type, which helps avoid dealing with null references -homepage: https://github.com/tonio-ramirez/optional.dart -repository: https://github.com/tonio-ramirez/optional.dart -environment: - sdk: '>=2.12.0 <3.0.0' -dependencies: - collection: ^1.15.0 -dev_dependencies: - mockito: '>=5.0.0 <6.0.0' - test: ^1.16.5 - pedantic: ^1.11.0 - build_runner: '>=1.10.0 <2.0.0' - coverage: ^1.0.3 diff --git a/pointycastle/LICENSE b/pointycastle/LICENSE deleted file mode 100644 index 5928ef3..0000000 --- a/pointycastle/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ - -Copyright (c) 2000 - 2019 The Legion of the Bouncy Castle Inc. (https://www.bouncycastle.org) - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/pointycastle/lib/adapters/stream_cipher_as_block_cipher.dart b/pointycastle/lib/adapters/stream_cipher_as_block_cipher.dart deleted file mode 100644 index e1a671d..0000000 --- a/pointycastle/lib/adapters/stream_cipher_as_block_cipher.dart +++ /dev/null @@ -1,37 +0,0 @@ -// See file LICENSE for more information. - -library impl.adapters.stream_cipher_as_block_cipher; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_block_cipher.dart'; - -/// An adapter to convert an [StreamCipher] to a [BlockCipher] -class StreamCipherAsBlockCipher extends BaseBlockCipher { - final StreamCipher streamCipher; - @override - final int blockSize; - - /// Create a [BlockCipher] from [streamCipher] simulating the given [blockSize] - StreamCipherAsBlockCipher(this.blockSize, this.streamCipher); - - @override - String get algorithmName => streamCipher.algorithmName; - - @override - void reset() { - streamCipher.reset(); - } - - @override - void init(bool forEncryption, CipherParameters? params) { - streamCipher.init(forEncryption, params); - } - - @override - int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { - streamCipher.processBytes(inp, inpOff, blockSize, out, outOff); - return blockSize; - } -} diff --git a/pointycastle/lib/api.dart b/pointycastle/lib/api.dart deleted file mode 100644 index 352a25e..0000000 --- a/pointycastle/lib/api.dart +++ /dev/null @@ -1,53 +0,0 @@ -// See file LICENSE for more information. - -/// This is the API specification library for the Pointy Castle project. -/// -/// It declares all abstract types used by the Pointy Castle library. -/// In addition, it implements the factories mechanism that allows -/// users to instantiate algorithms by their standard name. -library; - -import 'dart:typed_data'; - -import 'src/registry/registry.dart'; -import 'src/utils.dart'; - -part 'src/api/aead_block_cipher.dart'; -part 'src/api/aead_cipher.dart'; -part 'src/api/aead_parameters.dart'; -part 'src/api/algorithm.dart'; -part 'src/api/asymmetric_block_cipher.dart'; -part 'src/api/asymmetric_key.dart'; -part 'src/api/asymmetric_key_pair.dart'; -part 'src/api/asymmetric_key_parameter.dart'; -part 'src/api/block_cipher.dart'; -part 'src/api/cipher_parameters.dart'; -part 'src/api/des_parameters.dart'; -part 'src/api/desede_parameters.dart'; -part 'src/api/digest.dart'; -part 'src/api/key_derivator.dart'; -part 'src/api/key_generator.dart'; -part 'src/api/key_generator_parameters.dart'; -part 'src/api/key_parameter.dart'; -part 'src/api/mac.dart'; -part 'src/api/padded_block_cipher.dart'; -part 'src/api/padded_block_cipher_parameters.dart'; -part 'src/api/padding.dart'; -part 'src/api/parameters_with_iv.dart'; -part 'src/api/parameters_with_random.dart'; -part 'src/api/parameters_with_salt.dart'; -part 'src/api/parameters_with_salt_configuration.dart'; -part 'src/api/pbe_parameters_generator.dart'; -part 'src/api/private_key.dart'; -part 'src/api/private_key_parameter.dart'; -part 'src/api/public_key.dart'; -part 'src/api/public_key_parameter.dart'; -part 'src/api/rc2_parameters.dart'; -part 'src/api/registry_factory_exception.dart'; -part 'src/api/secure_random.dart'; -part 'src/api/signature.dart'; -part 'src/api/signer.dart'; -part 'src/api/srp_client.dart'; -part 'src/api/srp_server.dart'; -part 'src/api/stream_cipher.dart'; -part 'src/api/xof.dart'; diff --git a/pointycastle/lib/asn1.dart b/pointycastle/lib/asn1.dart deleted file mode 100644 index 906a288..0000000 --- a/pointycastle/lib/asn1.dart +++ /dev/null @@ -1,60 +0,0 @@ -library asn1; - -export 'asn1/asn1_encoding_rule.dart'; -export 'asn1/asn1_object.dart'; -export 'asn1/asn1_parser.dart'; -export 'asn1/asn1_tags.dart'; -export 'asn1/asn1_utils.dart'; -export 'asn1/primitives/asn1_bit_string.dart'; -export 'asn1/primitives/asn1_boolean.dart'; -export 'asn1/primitives/asn1_enumerated.dart'; -export 'asn1/primitives/asn1_generalized_time.dart'; -export 'asn1/primitives/asn1_ia5_string.dart'; -export 'asn1/primitives/asn1_integer.dart'; -export 'asn1/primitives/asn1_null.dart'; -export 'asn1/primitives/asn1_object_identifier.dart'; -export 'asn1/primitives/asn1_octet_string.dart'; -export 'asn1/primitives/asn1_printable_string.dart'; -export 'asn1/primitives/asn1_sequence.dart'; -export 'asn1/primitives/asn1_set.dart'; -export 'asn1/primitives/asn1_teletext_string.dart'; -export 'asn1/primitives/asn1_bmp_string.dart'; -export 'asn1/primitives/asn1_utc_time.dart'; -export 'asn1/primitives/asn1_utf8_string.dart'; -export 'asn1/unsupported_asn1_encoding_rule_exception.dart'; -export 'asn1/unsupported_asn1_tag_exception.dart'; - -// X501 -export 'asn1/x501/asn1_attribute_type_and_value.dart'; -export 'asn1/x501/asn1_name.dart'; -export 'asn1/x501/asn1_rdn.dart'; - -// X509 -export 'asn1/x509/asn1_algorithm_identifier.dart'; - -// PKCS7 -export 'asn1/pkcs/pkcs1/asn1_digest_info.dart'; - -// PKCS7 -export 'asn1/pkcs/pkcs7/asn1_content_info.dart'; -export 'asn1/pkcs/pkcs7/asn1_encrypted_content_info.dart'; - -// PKCS8 -export 'asn1/pkcs/pkcs8/asn1_encrypted_data.dart'; -export 'asn1/pkcs/pkcs8/asn1_encrypted_private_key_info.dart'; -export 'asn1/pkcs/pkcs8/asn1_private_key_info.dart'; - -// PKCS10 -export 'asn1/pkcs/pkcs10/asn1_certification_request.dart'; -export 'asn1/pkcs/pkcs10/asn1_subject_public_key_info.dart'; -export 'asn1/pkcs/pkcs10/asn1_certification_request_info.dart'; - -// PKCS12 -export 'asn1/pkcs/pkcs12/asn1_authenticated_safe.dart'; -export 'asn1/pkcs/pkcs12/asn1_cert_bag.dart'; -export 'asn1/pkcs/pkcs12/asn1_key_bag.dart'; -export 'asn1/pkcs/pkcs12/asn1_mac_data.dart'; -export 'asn1/pkcs/pkcs12/asn1_pfx.dart'; -export 'asn1/pkcs/pkcs12/asn1_pkcs12_attribute.dart'; -export 'asn1/pkcs/pkcs12/asn1_safe_bag.dart'; -export 'asn1/pkcs/pkcs12/asn1_safe_contents.dart'; diff --git a/pointycastle/lib/asn1/asn1_encoding_rule.dart b/pointycastle/lib/asn1/asn1_encoding_rule.dart deleted file mode 100644 index 3b9010c..0000000 --- a/pointycastle/lib/asn1/asn1_encoding_rule.dart +++ /dev/null @@ -1,16 +0,0 @@ -enum ASN1EncodingRule { - /// Normal DER encoding rules - ENCODING_DER, - - /// BER encoding where the length is described in a long form - ENCODING_BER_LONG_LENGTH_FORM, - - /// BER Constructed encoding with definite length - ENCODING_BER_CONSTRUCTED, - - /// BER encoding with padded bits to make the length of the value bytes a multiple of eight. Only used for ASN1BitString - ENCODING_BER_PADDED, - - /// BER Constructed encoding with indefinite length - ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH -} diff --git a/pointycastle/lib/asn1/asn1_object.dart b/pointycastle/lib/asn1/asn1_object.dart deleted file mode 100644 index 480ad33..0000000 --- a/pointycastle/lib/asn1/asn1_object.dart +++ /dev/null @@ -1,142 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_parser.dart'; -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_utils.dart'; - -/// -/// Base model for all ASN1Objects -/// -class ASN1Object { - /// - /// The BER tag representing this object. - /// - /// For a list of all supported BER tags take a look in the **Asn1Tags** class. - /// - int? tag; - - /// - /// The encoded bytes. - /// - Uint8List? encodedBytes; - - /// - /// The value bytes. - /// - Uint8List? valueBytes; - - /// - /// The index where the value bytes start. This is the position after the tag + length bytes. - /// - /// The default value for this field is 2. If the length byte is larger than **127**, the value of this field will increase depending on the length bytes. - /// - int valueStartPosition = 2; - - /// - /// Length of the encoded value bytes. - /// - int? valueByteLength; - - /// - /// Describes if this ASN1 Object is constructed. - /// - /// The object is marked as constructed if bit 6 of the [tag] field has value **1** - /// - bool? isConstructed; - - int dumpIndent = 2; - - ASN1Object({this.tag}) { - if (tag != null) { - isConstructed = ASN1Utils.isConstructed(tag!); - } - } - - /// - /// Creates a new ASN1Object from the given [encodedBytes]. - /// - /// The first byte will be used as the [tag].The field [valueStartPosition] and [valueByteLength] will be calculated on the given [encodedBytes]. - /// - ASN1Object.fromBytes(this.encodedBytes) { - tag = encodedBytes![0]; - isConstructed = ASN1Utils.isConstructed(tag!); - valueByteLength = ASN1Utils.decodeLength(encodedBytes!); - valueStartPosition = ASN1Utils.calculateValueStartPosition(encodedBytes!); - if (valueByteLength == -1) { - // Indefinite length, check the last to bytes - if (ASN1Utils.hasIndefiniteLengthEnding(encodedBytes!)) { - valueByteLength = encodedBytes!.length - 4; - } - } - valueBytes = Uint8List.view(encodedBytes!.buffer, - valueStartPosition + encodedBytes!.offsetInBytes, valueByteLength); - } - - /// - /// Encode the object to their byte representation. - /// - /// [encodingRule] defines if the [valueByteLength] should be encoded as indefinite length (0x80) or fixed length with short/long form. - /// The default is [ASN1EncodingRule.ENCODING_DER] which will automatically decode in definite length with short form. - /// - /// **Important note**: Subclasses need to override this method and may call this method. If this method is called by a subclass, the subclass has to set the [valueBytes] before calling super.encode(). - /// - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - if (encodedBytes == null) { - // Encode the length - Uint8List lengthAsBytes; - valueByteLength ??= valueBytes!.length; - // Check if we have indefinite length or fixed length (short or longform) - if (encodingRule == - ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH) { - // Set length to 0x80 - lengthAsBytes = Uint8List.fromList([0x80]); - // Add 2 to the valueByteLength to handle the 0x00, 0x00 at the end - //valueByteLength = valueByteLength + 2; - } else { - lengthAsBytes = ASN1Utils.encodeLength(valueByteLength!, - longform: - encodingRule == ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM); - } - // Create the Uint8List with the calculated length - encodedBytes = Uint8List(1 + lengthAsBytes.length + valueByteLength!); - // Set the tag - encodedBytes![0] = tag!; - // Set the length bytes - encodedBytes!.setRange(1, 1 + lengthAsBytes.length, lengthAsBytes, 0); - // Set the value bytes - encodedBytes!.setRange( - 1 + lengthAsBytes.length, encodedBytes!.length, valueBytes!, 0); - } - return encodedBytes!; - } - - /// - /// The total length of this object, including its value bytes, the encoded tag and length bytes. - /// - int get totalEncodedByteLength => valueStartPosition + valueByteLength!; - - /// - /// Creates a readable dump from the current ASN1Object. - /// - /// **Important note**: Subclasses need to override this method. If the ASN1Object is constructed and has child elements, dump() has to be called for each child element. - /// - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - if (tag == 0xA0 || tag == 0xA3) { - sb.write('[$tag]'); - var parser = ASN1Parser(valueBytes); - if (parser.hasNext()) { - var next = parser.nextObject(); - var dump = next.dump(spaces: spaces + dumpIndent); - sb.write('\n$dump'); - } else { - sb.write(' (0 elem)'); - } - } - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/asn1_parser.dart b/pointycastle/lib/asn1/asn1_parser.dart deleted file mode 100644 index e131335..0000000 --- a/pointycastle/lib/asn1/asn1_parser.dart +++ /dev/null @@ -1,163 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/asn1_utils.dart'; -import 'package:pointycastle/asn1/primitives/asn1_bit_string.dart'; -import 'package:pointycastle/asn1/primitives/asn1_bmp_string.dart'; -import 'package:pointycastle/asn1/primitives/asn1_boolean.dart'; -import 'package:pointycastle/asn1/primitives/asn1_generalized_time.dart'; -import 'package:pointycastle/asn1/primitives/asn1_ia5_string.dart'; -import 'package:pointycastle/asn1/primitives/asn1_integer.dart'; -import 'package:pointycastle/asn1/primitives/asn1_null.dart'; -import 'package:pointycastle/asn1/primitives/asn1_object_identifier.dart'; -import 'package:pointycastle/asn1/primitives/asn1_octet_string.dart'; -import 'package:pointycastle/asn1/primitives/asn1_printable_string.dart'; -import 'package:pointycastle/asn1/primitives/asn1_sequence.dart'; -import 'package:pointycastle/asn1/primitives/asn1_set.dart'; -import 'package:pointycastle/asn1/primitives/asn1_teletext_string.dart'; -import 'package:pointycastle/asn1/primitives/asn1_utc_time.dart'; -import 'package:pointycastle/asn1/primitives/asn1_utf8_string.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_tag_exception.dart'; - -/// -/// The ASN1Parser to parse bytes into ASN1 Objects -/// -class ASN1Parser { - /// - /// The bytes to parse - /// - final Uint8List? bytes; - - /// - /// The current position in the byte array. - /// - /// The inital value is 0. - /// - int _position = 0; - - ASN1Parser(this.bytes); - - /// - /// Returns true if there is still an object to parse. Otherwise false. - /// - bool hasNext() { - return _position < bytes!.length; - } - - /// - /// Parses the next object in the [bytes]. - /// - ASN1Object nextObject() { - // Get the current tag in the list bytes - var tag = bytes![_position]; - - // Get the length of the value bytes for the current object - var length = ASN1Utils.decodeLength(bytes!.sublist(_position)); - - var valueStartPosition = - ASN1Utils.calculateValueStartPosition(bytes!.sublist(_position)); - - var isIndefiniteLength = false; - - if (length == -1) { - length = ASN1Utils.calculateIndefiniteLength(bytes!, _position) + 2; - isIndefiniteLength = true; - } else if (bytes!.length - _position > length + valueStartPosition) { - length = length + valueStartPosition; - } else { - length = bytes!.length - _position; - } - - // Create new view from the bytes - var offset = _position + bytes!.offsetInBytes; - var subBytes = Uint8List.view(bytes!.buffer, offset, length); - - // Parse the view and the tag to an ASN1Object - var isConstructed = ASN1Utils.isConstructed(tag); - var isPrimitive = (0xC0 & tag) == 0; - //var isApplication = (0x40 & tag) != 0; - - ASN1Object obj; - if (isConstructed) { - obj = _createConstructed(tag, subBytes); - } else if (isPrimitive) { - obj = _createPrimitive(tag, subBytes); - } else { - // create a vanilla object - obj = ASN1Object.fromBytes(subBytes); - } - - // Update the position - _position = - _position + obj.totalEncodedByteLength + (isIndefiniteLength ? 2 : 0); - return obj; - } - - /// - /// Creates a constructed ASN1Object depending on the given [tag] and [bytes] - /// - ASN1Object _createConstructed(int tag, Uint8List bytes) { - switch (tag) { - case ASN1Tags.SEQUENCE: // sequence - return ASN1Sequence.fromBytes(bytes); - case ASN1Tags.SET: - return ASN1Set.fromBytes(bytes); - case ASN1Tags.IA5_STRING_CONSTRUCTED: - return ASN1IA5String.fromBytes(bytes); - case ASN1Tags.BIT_STRING_CONSTRUCTED: - return ASN1BitString.fromBytes(bytes); - case ASN1Tags.OCTET_STRING_CONSTRUCTED: - return ASN1OctetString.fromBytes(bytes); - case ASN1Tags.PRINTABLE_STRING_CONSTRUCTED: - return ASN1PrintableString.fromBytes(bytes); - case ASN1Tags.T61_STRING_CONSTRUCTED: - return ASN1TeletextString.fromBytes(bytes); - case 0xA0: - case 0xA1: - case 0xA2: - case 0xA3: - case 0xA4: - return ASN1Object.fromBytes(bytes); - default: - throw UnsupportedASN1TagException(tag); - } - } - - /// - /// Creates a primitive ASN1Object depending on the given [tag] and [bytes] - /// - ASN1Object _createPrimitive(int tag, Uint8List bytes) { - switch (tag) { - case ASN1Tags.OCTET_STRING: - return ASN1OctetString.fromBytes(bytes); - case ASN1Tags.UTF8_STRING: - return ASN1UTF8String.fromBytes(bytes); - case ASN1Tags.IA5_STRING: - return ASN1IA5String.fromBytes(bytes); - case ASN1Tags.INTEGER: - case ASN1Tags.ENUMERATED: - return ASN1Integer.fromBytes(bytes); - case ASN1Tags.BOOLEAN: - return ASN1Boolean.fromBytes(bytes); - case ASN1Tags.OBJECT_IDENTIFIER: - return ASN1ObjectIdentifier.fromBytes(bytes); - case ASN1Tags.BIT_STRING: - return ASN1BitString.fromBytes(bytes); - case ASN1Tags.NULL: - return ASN1Null.fromBytes(bytes); - case ASN1Tags.PRINTABLE_STRING: - return ASN1PrintableString.fromBytes(bytes); - case ASN1Tags.UTC_TIME: - return ASN1UtcTime.fromBytes(bytes); - case ASN1Tags.T61_STRING: - return ASN1TeletextString.fromBytes(bytes); - case ASN1Tags.GENERALIZED_TIME: - return ASN1GeneralizedTime.fromBytes(bytes); - case ASN1Tags.BMP_STRING: - return ASN1BMPString.fromBytes(bytes); - default: - throw UnsupportedASN1TagException(tag); - } - } -} diff --git a/pointycastle/lib/asn1/asn1_tags.dart b/pointycastle/lib/asn1/asn1_tags.dart deleted file mode 100644 index b61b78a..0000000 --- a/pointycastle/lib/asn1/asn1_tags.dart +++ /dev/null @@ -1,134 +0,0 @@ -/// -/// Class holding all ASN1 BER tags, supported by this package -/// -class ASN1Tags { - static const List TAGS = [ - BOOLEAN, - INTEGER, - BIT_STRING, - BIT_STRING_CONSTRUCTED, - OCTET_STRING, - OCTET_STRING_CONSTRUCTED, - NULL, - OBJECT_IDENTIFIER, - EXTERNAL, - ENUMERATED, - UTF8_STRING, - UTF8_STRING_CONSTRUCTED, - SEQUENCE, - SEQUENCE_OF, - SET, - SET_OF, - T61_STRING, - T61_STRING_CONSTRUCTED, - PRINTABLE_STRING, - PRINTABLE_STRING_CONSTRUCTED, - IA5_STRING, - IA5_STRING_CONSTRUCTED, - UTC_TIME, - GENERALIZED_TIME, - BMP_STRING - ]; - - /// Decimal 1 - static const int BOOLEAN = 0x01; - - /// Decimal 2 - static const int INTEGER = 0x02; - - /// Decimal 3 - static const int BIT_STRING = 0x03; - - /// Decimal 35 - static const int BIT_STRING_CONSTRUCTED = 0x23; - - /// Decimal 4 - static const int OCTET_STRING = 0x04; - - /// Decimal 36 - static const int OCTET_STRING_CONSTRUCTED = 0x24; - - /// Decimal 5 - static const int NULL = 0x05; - - /// Decimal 6 - static const int OBJECT_IDENTIFIER = 0x06; - - /// Decimal 8 - static const int EXTERNAL = 0x08; - - /// Decimal 10 - static const int ENUMERATED = 0x0a; - - /// Decimal 12 - static const int UTF8_STRING = 0x0c; - - /// Decimal 44 - static const int UTF8_STRING_CONSTRUCTED = 0x2C; - - /// Decimal 48 - static const int SEQUENCE = 0x30; - - /// Decimal 48 - static const int SEQUENCE_OF = 0x30; - - /// Decimal 49 - static const int SET = 0x31; - - /// Decimal 49 - static const int SET_OF = 0x31; - - /// Decimal 18 - static const int NUMERIC_STRING = 0x12; - - /// Decimal 19 - static const int PRINTABLE_STRING = 0x13; - - /// Decimal 51 - static const int PRINTABLE_STRING_CONSTRUCTED = 0x33; - - /// Decimal 20 - static const int T61_STRING = 0x14; - - /// Decimal 52 - static const int T61_STRING_CONSTRUCTED = 0x34; - - /// Decimal 21 - static const int VIDEOTEX_STRING = 0x15; - - /// Decimal 22 - static const int IA5_STRING = 0x16; - - /// Decimal 54 - static const int IA5_STRING_CONSTRUCTED = 0x36; - - /// Decimal 23 - static const int UTC_TIME = 0x17; - - /// Decimal 24 - static const int GENERALIZED_TIME = 0x18; - - /// Decimal 25 - static const int GRAPHIC_STRING = 0x19; - - /// Decimal 26 - static const int VISIBLE_STRING = 0x1a; - - /// Decimal 27 - static const int GENERAL_STRING = 0x1b; - - /// Decimal 28 - static const int UNIVERSAL_STRING = 0x1c; - - /// Decimal 30 - static const int BMP_STRING = 0x1e; - - /// Decimal 32 - static const int CONSTRUCTED = 0x20; - - /// Decimal 64 - static const int APPLICATION = 0x40; - - /// Decimal 128 - static const int TAGGED = 0x80; -} diff --git a/pointycastle/lib/asn1/asn1_utils.dart b/pointycastle/lib/asn1/asn1_utils.dart deleted file mode 100644 index 1cd8663..0000000 --- a/pointycastle/lib/asn1/asn1_utils.dart +++ /dev/null @@ -1,243 +0,0 @@ -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; -import 'package:pointycastle/asn1/object_identifiers.dart'; -import 'package:pointycastle/ecc/api.dart'; - -/// -/// Utils class holding different methods to ease the handling of ANS1Objects and their byte representation. -/// -class ASN1Utils { - /// - /// Calculates the start position of the value bytes for the given [encodedBytes]. - /// - /// It will return 2 if the **length byte** is less than or equal 127 or the length calculate on the **length byte** value. - /// This will throw a [RangeError] if the given [encodedBytes] has length < 2. - /// - static int calculateValueStartPosition(Uint8List encodedBytes) { - // TODO tag length can be >1 - var length = encodedBytes[1]; - if (length <= 0x7F) { - return 2; - } else { - return 2 + (length & 0x7F); - } - } - - /// - /// Calculates the length of the **value bytes** for the given [encodedBytes]. - /// - /// Will return **-1** if the length byte equals **0x80**. Throws an [ArgumentError] if the length could not be calculated for the given [encodedBytes]. - /// - static int decodeLength(Uint8List encodedBytes) { - var valueStartPosition = 2; - var length = encodedBytes[1]; - if (length <= 0x7F) { - return length; - } - if (length == 0x80) { - return -1; - } - if (length > 127) { - var length = encodedBytes[1] & 0x7F; - - var numLengthBytes = length; - - length = 0; - for (var i = 0; i < numLengthBytes; i++) { - length <<= 8; - length |= encodedBytes[valueStartPosition++] & 0xFF; - } - return length; - } - throw ArgumentError('Could not calculate the length from the given bytes.'); - } - - /// - /// Encode the given [length] to byte representation. - /// - static Uint8List encodeLength(int length, {bool longform = false}) { - Uint8List e; - if (length <= 127 && longform == false) { - e = Uint8List(1); - e[0] = length; - } else { - var x = Uint32List(1); - x[0] = length; - var y = Uint8List.view(x.buffer); - // Skip null bytes - var num = 3; - while (y[num] == 0) { - --num; - } - e = Uint8List(num + 2); - e[0] = 0x80 + num + 1; - for (var i = 1; i < e.length; ++i) { - e[i] = y[num--]; - } - } - return e; - } - - /// - /// Checks if the given int [i] is constructed according to section 3.2. - /// - /// The Identifier octets (represented by the given [i]) is marked as constructed if bit 6 has the value **1**. - /// - /// Example with the IA5 String tag: - /// - /// 0x36 = 0 0 1 1 0 1 1 0 - /// - /// 0x16 = 0 0 0 1 0 1 1 0 - /// ``` - /// ASN1Utils.isConstructed(0x36); // true - /// ASN1Utils.isConstructed(0x16); // false - /// ``` - /// - /// - static bool isConstructed(int i) { - // Shift bits - var newNum = i >> (6 - 1); - // Check if bit is set to 1 - return (newNum & 1) == 1; - } - - static bool isASN1Tag(int i) { - return ASN1Tags.TAGS.contains(i); - } - - /// - /// Checks if the given [bytes] ends with 0x00, 0x00 - /// - static bool hasIndefiniteLengthEnding(Uint8List bytes) { - var last = bytes.elementAt(bytes.length - 1); - var lastMinus1 = bytes.elementAt(bytes.length - 2); - if (last == 0 && lastMinus1 == 0) { - return true; - } - return false; - } - - /// - /// Calculates the indefinite length of the ASN1 object. - /// Throws an [ArgumentError] if the end of content octets is not found. - /// - static int calculateIndefiniteLength(Uint8List bytes, int startPosition) { - var currentPosition = startPosition; - var indefiniteLengthObjects = 0; - while (currentPosition < bytes.length - 1) { - if (bytes[currentPosition] == 0x00 && - bytes[currentPosition + 1] == 0x00) { - indefiniteLengthObjects--; - if (indefiniteLengthObjects == 0) { - return currentPosition - startPosition; - } - currentPosition += 2; - } else { - final nextLength = - ASN1Utils.decodeLength(bytes.sublist(currentPosition)); - final valueStartPosition = ASN1Utils.calculateValueStartPosition( - bytes.sublist(currentPosition)); - if (nextLength == 0) { - throw ArgumentError('Invalid length of zero.'); - } - if (valueStartPosition <= 0) { - throw ArgumentError( - 'Invalid value start position: $valueStartPosition'); - } - - if (nextLength == -1) { - indefiniteLengthObjects++; - currentPosition += valueStartPosition; - } else { - currentPosition += valueStartPosition + nextLength; - } - } - } - - throw ArgumentError('End of content octets not found'); - } - - static Uint8List getBytesFromPEMString(String pem, - {bool checkHeader = true}) { - var lines = LineSplitter.split(pem) - .map((line) => line.trim()) - .where((line) => line.isNotEmpty) - .toList(); - String base64; - if (checkHeader) { - if (lines.length < 2 || - !lines.first.startsWith('-----BEGIN') || - !lines.last.startsWith('-----END')) { - throw ArgumentError('The given string does not have the correct ' - 'begin/end markers expected in a PEM file.'); - } - base64 = lines.sublist(1, lines.length - 1).join(''); - } else { - base64 = lines.join(''); - } - - return Uint8List.fromList(base64Decode(base64)); - } - - static ECPrivateKey ecPrivateKeyFromDerBytes(Uint8List bytes, - {bool pkcs8 = false}) { - var asn1Parser = ASN1Parser(bytes); - var topLevelSeq = asn1Parser.nextObject() as ASN1Sequence; - late String curveName; - Uint8List x; - if (pkcs8) { - // Parse the PKCS8 format - var innerSeq = topLevelSeq.elements!.elementAt(1) as ASN1Sequence; - var b2 = innerSeq.elements!.elementAt(1) as ASN1ObjectIdentifier; - var b2Data = b2.objectIdentifierAsString; - var b2Curvedata = ObjectIdentifiers.getIdentifierByIdentifier(b2Data); - if (b2Curvedata != null) { - curveName = b2Curvedata['readableName'] as String; - } - - var octetString = topLevelSeq.elements!.elementAt(2) as ASN1OctetString; - asn1Parser = ASN1Parser(octetString.valueBytes); - var octetStringSeq = asn1Parser.nextObject() as ASN1Sequence; - var octetStringKeyData = - octetStringSeq.elements!.elementAt(1) as ASN1OctetString; - - x = octetStringKeyData.valueBytes!; - } else { - // Parse the SEC1 format - var privateKeyAsOctetString = - topLevelSeq.elements!.elementAt(1) as ASN1OctetString; - var choice = topLevelSeq.elements!.elementAt(2); - var s = ASN1Sequence(); - var parser = ASN1Parser(choice.valueBytes); - while (parser.hasNext()) { - s.add(parser.nextObject()); - } - var curveNameOi = s.elements!.elementAt(0) as ASN1ObjectIdentifier; - var data = ObjectIdentifiers.getIdentifierByIdentifier( - curveNameOi.objectIdentifierAsString); - if (data != null) { - curveName = data['readableName'] as String; - } - - x = privateKeyAsOctetString.valueBytes!; - } - - return ECPrivateKey(osp2i(x), ECDomainParameters(curveName)); - } - - static BigInt osp2i(Iterable bytes, {Endian endian = Endian.big}) { - var result = BigInt.from(0); - if (endian == Endian.little) { - bytes = bytes.toList().reversed; - } - - for (var byte in bytes) { - result = result << 8; - result |= BigInt.from(byte); - } - - return result; - } -} diff --git a/pointycastle/lib/asn1/object_identifiers.dart b/pointycastle/lib/asn1/object_identifiers.dart deleted file mode 100644 index bb0dff7..0000000 --- a/pointycastle/lib/asn1/object_identifiers.dart +++ /dev/null @@ -1,34 +0,0 @@ -import 'package:pointycastle/asn1/object_identifiers_database.dart'; - -/// -/// Class holding a list of object identifiers -/// -class ObjectIdentifiers { - /// - /// Returns the object identifier corresponding to the given [readableName]. - /// - /// Returns null if none object identifier can be found for the given [readableName]. - /// - static Map? getIdentifierByName(String readableName) { - for (var element in oi) { - if (element['readableName'] == readableName) { - return element; - } - } - return null; - } - - /// - /// Returns the object identifier corresponding to the given [identifier]. - /// - /// Returns null if none object identifier can be found for the given [identifier]. - /// - static Map? getIdentifierByIdentifier(String? identifier) { - for (var element in oi) { - if (element['identifierString'] == identifier) { - return element; - } - } - return null; - } -} diff --git a/pointycastle/lib/asn1/object_identifiers_database.dart b/pointycastle/lib/asn1/object_identifiers_database.dart deleted file mode 100644 index a36cdb7..0000000 --- a/pointycastle/lib/asn1/object_identifiers_database.dart +++ /dev/null @@ -1,803 +0,0 @@ -/// -/// A list of object identifiers, holding the identifier and a readable name. -/// -const oi = [ - { - 'identifierString': '1.2.860.3.15.1.1.1.1.4', - 'readableName': - 'UZDST 1092:2009 I digital signature parameters, UNICON.UZ paramset B', - 'identifier': [1, 2, 860, 3, 15, 1, 1, 1, 1, 4] - }, - { - 'identifierString': '1.2.860.3.15.1.3.2.1.0', - 'readableName': 'UZDST 1106:2009 II test digest parameters', - 'identifier': [1, 2, 860, 3, 15, 1, 3, 2, 1, 0] - }, - { - 'identifierString': '1.2.860.3.15.1.1.2.1.1', - 'readableName': - 'UZDST 1092:2009 II signature parameters, UNICON.UZ paramset A', - 'identifier': [1, 2, 860, 3, 15, 1, 1, 2, 1, 1] - }, - { - 'identifierString': '1.2.860.3.15.1.1.2.1.2', - 'readableName': - 'UZDST 1092:2009 II signature parameters, UNICON.UZ paramset B', - 'identifier': [1, 2, 860, 3, 15, 1, 1, 2, 1, 2] - }, - { - 'identifierString': '1.2.860.3.16.1.1', - 'readableName': 'Identifikatsionniy Nomer Nalogoplatelshika', - 'identifier': [1, 2, 860, 3, 16, 1, 1] - }, - { - 'identifierString': '1.2.860.3.16.1.2', - 'readableName': 'Personalniy Identifikatsionniy Nomer Fizicheskogo Litsa', - 'identifier': [1, 2, 860, 3, 16, 1, 2] - }, - { - 'identifierString': '1.2.860.3.15.1.1.1.1', - 'readableName': 'UZDST 1092:2009 I digital signature public key', - 'identifier': [1, 2, 860, 3, 15, 1, 1, 1, 1] - }, - { - 'identifierString': '1.2.860.3.15.1.1.2.1', - 'readableName': 'UZDST 1092:2009 II digital signature public key', - 'identifier': [1, 2, 860, 3, 15, 1, 1, 2, 1] - }, - { - 'identifierString': '1.2.860.3.15.1.1.1.2.2.2', - 'readableName': - 'UZDST 1092:2009 I/1106:2009 digital signature algorithm with message digest', - 'identifier': [1, 2, 860, 3, 15, 1, 1, 1, 2, 2, 2] - }, - { - 'identifierString': '1.2.860.3.15.1.1.2.2.2.2', - 'readableName': - 'UZDST 1092:2009 II/1106:2009 digital signature algorithm with message digest', - 'identifier': [1, 2, 860, 3, 15, 1, 1, 2, 2, 2, 2] - }, - { - 'identifierString': '1.2.860.3.15.1.1.1.1.1', - 'readableName': - 'UZDST 1092:2009 I digital signature parameters, SICNT paramset A', - 'identifier': [1, 2, 860, 3, 15, 1, 1, 1, 1, 1] - }, - { - 'identifierString': '1.2.860.3.15.1.1.1.1.2', - 'readableName': - 'UZDST 1092:2009 I digital signature parameters, SICNT paramset B', - 'identifier': [1, 2, 860, 3, 15, 1, 1, 1, 1, 1] - }, - { - 'identifierString': '1.2.860.3.15.1.1.1.1.3', - 'readableName': - 'UZDST 1092:2009 I digital signature parameters, UNICON.UZ paramset A', - 'identifier': [1, 2, 860, 3, 15, 1, 1, 1, 1, 3] - }, - { - 'identifierString': '1.2.860.3.15.1.3.2.1.1', - 'readableName': 'UZDST 1106:2009 II default digest parameters', - 'identifier': [1, 2, 860, 3, 15, 1, 3, 2, 1, 1] - }, - { - 'identifierString': '1.2.860.3.15.1.2.1', - 'readableName': 'UZDST 1105:2009 symmetric cipher', - 'identifier': [1, 2, 860, 3, 15, 1, 2, 1] - }, - { - 'identifierString': '1.2.860.3.15.1.3.2', - 'readableName': 'UZDST 1106:2009 II digest', - 'identifier': [1, 2, 860, 3, 15, 1, 3, 2] - }, - { - 'identifierString': '1.2.860.3.15.1.4.2', - 'readableName': 'UZDST 1106:2009 II digest based HMAC', - 'identifier': [1, 2, 860, 3, 15, 1, 4, 2] - }, - { - 'identifierString': '1.2.860.3.15.1.12.2.1', - 'readableName': 'PBE with UZDST 1106:2009 II and UZDST 1105:2009', - 'identifier': [1, 2, 860, 3, 15, 1, 12, 2, 1] - }, - { - 'identifierString': '1.2.840.113549.1.9.22.1', - 'readableName': 'x509Certificate', - 'identifier': [1, 2, 840, 113549, 1, 9, 22, 1] - }, - { - 'identifierString': '1.2.840.113549.1.9.22.2', - 'readableName': 'sdsiCertificate', - 'identifier': [1, 2, 840, 113549, 1, 9, 22, 2] - }, - { - 'identifierString': '1.2.840.113549.1.9.20', - 'readableName': 'friendlyName', - 'identifier': [1, 2, 840, 113549, 1, 9, 20] - }, - { - 'identifierString': '1.2.840.113549.1.9.21', - 'readableName': 'localKeyID', - 'identifier': [1, 2, 840, 113549, 1, 9, 21] - }, - { - 'identifierString': '1.2.840.113549.1.12.10.1.1', - 'readableName': 'keyBag', - 'identifier': [1, 2, 840, 113549, 1, 12, 10, 1, 1] - }, - { - 'identifierString': '1.2.840.113549.1.12.10.1.2', - 'readableName': 'pkcs-8ShroudedKeyBag', - 'identifier': [1, 2, 840, 113549, 1, 12, 10, 1, 2] - }, - { - 'identifierString': '1.2.840.113549.1.12.10.1.3', - 'readableName': 'certBag', - 'identifier': [1, 2, 840, 113549, 1, 12, 10, 1, 3] - }, - { - 'identifierString': '1.2.840.113549.1.12.10.1.4', - 'readableName': 'crlBag', - 'identifier': [1, 2, 840, 113549, 1, 12, 10, 1, 4] - }, - { - 'identifierString': '1.2.840.113549.1.12.10.1.5', - 'readableName': 'secretBag', - 'identifier': [1, 2, 840, 113549, 1, 12, 10, 1, 5] - }, - { - 'identifierString': '1.2.840.113549.1.12.10.1.6', - 'readableName': 'safeContentsBag', - 'identifier': [1, 2, 840, 113549, 1, 12, 10, 1, 6] - }, - { - 'identifierString': '1.2.840.113549.1.7.1', - 'readableName': 'data', - 'identifier': [1, 2, 840, 113549, 1, 7, 1] - }, - { - 'identifierString': '1.2.840.113549.1.7.6', - 'readableName': 'encryptedData', - 'identifier': [1, 2, 840, 113549, 1, 7, 6] - }, - { - 'identifierString': '1.2.840.113549.1.1.10', - 'readableName': 'rsaPSS', - 'identifier': [1, 2, 840, 113549, 1, 1, 10] - }, - { - 'identifierString': '2.16.840.1.101.3.4.2.1', - 'readableName': 'SHA-256', - 'identifier': [2, 16, 840, 1, 101, 3, 4, 2, 1] - }, - { - 'identifierString': '2.16.840.1.101.3.4.2.2', - 'readableName': 'SHA-384', - 'identifier': [2, 16, 840, 1, 101, 3, 4, 2, 2] - }, - { - 'identifierString': '2.16.840.1.101.3.4.2.3', - 'readableName': 'SHA-512', - 'identifier': [2, 16, 840, 1, 101, 3, 4, 2, 3] - }, - { - 'identifierString': '2.16.840.1.101.3.4.2.4', - 'readableName': 'SHA-224', - 'identifier': [2, 16, 840, 1, 101, 3, 4, 2, 4] - }, - { - 'identifierString': '2.5.4.3', - 'readableName': 'commonName', - 'identifier': [2, 5, 4, 3] - }, - { - 'identifierString': '2.5.4.6', - 'readableName': 'countryName', - 'identifier': [2, 5, 4, 6] - }, - { - 'identifierString': '2.5.4.10', - 'readableName': 'organizationName', - 'identifier': [2, 5, 4, 10] - }, - { - 'identifierString': '2.5.4.11', - 'readableName': 'organizationalUnitName', - 'identifier': [2, 5, 4, 11] - }, - { - 'identifierString': '1.3.6.1.4.1.311.60.2.1.3', - 'readableName': 'jurisdictionOfIncorporationC', - 'identifier': [1, 3, 6, 1, 4, 1, 311, 60, 2, 1, 3] - }, - { - 'identifierString': '1.3.6.1.4.1.311.60.2.1.2', - 'readableName': 'jurisdictionOfIncorporationSP', - 'identifier': [1, 3, 6, 1, 4, 1, 311, 60, 2, 1, 2] - }, - { - 'identifierString': '1.3.6.1.4.1.311.60.2.1.1', - 'readableName': 'jurisdictionOfIncorporationL', - 'identifier': [1, 3, 6, 1, 4, 1, 311, 60, 2, 1, 1] - }, - { - 'identifierString': '2.5.4.15', - 'readableName': 'businessCategory', - 'identifier': [2, 5, 4, 15] - }, - { - 'identifierString': '2.5.4.5', - 'readableName': 'serialNumber', - 'identifier': [2, 5, 4, 5] - }, - { - 'identifierString': '2.5.4.8', - 'readableName': 'stateOrProvinceName', - 'identifier': [2, 5, 4, 8] - }, - { - 'identifierString': '2.5.4.7', - 'readableName': 'localityName', - 'identifier': [2, 5, 4, 7] - }, - { - 'identifierString': '1.2.840.113549.1.1.1', - 'readableName': 'rsaEncryption', - 'identifier': [1, 2, 840, 113549, 1, 1, 1] - }, - { - 'identifierString': '2.5.29.17', - 'readableName': 'subjectAltName', - 'identifier': [2, 5, 29, 17] - }, - { - 'identifierString': '2.5.29.32', - 'readableName': 'certificatePolicies', - 'identifier': [2, 5, 29, 32] - }, - { - 'identifierString': '2.16.840.1.113733.1.7.23.6', - 'readableName': 'VeriSign EV policy', - 'identifier': [2, 16, 840, 1, 113733, 1, 7, 23, 6] - }, - { - 'identifierString': '1.3.6.1.5.5.7.2.1', - 'readableName': 'cps', - 'identifier': [1, 3, 6, 1, 5, 5, 7, 2, 1] - }, - { - 'identifierString': '1.3.6.1.5.5.7.2.2', - 'readableName': 'unotice', - 'identifier': [1, 3, 6, 1, 5, 5, 7, 2, 2] - }, - { - 'identifierString': '2.5.29.31', - 'readableName': 'cRLDistributionPoints', - 'identifier': [2, 5, 29, 31] - }, - { - 'identifierString': '2.5.29.37', - 'readableName': 'extKeyUsage', - 'identifier': [2, 5, 29, 37] - }, - { - 'identifierString': '2.5.29.35', - 'readableName': 'authorityKeyIdentifier', - 'identifier': [2, 5, 29, 35] - }, - { - 'identifierString': '1.3.6.1.5.5.7.3.1', - 'readableName': 'serverAuth', - 'identifier': [1, 3, 6, 1, 5, 5, 7, 3, 1] - }, - { - 'identifierString': '1.3.6.1.5.5.7.3.2', - 'readableName': 'clientAuth', - 'identifier': [1, 3, 6, 1, 5, 5, 7, 3, 2] - }, - { - 'identifierString': '1.3.6.1.5.5.7.1.1', - 'readableName': 'authorityInfoAccess', - 'identifier': [1, 3, 6, 1, 5, 5, 7, 1, 1] - }, - { - 'identifierString': '1.3.6.1.5.5.7.48.1', - 'readableName': 'ocsp', - 'identifier': [1, 3, 6, 1, 5, 5, 7, 48, 1] - }, - { - 'identifierString': '1.3.6.1.5.5.7.48.2', - 'readableName': 'caIssuers', - 'identifier': [1, 3, 6, 1, 5, 5, 7, 48, 2] - }, - { - 'identifierString': '1.2.840.113549.1.1.11', - 'readableName': 'sha256WithRSAEncryption', - 'identifier': [1, 2, 840, 113549, 1, 1, 11] - }, - { - 'identifierString': '1.2.840.113549.1.1.4', - 'readableName': 'md5WithRSAEncryption', - 'identifier': [1, 2, 840, 113549, 1, 1, 4] - }, - { - 'identifierString': '1.3.6.1.4.1.11129.2.4.2', - 'readableName': '2', - 'identifier': [1, 3, 6, 1, 4, 1, 11129, 2, 4, 2] - }, - { - 'identifierString': '2.23.140.1.1', - 'readableName': 'ev-guidelines', - 'identifier': [2, 23, 140, 1, 1] - }, - { - 'identifierString': '1.2.840.113549.1.1.5', - 'readableName': 'sha1WithRSAEncryption', - 'identifier': [1, 2, 840, 113549, 1, 1, 5] - }, - { - 'identifierString': '1.2.840.10045.2.1', - 'readableName': 'ecPublicKey', - 'identifier': [1, 2, 840, 10045, 2, 1] - }, - { - 'identifierString': '1.2.840.10045.3.1.7', - 'readableName': 'prime256v1', - 'identifier': [1, 2, 840, 10045, 3, 1, 7] - }, - { - 'identifierString': '1.2.840.10045.3.1.6', - 'readableName': 'prime239v3', - 'identifier': [1, 2, 840, 10045, 3, 1, 6] - }, - { - 'identifierString': '1.2.840.10045.3.1.5', - 'readableName': 'prime239v2', - 'identifier': [1, 2, 840, 10045, 3, 1, 5] - }, - { - 'identifierString': '1.2.840.10045.3.1.4', - 'readableName': 'prime239v1', - 'identifier': [1, 2, 840, 10045, 3, 1, 4] - }, - { - 'identifierString': '1.2.840.10045.3.1.3', - 'readableName': 'prime192v3', - 'identifier': [1, 2, 840, 10045, 3, 1, 3] - }, - { - 'identifierString': '1.2.840.10045.3.1.2', - 'readableName': 'prime192v2', - 'identifier': [1, 2, 840, 10045, 3, 1, 2] - }, - { - 'identifierString': '1.2.840.10045.3.1.1', - 'readableName': 'prime192v1', - 'identifier': [1, 2, 840, 10045, 3, 1, 1] - }, - { - 'identifierString': '1.3.101.110', - 'readableName': 'curveX25519', - 'identifier': [1, 3, 101, 110] - }, - { - 'identifierString': '1.3.101.111', - 'readableName': 'curveX448', - 'identifier': [1, 3, 101, 111] - }, - { - 'identifierString': '1.3.101.112', - 'readableName': 'curveEd25519', - 'identifier': [1, 3, 101, 112] - }, - { - 'identifierString': '1.3.101.113', - 'readableName': 'curveEd448', - 'identifier': [1, 3, 101, 113] - }, - { - 'identifierString': '1.3.132.0.1', - 'readableName': 'ansit163k1', - 'identifier': [1, 3, 132, 0, 1] - }, - { - 'identifierString': '1.3.132.0.2', - 'readableName': 'ansit163r1', - 'identifier': [1, 3, 132, 0, 2] - }, - { - 'identifierString': '1.3.132.0.3', - 'readableName': 'ansit239k1', - 'identifier': [1, 3, 132, 0, 3] - }, - { - 'identifierString': '1.3.132.0.4', - 'readableName': 'sect113r1', - 'identifier': [1, 3, 132, 0, 4] - }, - { - 'identifierString': '1.3.132.0.5', - 'readableName': 'sect113r2', - 'identifier': [1, 3, 132, 0, 5] - }, - { - 'identifierString': '1.3.132.0.6', - 'readableName': 'secp112r1', - 'identifier': [1, 3, 132, 0, 6] - }, - { - 'identifierString': '1.3.132.0.7', - 'readableName': 'secp112r2', - 'identifier': [1, 3, 132, 0, 7] - }, - { - 'identifierString': '1.3.132.0.8', - 'readableName': 'ansip160r1', - 'identifier': [1, 3, 132, 0, 8] - }, - { - 'identifierString': '1.3.132.0.9', - 'readableName': 'ansip160k1', - 'identifier': [1, 3, 132, 0, 9] - }, - { - 'identifierString': '1.3.132.0.15', - 'readableName': 'ansit163r2', - 'identifier': [1, 3, 132, 0, 15] - }, - { - 'identifierString': '1.3.132.0.16', - 'readableName': 'ansit283k1', - 'identifier': [1, 3, 132, 0, 16] - }, - { - 'identifierString': '1.3.132.0.17', - 'readableName': 'ansit283r1', - 'identifier': [1, 3, 132, 0, 17] - }, - { - 'identifierString': '1.3.132.0.22', - 'readableName': 'sect131r1', - 'identifier': [1, 3, 132, 0, 22] - }, - { - 'identifierString': '1.3.132.0.23', - 'readableName': '23', - 'identifier': [1, 3, 132, 0, 23] - }, - { - 'identifierString': '1.3.132.0.24', - 'readableName': 'ansit193r1', - 'identifier': [1, 3, 132, 0, 24] - }, - { - 'identifierString': '1.3.132.0.25', - 'readableName': 'ansit193r2', - 'identifier': [1, 3, 132, 0, 25] - }, - { - 'identifierString': '1.3.132.0.26', - 'readableName': 'ansit233k1', - 'identifier': [1, 3, 132, 0, 26] - }, - { - 'identifierString': '1.3.132.0.27', - 'readableName': 'ansit233r1', - 'identifier': [1, 3, 132, 0, 27] - }, - { - 'identifierString': '1.3.132.0.28', - 'readableName': 'secp128r1', - 'identifier': [1, 3, 132, 0, 28] - }, - { - 'identifierString': '1.3.132.0.29', - 'readableName': 'secp128r2', - 'identifier': [1, 3, 132, 0, 29] - }, - { - 'identifierString': '1.3.132.0.30', - 'readableName': 'ansip160r2', - 'identifier': [1, 3, 132, 0, 30] - }, - { - 'identifierString': '1.3.132.0.31', - 'readableName': 'ansip192k1', - 'identifier': [1, 3, 132, 0, 31] - }, - { - 'identifierString': '1.3.132.0.32', - 'readableName': 'ansip224k1', - 'identifier': [1, 3, 132, 0, 32] - }, - { - 'identifierString': '1.3.132.0.33', - 'readableName': 'ansip224r1', - 'identifier': [1, 3, 132, 0, 33] - }, - { - 'identifierString': '1.3.132.0.36', - 'readableName': 'ansit409k1', - 'identifier': [1, 3, 132, 0, 36] - }, - { - 'identifierString': '1.3.132.0.37', - 'readableName': 'ansit409r1', - 'identifier': [1, 3, 132, 0, 37] - }, - { - 'identifierString': '1.3.132.0.38', - 'readableName': 'ansit571k1', - 'identifier': [1, 3, 132, 0, 38] - }, - { - 'identifierString': '1.3.132.0.39', - 'readableName': 'ansit571r1', - 'identifier': [1, 3, 132, 0, 39] - }, - { - 'identifierString': '1.3.36.3.3.2.8.1.1.1', - 'readableName': 'brainpoolP160r1', - 'identifier': [1, 3, 36, 3, 3, 2, 8, 1, 1, 1] - }, - { - 'identifierString': '1.3.36.3.3.2.8.1.1.2', - 'readableName': 'brainpoolP160t1', - 'identifier': [1, 3, 36, 3, 3, 2, 8, 1, 1, 2] - }, - { - 'identifierString': '1.3.36.3.3.2.8.1.1.3', - 'readableName': 'brainpoolP192r1', - 'identifier': [1, 3, 36, 3, 3, 2, 8, 1, 1, 3] - }, - { - 'identifierString': '1.3.36.3.3.2.8.1.1.4', - 'readableName': 'brainpoolP192t1', - 'identifier': [1, 3, 36, 3, 3, 2, 8, 1, 1, 4] - }, - { - 'identifierString': '1.3.36.3.3.2.8.1.1.5', - 'readableName': 'brainpoolP224r1', - 'identifier': [1, 3, 36, 3, 3, 2, 8, 1, 1, 5] - }, - { - 'identifierString': '1.3.36.3.3.2.8.1.1.6', - 'readableName': 'brainpoolP224t1', - 'identifier': [1, 3, 36, 3, 3, 2, 8, 1, 1, 6] - }, - { - 'identifierString': '1.3.36.3.3.2.8.1.1.7', - 'readableName': 'brainpoolP256r1', - 'identifier': [1, 3, 36, 3, 3, 2, 8, 1, 1, 7] - }, - { - 'identifierString': '1.3.36.3.3.2.8.1.1.8', - 'readableName': 'brainpoolP256t1', - 'identifier': [1, 3, 36, 3, 3, 2, 8, 1, 1, 8] - }, - { - 'identifierString': '1.3.36.3.3.2.8.1.1.9', - 'readableName': 'brainpoolP320r1', - 'identifier': [1, 3, 36, 3, 3, 2, 8, 1, 1, 9] - }, - { - 'identifierString': '1.3.36.3.3.2.8.1.1.10', - 'readableName': 'brainpoolP320t1', - 'identifier': [1, 3, 36, 3, 3, 2, 8, 1, 1, 10] - }, - { - 'identifierString': '1.3.36.3.3.2.8.1.1.11', - 'readableName': 'brainpoolP384r1', - 'identifier': [1, 3, 36, 3, 3, 2, 8, 1, 1, 11] - }, - { - 'identifierString': '1.3.36.3.3.2.8.1.1.12', - 'readableName': 'brainpoolP384t1', - 'identifier': [1, 3, 36, 3, 3, 2, 8, 1, 1, 12] - }, - { - 'identifierString': '1.3.36.3.3.2.8.1.1.13', - 'readableName': 'brainpoolP512r1', - 'identifier': [1, 3, 36, 3, 3, 2, 8, 1, 1, 13] - }, - { - 'identifierString': '1.3.36.3.3.2.8.1.1.14', - 'readableName': 'brainpoolP512t1', - 'identifier': [1, 3, 36, 3, 3, 2, 8, 1, 1, 14] - }, - { - 'identifierString': '1.2.840.10045.4.3.2', - 'readableName': 'ecdsaWithSHA256', - 'identifier': [1, 2, 840, 10045, 4, 3, 2] - }, - { - 'identifierString': '2.5.4.3', - 'readableName': 'CN', - 'identifier': [2, 5, 4, 3] - }, - { - 'identifierString': '2.5.4.4', - 'readableName': 'SN', - 'identifier': [2, 5, 4, 4] - }, - { - 'identifierString': '2.5.4.5', - 'readableName': 'SERIALNUMBER', - 'identifier': [2, 5, 4, 5] - }, - { - 'identifierString': '2.5.4.6', - 'readableName': 'C', - 'identifier': [2, 5, 4, 6] - }, - { - 'identifierString': '2.5.4.7', - 'readableName': 'L', - 'identifier': [2, 5, 4, 7] - }, - { - 'identifierString': '2.5.4.8', - 'readableName': 'ST', - 'identifier': [2, 5, 4, 8] - }, - { - 'identifierString': '2.5.4.8', - 'readableName': 'S', - 'identifier': [2, 5, 4, 8] - }, - { - 'identifierString': '2.5.4.9', - 'readableName': 'streetAddress', - 'identifier': [2, 5, 4, 9] - }, - { - 'identifierString': '2.5.4.9', - 'readableName': 'STREET', - 'identifier': [2, 5, 4, 9] - }, - { - 'identifierString': '2.5.4.10', - 'readableName': 'O', - 'identifier': [2, 5, 4, 10] - }, - { - 'identifierString': '2.5.4.11', - 'readableName': 'OU', - 'identifier': [2, 5, 4, 11] - }, - { - 'identifierString': '2.5.4.12', - 'readableName': 'title', - 'identifier': [2, 5, 4, 12] - }, - { - 'identifierString': '2.5.4.12', - 'readableName': 'T', - 'identifier': [2, 5, 4, 12] - }, - { - 'identifierString': '2.5.4.12', - 'readableName': 'TITLE', - 'identifier': [2, 5, 4, 12] - }, - { - 'identifierString': '2.5.4.42', - 'readableName': 'givenName', - 'identifier': [2, 5, 4, 42] - }, - { - 'identifierString': '2.5.4.42', - 'readableName': 'G', - 'identifier': [2, 5, 4, 42] - }, - { - 'identifierString': '2.5.4.42', - 'readableName': 'GN', - 'identifier': [2, 5, 4, 42] - }, - { - 'identifierString': '1.3.132.0.35', - 'readableName': 'secp521r1', - 'identifier': [1, 3, 132, 0, 35] - }, - { - 'identifierString': '1.3.132.0.34', - 'readableName': 'secp384r1', - 'identifier': [1, 3, 132, 0, 34] - }, - { - 'identifierString': '1.2.840.10045.3.1.7', - 'readableName': 'secp256r1', - 'identifier': [1, 2, 840, 10045, 3, 1, 7] - }, - { - 'identifierString': '1.3.132.0.10', - 'readableName': 'secp256k1', - 'identifier': [1, 3, 132, 0, 10] - }, - { - 'identifierString': '2.5.29.15', - 'readableName': 'keyUsage', - 'identifier': [2, 5, 29, 15] - }, - { - 'identifierString': '2.5.29.19', - 'readableName': 'basicConstraints', - 'identifier': [2, 5, 29, 19] - }, - { - 'identifierString': '2.5.29.14', - 'readableName': 'subjectKeyIdentifier', - 'identifier': [2, 5, 29, 14] - }, - { - 'identifierString': '1.3.14.3.2.26', - 'readableName': 'SHA1', - 'identifier': [1, 3, 14, 3, 2, 26] - }, - { - 'identifierString': '1.2.840.113549.1.1.13', - 'readableName': 'sha512WithRSAEncryption', - 'identifier': [1, 2, 840, 113549, 1, 1, 13] - }, - { - 'identifierString': '1.2.840.113549.1.1.12', - 'readableName': 'sha384WithRSAEncryption', - 'identifier': [1, 2, 840, 113549, 1, 1, 12] - }, - { - 'identifierString': '1.2.840.113549.1.1.14', - 'readableName': 'sha224WithRSAEncryption', - 'identifier': [1, 2, 840, 113549, 1, 1, 14] - }, - { - 'identifierString': '1.2.840.113549.1.9.14', - 'readableName': 'extensionRequest', - 'identifier': [1, 2, 840, 113549, 1, 9, 14] - }, - { - 'identifierString': '1.2.840.10045.4.1', - 'readableName': 'ecdsaWithSHA1', - 'identifier': [1, 2, 840, 10045, 4, 1] - }, - { - 'identifierString': '1.2.840.10045.4.3.1', - 'readableName': 'ecdsaWithSHA224', - 'identifier': [1, 2, 840, 10045, 4, 3, 1] - }, - { - 'identifierString': '1.2.840.10045.4.3.3', - 'readableName': 'ecdsaWithSHA384', - 'identifier': [1, 2, 840, 10045, 4, 3, 3] - }, - { - 'identifierString': '1.2.840.10045.4.3.4', - 'readableName': 'ecdsaWithSHA512', - 'identifier': [1, 2, 840, 10045, 4, 3, 4] - }, - { - 'identifierString': '0.9.2342.19200300.100.1.1', - 'readableName': 'UID', - 'identifier': [0, 9, 2342, 19200300, 100, 1, 1] - }, - { - 'identifierString': '1.2.840.113549.1.9.1', - 'readableName': 'emailAddress', - 'identifier': [1, 2, 840, 113549, 1, 9, 1] - }, - { - 'identifierString': '2.5.4.26', - 'readableName': 'registeredAddress', - 'identifier': [2, 5, 4, 26] - }, - { - 'identifierString': '2.16.840.1.114412.1.1', - 'readableName': 'digiCertOVCert (Digicert CA policy)', - 'identifier': [2, 16, 840, 1, 114412, 1, 1] - }, - { - 'identifierString': '2.23.140.1.2.2', - 'readableName': 'organization-validated', - 'identifier': [2, 23, 140, 1, 2, 2] - } -]; diff --git a/pointycastle/lib/asn1/pkcs/pkcs1/asn1_digest_info.dart b/pointycastle/lib/asn1/pkcs/pkcs1/asn1_digest_info.dart deleted file mode 100644 index ae4d3a7..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs1/asn1_digest_info.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// DigestInfo ::= SEQUENCE { -/// digestAlgorithm DigestAlgorithmIdentifier, -/// digest Digest -/// } -/// -/// Digest ::= OCTET STRING -///``` -/// -class ASN1DigestInfo extends ASN1Object { - late ASN1AlgorithmIdentifier digestAlgorithm; - late Uint8List digest; - - ASN1DigestInfo(this.digest, this.digestAlgorithm); - - ASN1DigestInfo.fromSequence(ASN1Sequence seq) { - if (seq.elements!.length != 2) { - throw ArgumentError('Sequence has not enough elements'); - } - digestAlgorithm = ASN1AlgorithmIdentifier.fromSequence( - seq.elements!.elementAt(0) as ASN1Sequence); - var o = seq.elements!.elementAt(1) as ASN1OctetString; - if (o.valueBytes != null) { - digest = o.valueBytes!; - } - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence(elements: [ - digestAlgorithm, - ASN1OctetString(octets: digest), - ]); - return tmp.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs10/asn1_certification_request.dart b/pointycastle/lib/asn1/pkcs/pkcs10/asn1_certification_request.dart deleted file mode 100644 index afe1970..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs10/asn1_certification_request.dart +++ /dev/null @@ -1,52 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// CertificationRequest ::= SEQUENCE { -/// certificationRequestInfo CertificationRequestInfo, -/// signatureAlgorithm AlgorithmIdentifier{{ SignatureAlgorithms }}, -/// signature BIT STRING -/// } -///``` -/// -class ASN1CertificationRequest extends ASN1Object { - late ASN1Object certificationRequestInfo; - late ASN1AlgorithmIdentifier signatureAlgorithm; - late ASN1BitString signature; - - ASN1CertificationRequest( - this.certificationRequestInfo, - this.signatureAlgorithm, - this.signature, - ); - - ASN1CertificationRequest.fromSequence(ASN1Sequence seq) { - if (seq.elements == null || seq.elements!.length != 3) { - throw ArgumentError(''); - } - if (seq.elements!.elementAt(0) is! ASN1Sequence) { - throw ArgumentError('Element at index 0 has to be ASN1Sequence'); - } - if (seq.elements!.elementAt(1) is! ASN1Sequence) { - throw ArgumentError('Element at index 1 has to be ASN1Sequence'); - } - if (seq.elements!.elementAt(2) is! ASN1BitString) { - throw ArgumentError('Element at index 2 has to be ASN1BitString'); - } - certificationRequestInfo = seq.elements!.elementAt(0); - signatureAlgorithm = ASN1AlgorithmIdentifier.fromSequence( - seq.elements!.elementAt(1) as ASN1Sequence); - signature = seq.elements!.elementAt(2) as ASN1BitString; - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence( - elements: [certificationRequestInfo, signatureAlgorithm, signature]); - - return tmp.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs10/asn1_certification_request_info.dart b/pointycastle/lib/asn1/pkcs/pkcs10/asn1_certification_request_info.dart deleted file mode 100644 index ff7e966..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs10/asn1_certification_request_info.dart +++ /dev/null @@ -1,66 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// CertificationRequestInfo ::= SEQUENCE { -/// version INTEGER { v1(0) } (v1,...), -/// subject Name, -/// subjectPKInfo SubjectPublicKeyInfo{{ PKInfoAlgorithms }}, -/// attributes [0] Attributes{{ CRIAttributes }} -/// } -///``` -/// -class ASN1CertificationRequestInfo extends ASN1Object { - /// The version. The default should be 0 - late ASN1Integer version; - - /// The distinguished name of the certificate subject - late ASN1Name subject; - - /// Information about the public key being certified. - late ASN1SubjectPublicKeyInfo subjectPKInfo; - - /// Collection of attributes providing additional information about the subject of the certificate. - ASN1Object? attributes; - - ASN1CertificationRequestInfo( - this.version, - this.subject, - this.subjectPKInfo, { - this.attributes, - }); - - ASN1CertificationRequestInfo.fromSequence(ASN1Sequence seq) { - if (seq.elements == null || seq.elements!.length != 3) { - throw ArgumentError(''); - } - if (seq.elements!.elementAt(0) is! ASN1Integer) { - throw ArgumentError('Element at index 0 has to be ASN1Integer'); - } - version = seq.elements!.elementAt(0) as ASN1Integer; - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence( - elements: [version, subject, subjectPKInfo, _getWrapper()]); - - return tmp.encode(encodingRule: encodingRule); - } - - ASN1Object _getWrapper() { - var wrapper = ASN1Object(tag: 0xA0); - if (attributes != null) { - var contentBytes = attributes!.encode(); - wrapper.valueBytes = contentBytes; - wrapper.valueByteLength = contentBytes.length; - } else { - wrapper.valueBytes = Uint8List(0); - wrapper.valueByteLength = 0; - } - return wrapper; - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs10/asn1_subject_public_key_info.dart b/pointycastle/lib/asn1/pkcs/pkcs10/asn1_subject_public_key_info.dart deleted file mode 100644 index 4400022..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs10/asn1_subject_public_key_info.dart +++ /dev/null @@ -1,48 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// SubjectPublicKeyInfo { ALGORITHM : IOSet} ::= SEQUENCE { -/// algorithm AlgorithmIdentifier {{IOSet}}, -/// subjectPublicKey BIT STRING -/// } -///``` -/// -class ASN1SubjectPublicKeyInfo extends ASN1Object { - late ASN1AlgorithmIdentifier algorithm; - late ASN1BitString subjectPublicKey; - - ASN1SubjectPublicKeyInfo( - this.algorithm, - this.subjectPublicKey, - ); - - ASN1SubjectPublicKeyInfo.fromSequence(ASN1Sequence seq) { - if (seq.elements == null || seq.elements!.length != 2) { - throw ArgumentError(''); - } - if (seq.elements!.elementAt(0) is! ASN1Sequence) { - throw ArgumentError('Element at index 0 has to be ASN1Sequence'); - } - if (seq.elements!.elementAt(1) is! ASN1BitString) { - throw ArgumentError('Element at index 1 has to be ASN1BitString'); - } - algorithm = ASN1AlgorithmIdentifier.fromSequence( - seq.elements!.elementAt(0) as ASN1Sequence); - subjectPublicKey = seq.elements!.elementAt(1) as ASN1BitString; - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence( - elements: [ - algorithm, - subjectPublicKey, - ], - ); - return tmp.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_authenticated_safe.dart b/pointycastle/lib/asn1/pkcs/pkcs12/asn1_authenticated_safe.dart deleted file mode 100644 index 7874bc0..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_authenticated_safe.dart +++ /dev/null @@ -1,31 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -/// Taken from [RFC 7292](https://www.rfc-editor.org/rfc/rfc7292#page-10). -///``` -/// AuthenticatedSafe ::= SEQUENCE OF ContentInfo -///``` -/// -class ASN1AuthenticatedSafe extends ASN1Object { - late List info; - - ASN1AuthenticatedSafe(this.info); - - ASN1AuthenticatedSafe.fromSequence(ASN1Sequence seq) { - info = []; - if (seq.elements != null) { - for (var element in seq.elements!) { - info.add(ASN1ContentInfo.fromSequence(element as ASN1Sequence)); - } - } - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence(elements: info); - return tmp.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_cert_bag.dart b/pointycastle/lib/asn1/pkcs/pkcs12/asn1_cert_bag.dart deleted file mode 100644 index fef3c6b..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_cert_bag.dart +++ /dev/null @@ -1,88 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// CertBag ::= SEQUENCE { -/// certId BAG-TYPE.&id ({CertTypes}), -/// certValue [0] EXPLICIT BAG-TYPE.&Type ({CertTypes}{@certId}) -/// } -///``` -/// -class ASN1CertBag extends ASN1Object { - /// - /// Possible objectIdentifier : - /// * 1.2.840.113549.1.9.22.1 (x509Certificate) - /// * 1.2.840.113549.1.9.22.2 (sdsiCertificate) - /// - late ASN1ObjectIdentifier certId; - - /// - /// Possible objects : - /// * x509Certificate => [ASN1OctetString] - /// * sdsiCertificate => [ASN1IA5String] - /// - late ASN1Object certValue; - - ASN1CertBag(this.certId, this.certValue); - - /// - /// Constructor to create the CertBag for a X509 Certificate. - /// - ASN1CertBag.forX509Certificate(ASN1OctetString this.certValue) { - certId = - ASN1ObjectIdentifier.fromIdentifierString('1.2.840.113549.1.9.22.1'); - } - - /// - /// Constructor to create the CertBag for a SDSI Certificate. - /// - ASN1CertBag.forSdsiCertificate(ASN1IA5String this.certValue) { - certId = - ASN1ObjectIdentifier.fromIdentifierString('1.2.840.113549.1.9.22.2'); - } - - /// - /// Creates a CertBag object from the given sequence consisting of two elements : - /// * ASN1ObjectIdentifier - /// * ASN1OctetString or ASN1IA5String - /// - ASN1CertBag.fromSequence(ASN1Sequence seq) { - certId = seq.elements!.elementAt(0) as ASN1ObjectIdentifier; - if (seq.elements!.length == 2) { - var el = seq.elements!.elementAt(1); - if (el.tag == 0xA0) { - certValue = ASN1Parser(el.valueBytes).nextObject(); - } else { - certValue = el; - } - } - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var wrapper = _getWrapper(); - var tmp = ASN1Sequence(elements: [ - certId, - wrapper, - ]); - return tmp.encode(encodingRule: encodingRule); - } - - ASN1Object _getWrapper() { - var wrapper = ASN1Object(tag: 0xA0); - var contentBytes = certValue.encode(); - wrapper.valueBytes = contentBytes; - wrapper.valueByteLength = contentBytes.length; - return wrapper; - } - - ASN1CertBag.fromX509Pem(String pem) { - var bytes = ASN1Utils.getBytesFromPEMString(pem); - certValue = ASN1OctetString(octets: bytes); - certId = - ASN1ObjectIdentifier.fromIdentifierString('1.2.840.113549.1.9.22.1'); - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_key_bag.dart b/pointycastle/lib/asn1/pkcs/pkcs12/asn1_key_bag.dart deleted file mode 100644 index c5a8601..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_key_bag.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'dart:typed_data'; -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// KeyBag ::= PrivateKeyInfo -///``` -/// -class ASN1KeyBag extends ASN1Object { - ASN1PrivateKeyInfo privateKeyInfo; - - ASN1KeyBag(this.privateKeyInfo); - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - return privateKeyInfo.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_mac_data.dart b/pointycastle/lib/asn1/pkcs/pkcs12/asn1_mac_data.dart deleted file mode 100644 index f44c8f9..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_mac_data.dart +++ /dev/null @@ -1,47 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// MacData ::= SEQUENCE { -/// mac DigestInfo, -/// macSalt OCTET STRING, -/// iterations INTEGER DEFAULT 1 -/// } -///``` -/// -class ASN1MacData extends ASN1Object { - late ASN1DigestInfo mac; - late Uint8List macSalt; - late BigInt iterationCount; - - ASN1MacData(this.mac, this.macSalt, this.iterationCount); - - ASN1MacData.fromSequence(ASN1Sequence seq) { - if (seq.elements!.length != 3) { - throw ArgumentError('Sequence has not enough elements'); - } - mac = - ASN1DigestInfo.fromSequence(seq.elements!.elementAt(0) as ASN1Sequence); - var o = seq.elements!.elementAt(1) as ASN1OctetString; - if (o.valueBytes != null) { - macSalt = o.valueBytes!; - } - var i = seq.elements!.elementAt(2) as ASN1Integer; - if (i.integer != null) { - iterationCount = i.integer!; - } - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence(elements: [ - mac, - ASN1OctetString(octets: macSalt), - ASN1Integer(iterationCount), - ]); - return tmp.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_pfx.dart b/pointycastle/lib/asn1/pkcs/pkcs12/asn1_pfx.dart deleted file mode 100644 index 3710826..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_pfx.dart +++ /dev/null @@ -1,52 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// PFX ::= SEQUENCE { -/// version INTEGER {v3(3)}(v3,...), -/// authSafe ContentInfo, -/// macData MacData OPTIONAL -/// } -///``` -/// -class ASN1Pfx extends ASN1Object { - late ASN1Integer version; - late ASN1ContentInfo authSafe; - ASN1MacData? macData; - - ASN1Pfx(this.version, this.authSafe, {this.macData}); - - /// - /// Creates an instance of [PFX] from the given [sequence]. The sequence must have at least 2 elements. - /// - ASN1Pfx.fromSequence(ASN1Sequence seq) { - if (seq.elements == null || seq.elements!.isEmpty) { - throw ArgumentError('Empty sequence'); - } - if (seq.elements!.length == 1) { - throw ArgumentError('Sequence has not enough elements'); - } - version = seq.elements!.elementAt(0) as ASN1Integer; - if (version.integer!.toInt() != 3) { - throw ArgumentError('Wrong version for PFX PDU'); - } - authSafe = ASN1ContentInfo.fromSequence( - seq.elements!.elementAt(1) as ASN1Sequence); - if (seq.elements!.length == 3) { - macData = - ASN1MacData.fromSequence(seq.elements!.elementAt(2) as ASN1Sequence); - } - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence(elements: [version, authSafe]); - if (macData != null) { - tmp.add(macData!); - } - return tmp.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_pkcs12_attribute.dart b/pointycastle/lib/asn1/pkcs/pkcs12/asn1_pkcs12_attribute.dart deleted file mode 100644 index c52381a..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_pkcs12_attribute.dart +++ /dev/null @@ -1,58 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// PKCS12Attribute ::= SEQUENCE { -/// attrId ATTRIBUTE.&id ({PKCS12AttrSet}), -/// attrValues SET OF ATTRIBUTE.&Type ({PKCS12AttrSet}{@attrId}) -/// } -///``` -/// -class ASN1Pkcs12Attribute extends ASN1Object { - /// - /// Defines the type of the attribute. - /// - /// Possible objectIdentifier : - /// * 1.2.840.113549.1.9.20 (friendlyName) - /// * 1.2.840.113549.1.9.21 (localKeyID) - /// - /// See https://www.rfc-editor.org/rfc/rfc2985#section-5 for all possible attribute types. - /// - late ASN1ObjectIdentifier attrId; - - /// - /// ASN1Set containing the values, depending on the [attrId]. - /// - late ASN1Set attrValues; - - ASN1Pkcs12Attribute(this.attrId, this.attrValues); - - /// - /// Creates an instance of Attribute for friendlyName with the given [name]. - /// - ASN1Pkcs12Attribute.friendlyName(String name) { - attrId = ASN1ObjectIdentifier.fromIdentifierString('1.2.840.113549.1.9.20'); - var bmpString = ASN1BMPString(stringValue: name); - attrValues = ASN1Set(elements: [bmpString]); - } - - /// - /// Creates an instance of Attribute for localKeyID with the given [octets]. - /// - ASN1Pkcs12Attribute.localKeyID(Uint8List octets) { - //attrId = ASN1ObjectIdentifier.fromIdentifierString('1.2.840.113549.1.9.21'); - attrId = ASN1ObjectIdentifier.fromBytes(Uint8List.fromList( - [0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x15])); - var octetString = ASN1OctetString(octets: octets); - attrValues = ASN1Set(elements: [octetString]); - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence(elements: [attrId, attrValues]); - return tmp.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_safe_bag.dart b/pointycastle/lib/asn1/pkcs/pkcs12/asn1_safe_bag.dart deleted file mode 100644 index 70816b4..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_safe_bag.dart +++ /dev/null @@ -1,93 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// SafeBag ::= SEQUENCE { -/// bagId BAG-TYPE.&id ({PKCS12BagSet}) -/// bagValue [0] EXPLICIT BAG-TYPE.&Type({PKCS12BagSet}{@bagId}), -/// bagAttributes SET OF PKCS12Attribute OPTIONAL -/// } -///``` -/// -class ASN1SafeBag extends ASN1Object { - /// - /// Describes the bag type. Possible objectIdentifier : - /// - /// * 1.2.840.113549.1.12.10.1.1 (keyBag) - /// * 1.2.840.113549.1.12.10.1.2 (pkcs-8ShroudedKeyBag) - /// * 1.2.840.113549.1.12.10.1.3 (certBag) - /// * 1.2.840.113549.1.12.10.1.4 (crlBag) - /// * 1.2.840.113549.1.12.10.1.5 (secretBag) - /// * 1.2.840.113549.1.12.10.1.6 (safeContentsBag) - /// - late ASN1ObjectIdentifier bagId; - late ASN1Object bagValue; - ASN1Set? bagAttributes; - - ASN1SafeBag(this.bagId, this.bagValue, {this.bagAttributes}); - - /// - /// Constructor to create the SafeBag for a pkcs-8ShroudedKeyBag. - /// - ASN1SafeBag.forPkcs8ShroudedKeyBag(this.bagValue, {this.bagAttributes}) { - bagId = - ASN1ObjectIdentifier.fromIdentifierString('1.2.840.113549.1.12.10.1.2'); - } - - /// - /// Constructor to create the SafeBag for a certBag. - /// - ASN1SafeBag.forCertBag(this.bagValue, {this.bagAttributes}) { - bagId = - ASN1ObjectIdentifier.fromIdentifierString('1.2.840.113549.1.12.10.1.3'); - } - - /// - /// Constructor to create the SafeBag for a [KeyBag] holding a [PrivateKeyInfo]. - /// - ASN1SafeBag.forKeyBag(this.bagValue, {this.bagAttributes}) { - bagId = - ASN1ObjectIdentifier.fromIdentifierString('1.2.840.113549.1.12.10.1.1'); - } - - /// - /// Creates a SafeBag object from the given sequence consisting of up to three elements : - /// * [ASN1ObjectIdentifier] - /// * [EncryptedPrivateKeyInfo] or [CertBag] - /// * [ASN1Set] (OPTIONAL) - /// - ASN1SafeBag.fromSequence(ASN1Sequence seq) { - bagId = seq.elements!.elementAt(0) as ASN1ObjectIdentifier; - if (seq.elements!.length >= 2) { - var el = seq.elements!.elementAt(1); - if (el.tag == 0xA0) { - bagValue = ASN1Parser(el.valueBytes).nextObject(); - } else { - bagValue = el; - } - } - if (seq.elements!.length == 3) { - bagAttributes = seq.elements!.elementAt(2) as ASN1Set; - } - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence(elements: [bagId, _getWrapper()]); - if (bagAttributes != null) { - tmp.add(bagAttributes!); - } - return tmp.encode(encodingRule: encodingRule); - } - - ASN1Object _getWrapper() { - var wrapper = ASN1Object(tag: 0xA0); - var contentBytes = bagValue.encode(); - wrapper.valueBytes = contentBytes; - wrapper.valueByteLength = contentBytes.length; - return wrapper; - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_safe_contents.dart b/pointycastle/lib/asn1/pkcs/pkcs12/asn1_safe_contents.dart deleted file mode 100644 index 54aea59..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs12/asn1_safe_contents.dart +++ /dev/null @@ -1,40 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// SafeContents ::= SEQUENCE OF SafeBag -///``` -/// -class ASN1SafeContents extends ASN1Object { - /// - /// The safebags to store. - /// - late List safeBags; - - ASN1SafeContents(this.safeBags); - - /// - /// Creates a SafeContents object from the given sequence consisting of [SafeBag] or [ASN1Sequence]. - /// - ASN1SafeContents.fromSequence(ASN1Sequence seq) { - safeBags = []; - if (seq.elements != null) { - for (var element in seq.elements!) { - if (element is ASN1SafeBag) { - safeBags.add(element); - } else if (element is ASN1Sequence) { - safeBags.add(ASN1SafeBag.fromSequence(element)); - } - } - } - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence(elements: safeBags); - return tmp.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs7/asn1_content_info.dart b/pointycastle/lib/asn1/pkcs/pkcs7/asn1_content_info.dart deleted file mode 100644 index 150fa49..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs7/asn1_content_info.dart +++ /dev/null @@ -1,65 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -/// -/// ``` -/// ContentInfo ::= SEQUENCE { -/// contentType ContentType, -/// content -/// [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL } -/// ``` -/// -class ASN1ContentInfo extends ASN1Object { - late ASN1ObjectIdentifier contentType; - ASN1Object? content; - - ASN1ContentInfo(this.contentType, {this.content}); - - ASN1ContentInfo.fromSequence(ASN1Sequence seq) { - contentType = seq.elements!.elementAt(0) as ASN1ObjectIdentifier; - if (seq.elements!.length == 2) { - var el = seq.elements!.elementAt(1); - if (el.tag == 0xA0) { - content = ASN1Parser(el.valueBytes).nextObject(); - } else { - content = el; - } - } - } - - ASN1ContentInfo.forData(this.content) { - contentType = - ASN1ObjectIdentifier.fromIdentifierString('1.2.840.113549.1.7.1'); - } - - ASN1ContentInfo.forEncryptedData(this.content) { - contentType = - ASN1ObjectIdentifier.fromIdentifierString('1.2.840.113549.1.7.6'); - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var wrapper = _getWrapper(); - var tmp = ASN1Sequence(elements: [ - contentType, - wrapper, - ]); - return tmp.encode(encodingRule: encodingRule); - } - - ASN1Object _getWrapper() { - var wrapper = ASN1Object(tag: 0xA0); - if (content != null) { - var contentBytes = content!.encode(); - wrapper.valueBytes = contentBytes; - wrapper.valueByteLength = contentBytes.length; - } else { - wrapper.valueBytes = Uint8List(0); - wrapper.valueByteLength = 0; - } - return wrapper; - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs7/asn1_encrypted_content_info.dart b/pointycastle/lib/asn1/pkcs/pkcs7/asn1_encrypted_content_info.dart deleted file mode 100644 index f3f444a..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs7/asn1_encrypted_content_info.dart +++ /dev/null @@ -1,67 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; -import 'package:pointycastle/pointycastle.dart'; - -/// -///``` -/// EncryptedContentInfo ::= SEQUENCE { -/// contentType ContentType, -/// contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier, -/// encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL -/// } -///``` -/// -class ASN1EncryptedContentInfo extends ASN1Object { - late ASN1ObjectIdentifier contentType; - late ASN1AlgorithmIdentifier contentEncryptionAlgorithm; - Uint8List? encryptedContent; - - ASN1EncryptedContentInfo(this.contentType, this.contentEncryptionAlgorithm, - {this.encryptedContent}); - - ASN1EncryptedContentInfo.fromSequence(ASN1Sequence seq) { - contentType = seq.elements!.elementAt(0) as ASN1ObjectIdentifier; - if (seq.elements!.length >= 2) { - var el = seq.elements!.elementAt(1); - if (el is ASN1Sequence) { - contentEncryptionAlgorithm = ASN1AlgorithmIdentifier.fromSequence(el); - } - } - if (seq.elements!.length >= 3) { - var asn1Obj = seq.elements!.elementAt(2); - encryptedContent = asn1Obj.valueBytes; - } - } - - ASN1EncryptedContentInfo.forData( - this.contentEncryptionAlgorithm, this.encryptedContent) { - //contentType = - // ASN1ObjectIdentifier.fromIdentifierString('1.2.840.113549.1.7.1'); - contentType = ASN1ObjectIdentifier.fromBytes( - Uint8List.fromList( - [0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01]), - ); - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var wrapper = _getWrapper(); - var tmp = ASN1Sequence(elements: [ - contentType, - contentEncryptionAlgorithm, - wrapper, - ]); - return tmp.encode(encodingRule: encodingRule); - } - - ASN1Object _getWrapper() { - var wrapper = ASN1Object(tag: 0x80); - if (encryptedContent != null) { - wrapper.valueBytes = encryptedContent; - wrapper.valueByteLength = encryptedContent!.length; - } - return wrapper; - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs8/asn1_encrypted_data.dart b/pointycastle/lib/asn1/pkcs/pkcs8/asn1_encrypted_data.dart deleted file mode 100644 index 3b67c88..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs8/asn1_encrypted_data.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// EncryptedData ::= SEQUENCE { -/// version Version, -/// encryptedContentInfo EncryptedContentInfo -/// } -///``` -/// -class ASN1EncryptedData extends ASN1Object { - ASN1Integer version = ASN1Integer.fromtInt(0); - late ASN1EncryptedContentInfo encryptedContentInfo; - - ASN1EncryptedData(this.encryptedContentInfo); - - ASN1EncryptedData.fromSequence(ASN1Sequence seq) { - version = seq.elements!.elementAt(0) as ASN1Integer; - if (seq.elements!.length >= 2) { - var el = seq.elements!.elementAt(1); - if (el is ASN1Sequence) { - encryptedContentInfo = ASN1EncryptedContentInfo.fromSequence(el); - } - } - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence(elements: [ - version, - encryptedContentInfo, - ]); - return tmp.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asn1/pkcs/pkcs8/asn1_encrypted_private_key_info.dart b/pointycastle/lib/asn1/pkcs/pkcs8/asn1_encrypted_private_key_info.dart deleted file mode 100644 index 28393a4..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs8/asn1_encrypted_private_key_info.dart +++ /dev/null @@ -1,3 +0,0 @@ -import 'package:pointycastle/asn1.dart'; - -class ASN1EncryptedPrivateKeyInfo extends ASN1Object {} diff --git a/pointycastle/lib/asn1/pkcs/pkcs8/asn1_private_key_info.dart b/pointycastle/lib/asn1/pkcs/pkcs8/asn1_private_key_info.dart deleted file mode 100644 index d107201..0000000 --- a/pointycastle/lib/asn1/pkcs/pkcs8/asn1_private_key_info.dart +++ /dev/null @@ -1,108 +0,0 @@ -import 'dart:typed_data'; -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// PrivateKeyInfo ::= OneAsymmetricKey -/// -/// OneAsymmetricKey ::= SEQUENCE { -/// version Version, -/// privateKeyAlgorithm PrivateKeyAlgorithmIdentifier, -/// privateKey PrivateKey, -/// attributes [0] Attributes OPTIONAL, -/// ..., -/// [[2: publicKey [1] PublicKey OPTIONAL ]], -/// ... -/// } -///``` -/// -class ASN1PrivateKeyInfo extends ASN1Object { - late ASN1Integer version; - late ASN1AlgorithmIdentifier privateKeyAlgorithm; - late ASN1OctetString privateKey; - ASN1Set? attributes; - ASN1BitString? publicKey; - - ASN1PrivateKeyInfo(this.version, this.privateKeyAlgorithm, this.privateKey); - - /// - /// Creates an instance of PrivateKeyInfo for the given [pem]. - /// The [pem] should represent a RSA private key in PKCS1. - /// - ASN1PrivateKeyInfo.fromPkcs1RsaPem(String pem) { - var bytes = ASN1Utils.getBytesFromPEMString(pem); - var asn1Parser = ASN1Parser(bytes); - var privateKeySeq = asn1Parser.nextObject(); - privateKey = ASN1OctetString(octets: privateKeySeq.encode()); - version = ASN1Integer.fromtInt(0); - privateKeyAlgorithm = - ASN1AlgorithmIdentifier.fromIdentifier('1.2.840.113549.1.1.1'); - } - - /// - /// Creates an instance of PrivateKeyInfo for the given [pem]. - /// The [pem] should represent a RSA private key in PKCS1. - /// - ASN1PrivateKeyInfo.fromEccPem(String pem) { - var bytes = ASN1Utils.getBytesFromPEMString(pem); - var private = ASN1Utils.ecPrivateKeyFromDerBytes(bytes); - var asn1Parser = ASN1Parser(bytes); - var privateKeySeq = asn1Parser.nextObject() as ASN1Sequence; - var seq = ASN1Sequence(elements: [ - privateKeySeq.elements!.elementAt(0), - privateKeySeq.elements!.elementAt(1), - privateKeySeq.elements!.elementAt(3), - ]); - - privateKey = ASN1OctetString(octets: seq.encode()); - - version = ASN1Integer.fromtInt(0); - var param = ASN1ObjectIdentifier.fromName(private.parameters!.domainName); - privateKeyAlgorithm = ASN1AlgorithmIdentifier.fromName( - 'ecPublicKey', - parameters: param, - ); - } - - /// - /// Creates an instance of PrivateKeyInfo for the given [pem]. - /// The [pem] should represent a RSA private key in PKCS8. - /// - ASN1PrivateKeyInfo.fromPkcs8RsaPem(String pem) { - var bytes = ASN1Utils.getBytesFromPEMString(pem); - var asn1Parser = ASN1Parser(bytes); - var privateKeySeq = asn1Parser.nextObject() as ASN1Sequence; - version = privateKeySeq.elements!.elementAt(0) as ASN1Integer; - privateKeyAlgorithm = ASN1AlgorithmIdentifier.fromSequence( - privateKeySeq.elements!.elementAt(1) as ASN1Sequence); - privateKey = privateKeySeq.elements!.elementAt(2) as ASN1OctetString; - } - - /// - /// Creates an instance of PrivateKeyInfo for the given [key]. - /// The [key] should represent a RSA private key in PKCS1 format as an [ASN1Sequence]. - /// - ASN1PrivateKeyInfo.fromPkcs1Rsa(ASN1Object key) { - privateKey = ASN1OctetString(octets: key.encode()); - version = ASN1Integer.fromtInt(0); - privateKeyAlgorithm = - ASN1AlgorithmIdentifier.fromIdentifier('1.2.840.113549.1.1.1'); - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence(elements: [ - version, - privateKeyAlgorithm, - privateKey, - ]); - if (attributes != null) { - tmp.add(attributes!); - } - if (publicKey != null) { - tmp.add(publicKey!); - } - return tmp.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_bit_string.dart b/pointycastle/lib/asn1/primitives/asn1_bit_string.dart deleted file mode 100644 index f15e20e..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_bit_string.dart +++ /dev/null @@ -1,166 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_parser.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/asn1_utils.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; - -/// -/// An ASN1 Bit String object -/// -class ASN1BitString extends ASN1Object { - /// - /// The decoded string value - /// - List? stringValues; - - /// - /// The unused bits - /// - int? unusedbits; - - /// - /// A list of elements. Only set if this ASN1IA5String is constructed, otherwhise null. - /// - /// - List? elements; - - /// - /// Create an [ASN1BitString] entity with the given [stringValues]. - /// - ASN1BitString( - {this.stringValues, this.elements, int tag = ASN1Tags.BIT_STRING}) - : super(tag: tag); - - /// - /// Creates an [ASN1BitString] entity from the given [encodedBytes]. - /// - ASN1BitString.fromBytes(Uint8List super.bytes) : super.fromBytes() { - if (ASN1Utils.isConstructed(encodedBytes!.elementAt(0))) { - elements = []; - var parser = ASN1Parser(valueBytes); - stringValues = []; - while (parser.hasNext()) { - var bitString = parser.nextObject() as ASN1BitString; - stringValues!.addAll(bitString.stringValues!); - elements!.add(bitString); - } - } else { - unusedbits = valueBytes![0]; - stringValues = valueBytes!.sublist(1); - } - } - - /// - /// Encodes this ASN1Object depending on the given [encodingRule] - /// - /// If no [ASN1EncodingRule] is given, ENCODING_DER will be used. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// * [ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM] - /// * [ASN1EncodingRule.ENCODING_BER_CONSTRUCTED] - /// * [ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH] - /// * [ASN1EncodingRule.ENCODING_BER_PADDED] - /// - /// Throws an [UnsupportedAsn1EncodingRuleException] if the given [encodingRule] is not supported. - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - switch (encodingRule) { - case ASN1EncodingRule.ENCODING_BER_PADDED: - case ASN1EncodingRule.ENCODING_DER: - case ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM: - var b = []; - if (unusedbits != null) { - b.add(unusedbits!); - } else { - b.add(0); - } - b.addAll(stringValues!); - valueBytes = Uint8List.fromList(b); - break; - case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH: - case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED: - valueByteLength = 0; - if (elements == null) { - elements = []; - elements!.add(ASN1BitString(stringValues: stringValues)); - } - valueByteLength = _childLength( - isIndefinite: encodingRule == - ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH); - valueBytes = Uint8List(valueByteLength!); - var i = 0; - for (var obj in elements!) { - var b = obj.encode(); - valueBytes!.setRange(i, i + b.length, b); - i += b.length; - } - break; - } - - return super.encode(encodingRule: encodingRule); - } - - /// - /// Calculate encoded length of all children - /// - int _childLength({bool isIndefinite = false}) { - var l = 0; - for (var obj in elements!) { - l += obj.encode().length; - } - if (isIndefinite) { - return l + 2; - } - return l; - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - if (isConstructed!) { - sb.write('BIT STRING (${elements!.length} elem)'); - for (var e in elements!) { - var dump = e.dump(spaces: spaces + dumpIndent); - sb.write('\n$dump'); - } - } else { - if (ASN1Utils.isASN1Tag(stringValues!.elementAt(0))) { - var sb2 = StringBuffer(); - for (var v in stringValues!) { - var s = v.toRadixString(2); - sb2.write(s); - } - var bits = sb2.toString(); - if (unusedbits != null) { - bits = bits.substring(0, bits.length - unusedbits!); - } - var parser = ASN1Parser(stringValues as Uint8List?); - var next = parser.nextObject(); - var dump = next.dump(spaces: spaces + dumpIndent); - sb.write('BIT STRING (${bits.length} bit)\n$dump'); - } else { - var sb2 = StringBuffer(); - for (var v in stringValues!) { - var s = v.toRadixString(2); - sb2.write(s); - } - var bits = sb2.toString(); - if (unusedbits != null) { - bits = bits.substring(0, bits.length - unusedbits!); - } - sb.write('BIT STRING (${bits.length} bit) '); - sb.write(bits); - } - } - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_bmp_string.dart b/pointycastle/lib/asn1/primitives/asn1_bmp_string.dart deleted file mode 100644 index 580d3c6..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_bmp_string.dart +++ /dev/null @@ -1,143 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_parser.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/asn1_utils.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; - -/// -/// An ASN1 IA5 String object -/// -class ASN1BMPString extends ASN1Object { - /// - /// The ascii decoded string value - /// - String? stringValue; - - /// - /// A list of elements. Only set if this ASN1BMPString is constructed, otherwhise null. - /// - List? elements; - - /// - /// Create an [ASN1BMPString] entity with the given [stringValue]. - /// - ASN1BMPString( - {this.stringValue, this.elements, int tag = ASN1Tags.BMP_STRING}) - : super(tag: tag); - - /// - /// Creates an [ASN1BMPString] entity from the given [encodedBytes]. - /// - ASN1BMPString.fromBytes(Uint8List encodedBytes) - : super.fromBytes(encodedBytes) { - if (ASN1Utils.isConstructed(encodedBytes.elementAt(0))) { - elements = []; - var parser = ASN1Parser(valueBytes); - var sb = StringBuffer(); - while (parser.hasNext()) { - var bmpString = parser.nextObject() as ASN1BMPString; - sb.write(bmpString.stringValue); - elements!.add(bmpString); - } - stringValue = sb.toString(); - } else { - var utf16CodeUnits = []; - - for (var i = 0; i < valueBytes!.length; i += 2) { - // Combine High-Byte and Low-Byte to create a UTF-16 code unit - var highByte = valueBytes![i]; - var lowByte = valueBytes![i + 1]; - utf16CodeUnits.add((highByte << 8) | lowByte); - } - - // Decode UTF-16 code units into a Dart String - stringValue = String.fromCharCodes(utf16CodeUnits); - } - } - - /// - /// Encodes this ASN1Object depending on the given [encodingRule] - /// - /// If no [ASN1EncodingRule] is given, ENCODING_DER will be used. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// * [ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM] - /// * [ASN1EncodingRule.ENCODING_BER_CONSTRUCTED] - /// * [ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH] - /// - /// Throws an [UnsupportedAsn1EncodingRuleException] if the given [encodingRule] is not supported. - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - switch (encodingRule) { - case ASN1EncodingRule.ENCODING_DER: - case ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM: - // Kodierung in UTF-16-Big-Endian (UCS-2) - var l = []; - for (var codeUnit in stringValue!.codeUnits) { - l.add((codeUnit >> 8) & 0xFF); // High-Byte - l.add(codeUnit & 0xFF); // Low-Byte - } - valueBytes = Uint8List.fromList(l); - break; - case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH: - case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED: - valueByteLength = 0; - if (elements == null) { - elements!.add(ASN1BMPString(stringValue: stringValue)); - } - valueByteLength = _childLength( - isIndefinite: encodingRule == - ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH); - valueBytes = Uint8List(valueByteLength!); - var i = 0; - for (var obj in elements!) { - var b = obj.encode(); - valueBytes!.setRange(i, i + b.length, b); - i += b.length; - } - break; - case ASN1EncodingRule.ENCODING_BER_PADDED: - throw UnsupportedAsn1EncodingRuleException(encodingRule); - } - - return super.encode(encodingRule: encodingRule); - } - - /// - /// Calculate encoded length of all children - /// - int _childLength({bool isIndefinite = false}) { - var l = 0; - for (var obj in elements!) { - l += obj.encode().length; - } - if (isIndefinite) { - return l + 2; - } - return l; - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - if (isConstructed!) { - sb.write('BMPString (${elements!.length} elem)'); - for (var e in elements!) { - var dump = e.dump(spaces: spaces + dumpIndent); - sb.write('\n $dump'); - } - } else { - sb.write('BMPString $stringValue'); - } - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_boolean.dart b/pointycastle/lib/asn1/primitives/asn1_boolean.dart deleted file mode 100644 index 6eb0056..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_boolean.dart +++ /dev/null @@ -1,68 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; - -/// -/// An ASN1 Boolean object -/// -class ASN1Boolean extends ASN1Object { - bool? boolValue; - - /// - /// The byte to use for the TRUE value - /// - static const int BOOLEAN_TRUE_VALUE = 0xff; - - /// - /// The byte to use for the FALSE value - /// - static const int BOOLEAN_FALSE_VALUE = 0x00; - - /// - /// Creates an [ASN1Boolean] entity with the given [boolValue]. - /// - ASN1Boolean(this.boolValue, {int tag = ASN1Tags.BOOLEAN}) : super(tag: tag); - - /// - /// Creates an [ASN1Boolean] entity from the given [encodedBytes]. - /// - ASN1Boolean.fromBytes(Uint8List super.encodedBytes) : super.fromBytes() { - boolValue = (valueBytes![0] == BOOLEAN_TRUE_VALUE); - } - - /// - /// Encodes this ASN1Object depending on the given [encodingRule] - /// - /// If no [ASN1EncodingRule] is given, ENCODING_DER will be used. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// - /// Throws an [UnsupportedAsn1EncodingRuleException] if the given [encodingRule] is not supported. - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - if (encodingRule != ASN1EncodingRule.ENCODING_DER) { - throw UnsupportedAsn1EncodingRuleException(encodingRule); - } - valueByteLength = 1; - valueBytes = (boolValue == true) - ? Uint8List.fromList([BOOLEAN_TRUE_VALUE]) - : Uint8List.fromList([BOOLEAN_FALSE_VALUE]); - return super.encode(); - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - sb.write('BOOLEAN $boolValue'); - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_enumerated.dart b/pointycastle/lib/asn1/primitives/asn1_enumerated.dart deleted file mode 100644 index d8fc673..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_enumerated.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/primitives/asn1_integer.dart'; - -/// -/// An ASN1Enumerated object -/// -class ASN1Enumerated extends ASN1Integer { - /// - /// Create an [ASN1Enumerated] entity with the given integer [i]. - /// - ASN1Enumerated(int i, {int tag = ASN1Tags.ENUMERATED}) - : super(BigInt.from(i), tag: tag); - - /// - /// Creates an [ASN1Enumerated] entity from the given [encodedBytes]. - /// - ASN1Enumerated.fromBytes(super.encodedBytes) : super.fromBytes(); -} diff --git a/pointycastle/lib/asn1/primitives/asn1_generalized_time.dart b/pointycastle/lib/asn1/primitives/asn1_generalized_time.dart deleted file mode 100644 index 58f75be..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_generalized_time.dart +++ /dev/null @@ -1,79 +0,0 @@ -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; - -class ASN1GeneralizedTime extends ASN1Object { - // The decoded date value - DateTime? dateTimeValue; - - /// - /// Create an [ASN1GeneralizedTime] entity with the given BigInt [dateTimeValue]. - /// - ASN1GeneralizedTime(this.dateTimeValue, {int tag = ASN1Tags.GENERALIZED_TIME}) - : super(tag: tag); - - /// - /// Creates an [ASN1GeneralizedTime] entity from the given [encodedBytes]. - /// - ASN1GeneralizedTime.fromBytes(Uint8List super.bytes) : super.fromBytes() { - var octets = valueBytes!; - var stringValue = ascii.decode(octets); - var year = stringValue.substring(0, 4); - var month = stringValue.substring(4, 6); - var day = stringValue.substring(6, 8); - var hour = stringValue.substring(8, 10); - var minute = stringValue.substring(10, 12); - var second = stringValue.substring(12, 14); - if (stringValue.length > 14) { - var timeZone = stringValue.substring(14, stringValue.length); - dateTimeValue = - DateTime.parse('$year-$month-$day $hour:$minute:$second$timeZone'); - } else { - dateTimeValue = DateTime.parse('$year-$month-$day $hour:$minute:$second'); - } - } - - /// - /// Encodes this ASN1Object depending on the given [encodingRule] - /// - /// If no [ASN1EncodingRule] is given, ENCODING_DER will be used. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// - /// Throws an [UnsupportedAsn1EncodingRuleException] if the given [encodingRule] is not supported. - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - if (encodingRule != ASN1EncodingRule.ENCODING_DER) { - throw UnsupportedAsn1EncodingRuleException(encodingRule); - } - var utc = dateTimeValue!.toUtc(); - var year = utc.year.toString(); - var month = utc.month.toString(); - var day = utc.day.toString(); - var hour = utc.hour.toString(); - var minute = utc.minute.toString(); - var second = utc.second.toString(); - // Encode string to YYMMDDhhmm[ss]Z - var utcString = '$year$month$day$hour$minute${second}Z'; - valueBytes = ascii.encode(utcString); - valueByteLength = valueBytes!.length; - return super.encode(); - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - sb.write('GENERALIZEDTIME ${dateTimeValue!.toIso8601String()}'); - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_ia5_string.dart b/pointycastle/lib/asn1/primitives/asn1_ia5_string.dart deleted file mode 100644 index 7adcff6..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_ia5_string.dart +++ /dev/null @@ -1,130 +0,0 @@ -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_parser.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/asn1_utils.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; - -/// -/// An ASN1 IA5 String object -/// -class ASN1IA5String extends ASN1Object { - /// - /// The ascii decoded string value - /// - String? stringValue; - - /// - /// A list of elements. Only set if this ASN1IA5String is constructed, otherwhise null. - /// - List? elements; - - /// - /// Create an [ASN1IA5String] entity with the given [stringValue]. - /// - ASN1IA5String( - {this.stringValue, this.elements, int tag = ASN1Tags.IA5_STRING}) - : super(tag: tag); - - /// - /// Creates an [ASN1IA5String] entity from the given [encodedBytes]. - /// - ASN1IA5String.fromBytes(Uint8List encodedBytes) - : super.fromBytes(encodedBytes) { - if (ASN1Utils.isConstructed(encodedBytes.elementAt(0))) { - elements = []; - var parser = ASN1Parser(valueBytes); - var sb = StringBuffer(); - while (parser.hasNext()) { - var ia5String = parser.nextObject() as ASN1IA5String; - sb.write(ia5String.stringValue); - elements!.add(ia5String); - } - stringValue = sb.toString(); - } else { - stringValue = ascii.decode(valueBytes!); - } - } - - /// - /// Encodes this ASN1Object depending on the given [encodingRule] - /// - /// If no [ASN1EncodingRule] is given, ENCODING_DER will be used. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// * [ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM] - /// * [ASN1EncodingRule.ENCODING_BER_CONSTRUCTED] - /// * [ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH] - /// - /// Throws an [UnsupportedAsn1EncodingRuleException] if the given [encodingRule] is not supported. - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - switch (encodingRule) { - case ASN1EncodingRule.ENCODING_DER: - case ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM: - var octets = ascii.encode(stringValue!); - valueByteLength = octets.length; - valueBytes = Uint8List.fromList(octets); - break; - case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH: - case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED: - valueByteLength = 0; - if (elements == null) { - elements!.add(ASN1IA5String(stringValue: stringValue)); - } - valueByteLength = _childLength( - isIndefinite: encodingRule == - ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH); - valueBytes = Uint8List(valueByteLength!); - var i = 0; - for (var obj in elements!) { - var b = obj.encode(); - valueBytes!.setRange(i, i + b.length, b); - i += b.length; - } - break; - case ASN1EncodingRule.ENCODING_BER_PADDED: - throw UnsupportedAsn1EncodingRuleException(encodingRule); - } - - return super.encode(encodingRule: encodingRule); - } - - /// - /// Calculate encoded length of all children - /// - int _childLength({bool isIndefinite = false}) { - var l = 0; - for (var obj in elements!) { - l += obj.encode().length; - } - if (isIndefinite) { - return l + 2; - } - return l; - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - if (isConstructed!) { - sb.write('IA5String (${elements!.length} elem)'); - for (var e in elements!) { - var dump = e.dump(spaces: spaces + dumpIndent); - sb.write('\n $dump'); - } - } else { - sb.write('IA5String $stringValue'); - } - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_integer.dart b/pointycastle/lib/asn1/primitives/asn1_integer.dart deleted file mode 100644 index 2e936eb..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_integer.dart +++ /dev/null @@ -1,72 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; -import 'package:pointycastle/src/utils.dart'; - -class ASN1Integer extends ASN1Object { - /// - /// The integer value - /// - BigInt? integer; - - /// - /// Create an [ASN1Integer] entity with the given BigInt [integer]. - /// - ASN1Integer(this.integer, {int tag = ASN1Tags.INTEGER}) : super(tag: tag); - - /// - /// Create an [ASN1Integer] entity with the given int [i]. - /// - ASN1Integer.fromtInt(int i, {int tag = ASN1Tags.INTEGER}) : super(tag: tag) { - integer = BigInt.from(i); - } - - /// - /// Creates an [ASN1Integer] entity from the given [encodedBytes]. - /// - ASN1Integer.fromBytes(Uint8List super.encodedBytes) : super.fromBytes() { - integer = decodeBigInt(valueBytes!); - } - - /// - /// Encodes this ASN1Object depending on the given [encodingRule] - /// - /// If no [ASN1EncodingRule] is given, ENCODING_DER will be used. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// - /// Throws an [UnsupportedAsn1EncodingRuleException] if the given [encodingRule] is not supported. - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - if (encodingRule != ASN1EncodingRule.ENCODING_DER) { - throw UnsupportedAsn1EncodingRuleException(encodingRule); - } - if (integer!.bitLength == 0) { - if (integer == BigInt.from(-1)) { - valueBytes = Uint8List.fromList([0xff]); - } else { - valueBytes = Uint8List.fromList([0]); - } - } else { - valueBytes = encodeBigInt(integer); - } - valueByteLength = valueBytes!.length; - return super.encode(); - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - sb.write('INTEGER ${integer.toString().toUpperCase()}'); - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_null.dart b/pointycastle/lib/asn1/primitives/asn1_null.dart deleted file mode 100644 index b626c40..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_null.dart +++ /dev/null @@ -1,53 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; - -/// -/// An ASN1 Null object -/// -class ASN1Null extends ASN1Object { - /// - /// Creates an empty [ASN1Null] entity with only the [tag] set. - /// - ASN1Null({int tag = ASN1Tags.NULL}) : super(tag: tag); - - /// - /// Creates an [ASN1Null] entity from the given [encodedBytes]. - /// - ASN1Null.fromBytes(Uint8List super.encodedBytes) : super.fromBytes(); - - /// - /// Encode the [ASN1Null] to the byte representation. - /// - /// This basically returns **[0x05, 0x00]** or **[0x05, 0x81, 0x00]** depending on the [encodingRule] and will not call the *super.encode()* method. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// * [ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM] - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - switch (encodingRule) { - case ASN1EncodingRule.ENCODING_DER: - return Uint8List.fromList([tag!, 0x00]); - case ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM: - return Uint8List.fromList([tag!, 0x81, 0x00]); - default: - throw UnsupportedAsn1EncodingRuleException(encodingRule); - } - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - sb.write('NULL'); - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_object_identifier.dart b/pointycastle/lib/asn1/primitives/asn1_object_identifier.dart deleted file mode 100644 index 76b9ecd..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_object_identifier.dart +++ /dev/null @@ -1,189 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/object_identifiers.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; -import 'package:pointycastle/asn1/unsupported_object_identifier_exception.dart'; - -class ASN1ObjectIdentifier extends ASN1Object { - /// - /// The object identifier integer values - /// - List? objectIdentifier; - - /// - /// The String representation of the [objectIdentifier] - /// - String? objectIdentifierAsString; - - /// - /// The readable representation of the [objectIdentifier] - /// - String? readableName; - - /// - /// Create an [ASN1ObjectIdentifier] entity with the given [objectIdentifier]. - /// - ASN1ObjectIdentifier(this.objectIdentifier, - {int tag = ASN1Tags.OBJECT_IDENTIFIER}) - : super(tag: tag) { - objectIdentifierAsString = objectIdentifier!.join('.'); - } - - /// - /// Creates an [ASN1ObjectIdentifier] entity from the given [encodedBytes]. - /// - ASN1ObjectIdentifier.fromBytes(Uint8List super.encodedBytes) - : super.fromBytes() { - var value = 0; - var first = true; - BigInt? bigValue; - var list = []; - var sb = StringBuffer(); - for (var element in valueBytes!) { - var b = element & 0xff; - if (value < 0x80000000000000) { - value = value * 128 + (b & 0x7f); - if ((b & 0x80) == 0) { - if (first) { - var truncated = value ~/ 40; - if (truncated < 2) { - list.add(truncated); - sb.write(truncated); - value -= truncated * 40; - } else { - list.add(2); - sb.write('2'); - value -= 80; - } - first = false; - } - list.add(value); - sb.write('.$value'); - value = 0; - } - } else { - bigValue ??= BigInt.from(value); - bigValue = bigValue << (7); - bigValue = bigValue | BigInt.from(b & 0x7f); - if ((b & 0x80) == 0) { - sb.write('.$bigValue'); - bigValue = null; - value = 0; - } - } - } - objectIdentifierAsString = sb.toString(); - objectIdentifier = Uint8List.fromList(list); - var identifier = - ObjectIdentifiers.getIdentifierByIdentifier(objectIdentifierAsString); - if (identifier != null) { - readableName = identifier['readableName'] as String?; - } - } - - /// - /// Creates an [ASN1ObjectIdentifier] entity from the given [name]. - /// - /// Example: - /// ``` - /// var oi = ASN1ObjectIdentifier.fromName('ecdsaWithSHA256'); - /// ``` - /// - /// Throws an [UnsupportedObjectIdentifierException] if the given [name] is not supported - /// - ASN1ObjectIdentifier.fromName(String name) { - tag = ASN1Tags.OBJECT_IDENTIFIER; - var identifier = ObjectIdentifiers.getIdentifierByName(name); - if (identifier == null) { - throw UnsupportedObjectIdentifierException(name); - } - objectIdentifierAsString = identifier['identifierString'] as String?; - readableName = identifier['readableName'] as String?; - objectIdentifier = identifier['identifier'] as List?; - } - - /// - /// Creates an [ASN1ObjectIdentifier] entity from the given [objectIdentifierAsString]. - /// - /// Example: - /// ``` - /// var oi = ASN1ObjectIdentifier.fromName('2.5.4.3'); - /// ``` - /// - /// Throws an [UnsupportedObjectIdentifierException] if the given [objectIdentifierAsString] is not supported - /// - ASN1ObjectIdentifier.fromIdentifierString(this.objectIdentifierAsString, - {int tag = ASN1Tags.OBJECT_IDENTIFIER}) - : super(tag: tag) { - var identifier = - ObjectIdentifiers.getIdentifierByIdentifier(objectIdentifierAsString); - if (identifier != null) { - objectIdentifierAsString = identifier['identifierString'] as String?; - readableName = identifier['readableName'] as String?; - objectIdentifier = identifier['identifier'] as List?; - } else { - var splittedInts = objectIdentifierAsString!.split('.'); - objectIdentifier = []; - for (var i in splittedInts) { - objectIdentifier!.add(int.parse(i)); - } - } - } - - /// - /// Encodes this ASN1Object depending on the given [encodingRule] - /// - /// If no [ASN1EncodingRule] is given, ENCODING_DER will be used. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// - /// Throws an [UnsupportedAsn1EncodingRuleException] if the given [encodingRule] is not supported. - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - if (encodingRule != ASN1EncodingRule.ENCODING_DER) { - throw UnsupportedAsn1EncodingRuleException(encodingRule); - } - var oi = []; - oi.add(objectIdentifier![0] * 40 + objectIdentifier![1]); - - for (var ci = 2; ci < objectIdentifier!.length; ci++) { - var position = oi.length; - var v = objectIdentifier![ci]; - assert(v >= 0); - - var first = true; - do { - var remainder = v & 127; - v = v >> 7; - if (first) { - first = false; - } else { - remainder |= 0x80; - } - - oi.insert(position, remainder); - } while (v > 0); - } - - valueBytes = Uint8List.fromList(oi); - valueByteLength = oi.length; - - return super.encode(); - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - sb.write('OBJECT IDENTIFIER $objectIdentifierAsString $readableName'); - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_octet_string.dart b/pointycastle/lib/asn1/primitives/asn1_octet_string.dart deleted file mode 100644 index d518655..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_octet_string.dart +++ /dev/null @@ -1,133 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_parser.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/asn1_utils.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; - -/// -/// An ASN1 Octed String object -/// -class ASN1OctetString extends ASN1Object { - /// - /// The decoded string value - /// - Uint8List? octets; - - /// - /// A list of elements. Only set if this ASN1OctetString is constructed, otherwhise null. - /// - List? elements; - - /// - /// Create an [ASN1OctetString] entity with the given [octets]. - /// - ASN1OctetString({this.octets, this.elements, int tag = ASN1Tags.OCTET_STRING}) - : super(tag: tag); - - /// - /// Creates an [ASN1OctetString] entity from the given [encodedBytes]. - /// - ASN1OctetString.fromBytes(Uint8List encodedBytes) - : super.fromBytes(encodedBytes) { - if (ASN1Utils.isConstructed(encodedBytes.elementAt(0))) { - elements = []; - var parser = ASN1Parser(valueBytes); - var bytes = []; - while (parser.hasNext()) { - var octetString = parser.nextObject() as ASN1OctetString; - bytes.addAll(octetString.octets!); - elements!.add(octetString); - } - octets = Uint8List.fromList(bytes); - } else { - octets = valueBytes; - } - } - - /// - /// Encodes this ASN1Object depending on the given [encodingRule] - /// - /// If no [ASN1EncodingRule] is given, ENCODING_DER will be used. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// * [ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM] - /// * [ASN1EncodingRule.ENCODING_BER_CONSTRUCTED] - /// * [ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH] - /// - /// Throws an [UnsupportedAsn1EncodingRuleException] if the given [encodingRule] is not supported. - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - switch (encodingRule) { - case ASN1EncodingRule.ENCODING_DER: - case ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM: - valueByteLength = octets!.length; - valueBytes = octets; - break; - case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED: - case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH: - valueByteLength = 0; - if (elements == null) { - elements!.add(ASN1OctetString(octets: octets)); - } - valueByteLength = _childLength( - isIndefinite: encodingRule == - ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH); - valueBytes = Uint8List(valueByteLength!); - var i = 0; - for (var obj in elements!) { - var b = obj.encode(); - valueBytes!.setRange(i, i + b.length, b); - i += b.length; - } - break; - case ASN1EncodingRule.ENCODING_BER_PADDED: - throw UnsupportedAsn1EncodingRuleException(encodingRule); - } - return super.encode(encodingRule: encodingRule); - } - - /// - /// Calculate encoded length of all children - /// - int _childLength({bool isIndefinite = false}) { - var l = 0; - for (var obj in elements!) { - l += obj.encode().length; - } - if (isIndefinite) { - return l + 2; - } - return l; - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - if (isConstructed!) { - sb.write('OCTET STRING (${elements!.length} elem)'); - for (var e in elements!) { - var dump = e.dump(spaces: spaces + dumpIndent); - sb.write('\n $dump'); - } - } else { - sb.write('OCTET STRING (${octets!.length} byte) '); - for (var o in octets!) { - var s = o.toRadixString(16).toUpperCase(); - if (s.length == 1) { - s = '0$s'; - } - sb.write(s); - } - } - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_printable_string.dart b/pointycastle/lib/asn1/primitives/asn1_printable_string.dart deleted file mode 100644 index f12c897..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_printable_string.dart +++ /dev/null @@ -1,130 +0,0 @@ -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_parser.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/asn1_utils.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; - -/// -/// An ASN1 Printable String object -/// -class ASN1PrintableString extends ASN1Object { - /// - /// The ascii decoded string value - /// - String? stringValue; - - /// - /// A list of elements. Only set if this ASN1PrintableString is constructed, otherwhise null. - /// - List? elements; - - /// - /// Create an [ASN1PrintableString] entity with the given [stringValue]. - /// - ASN1PrintableString( - {this.stringValue, this.elements, int tag = ASN1Tags.PRINTABLE_STRING}) - : super(tag: tag); - - /// - /// Creates an [ASN1PrintableString] entity from the given [encodedBytes]. - /// - ASN1PrintableString.fromBytes(Uint8List encodedBytes) - : super.fromBytes(encodedBytes) { - if (ASN1Utils.isConstructed(encodedBytes.elementAt(0))) { - elements = []; - var parser = ASN1Parser(valueBytes); - var sb = StringBuffer(); - while (parser.hasNext()) { - var printableString = parser.nextObject() as ASN1PrintableString; - sb.write(printableString.stringValue); - elements!.add(printableString); - } - stringValue = sb.toString(); - } else { - stringValue = ascii.decode(valueBytes!); - } - } - - /// - /// Encodes this ASN1Object depending on the given [encodingRule] - /// - /// If no [ASN1EncodingRule] is given, ENCODING_DER will be used. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// * [ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM] - /// * [ASN1EncodingRule.ENCODING_BER_CONSTRUCTED] - /// * [ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH] - /// - /// Throws an [UnsupportedAsn1EncodingRuleException] if the given [encodingRule] is not supported. - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - switch (encodingRule) { - case ASN1EncodingRule.ENCODING_DER: - case ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM: - var octets = ascii.encode(stringValue!); - valueByteLength = octets.length; - valueBytes = Uint8List.fromList(octets); - break; - case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH: - case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED: - valueByteLength = 0; - if (elements == null) { - elements!.add(ASN1PrintableString(stringValue: stringValue)); - } - valueByteLength = _childLength( - isIndefinite: encodingRule == - ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH); - valueBytes = Uint8List(valueByteLength!); - var i = 0; - for (var obj in elements!) { - var b = obj.encode(); - valueBytes!.setRange(i, i + b.length, b); - i += b.length; - } - break; - case ASN1EncodingRule.ENCODING_BER_PADDED: - throw UnsupportedAsn1EncodingRuleException(encodingRule); - } - - return super.encode(encodingRule: encodingRule); - } - - /// - /// Calculate encoded length of all children - /// - int _childLength({bool isIndefinite = false}) { - var l = 0; - for (var obj in elements!) { - l += obj.encode().length; - } - if (isIndefinite) { - return l + 2; - } - return l; - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - if (isConstructed!) { - sb.write('PRINTABLE STRING (${elements!.length} elem)'); - for (var e in elements!) { - var dump = e.dump(spaces: spaces + dumpIndent); - sb.write('\n$dump'); - } - } else { - sb.write('PRINTABLE STRING $stringValue'); - } - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_sequence.dart b/pointycastle/lib/asn1/primitives/asn1_sequence.dart deleted file mode 100644 index 325181a..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_sequence.dart +++ /dev/null @@ -1,94 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_parser.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; - -class ASN1Sequence extends ASN1Object { - /// - /// The decoded string value - /// - List? elements = []; - - /// - /// Create an [ASN1Sequence] entity with the given [elements]. - /// - ASN1Sequence({this.elements, int tag = ASN1Tags.SEQUENCE}) : super(tag: tag); - - /// - /// Creates an [ASN1Sequence] entity from the given [encodedBytes]. - /// - ASN1Sequence.fromBytes(Uint8List super.encodedBytes) : super.fromBytes() { - elements = []; - var parser = ASN1Parser(valueBytes); - while (parser.hasNext()) { - elements!.add(parser.nextObject()); - } - } - - /// - /// Encodes this ASN1Object depending on the given [encodingRule] - /// - /// If no [ASN1EncodingRule] is given, ENCODING_DER will be used. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// - /// Throws an [UnsupportedAsn1EncodingRuleException] if the given [encodingRule] is not supported. - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - if (encodingRule != ASN1EncodingRule.ENCODING_DER) { - throw UnsupportedAsn1EncodingRuleException(encodingRule); - } - valueBytes = Uint8List(0); - valueByteLength = 0; - if (elements != null) { - valueByteLength = _childLength(); - valueBytes = Uint8List(valueByteLength!); - var i = 0; - for (var obj in elements!) { - var b = obj.encode(); - valueBytes!.setRange(i, i + b.length, b); - i += b.length; - } - } - return super.encode(); - } - - /// - /// Calculate encoded length of all children - /// - int _childLength() { - var l = 0; - for (var obj in elements!) { - l += obj.encode().length; - } - return l; - } - - /// - /// Adds the given [obj] to the [elements] list. - /// - void add(ASN1Object obj) { - elements ??= []; - elements!.add(obj); - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - sb.write('SEQUENCE (${elements!.length} elem)'); - for (var e in elements!) { - var dump = e.dump(spaces: spaces + dumpIndent); - sb.write('\n$dump'); - } - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_set.dart b/pointycastle/lib/asn1/primitives/asn1_set.dart deleted file mode 100644 index 895c089..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_set.dart +++ /dev/null @@ -1,94 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_parser.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; - -class ASN1Set extends ASN1Object { - /// - /// The decoded string value - /// - List? elements; - - /// - /// Create an [ASN1Set] entity with the given [elements]. - /// - ASN1Set({this.elements, int tag = ASN1Tags.SET}) : super(tag: tag); - - /// - /// Creates an [ASN1Set] entity from the given [encodedBytes]. - /// - ASN1Set.fromBytes(Uint8List super.encodedBytes) : super.fromBytes() { - elements = []; - var parser = ASN1Parser(valueBytes); - while (parser.hasNext()) { - elements!.add(parser.nextObject()); - } - } - - /// - /// Encodes this ASN1Object depending on the given [encodingRule] - /// - /// If no [ASN1EncodingRule] is given, ENCODING_DER will be used. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// - /// Throws an [UnsupportedAsn1EncodingRuleException] if the given [encodingRule] is not supported. - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - if (encodingRule != ASN1EncodingRule.ENCODING_DER) { - throw UnsupportedAsn1EncodingRuleException(encodingRule); - } - valueBytes = Uint8List(0); - valueByteLength = 0; - if (elements != null) { - valueByteLength = _childLength(); - valueBytes = Uint8List(valueByteLength!); - var i = 0; - for (var obj in elements!) { - var b = obj.encode(); - valueBytes!.setRange(i, i + b.length, b); - i += b.length; - } - } - return super.encode(); - } - - /// - /// Calculate encoded length of all children - /// - int _childLength() { - var l = 0; - for (var obj in elements!) { - l += obj.encode().length; - } - return l; - } - - /// - /// Adds the given [obj] to the [elements] list. - /// - void add(ASN1Object obj) { - elements ??= []; - elements!.add(obj); - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - sb.write('SET (${elements!.length} elem)'); - for (var e in elements!) { - var dump = e.dump(spaces: spaces + dumpIndent); - sb.write('\n$dump'); - } - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_teletext_string.dart b/pointycastle/lib/asn1/primitives/asn1_teletext_string.dart deleted file mode 100644 index f4a6a34..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_teletext_string.dart +++ /dev/null @@ -1,130 +0,0 @@ -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_parser.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/asn1_utils.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; - -/// -/// An ASN1 Octed String object -/// -class ASN1TeletextString extends ASN1Object { - /// - /// The ascii decoded string value - /// - String? stringValue; - - /// - /// A list of elements. Only set if this ASN1TeletextString is constructed, otherwhise null. - /// - List? elements; - - /// - /// Create an [ASN1TeletextString] entity with the given [stringValue]. - /// - ASN1TeletextString( - {this.stringValue, this.elements, int tag = ASN1Tags.T61_STRING}) - : super(tag: tag); - - /// - /// Creates an [ASN1TeletextString] entity from the given [encodedBytes]. - /// - ASN1TeletextString.fromBytes(Uint8List encodedBytes) - : super.fromBytes(encodedBytes) { - if (ASN1Utils.isConstructed(encodedBytes.elementAt(0))) { - elements = []; - var parser = ASN1Parser(valueBytes); - var sb = StringBuffer(); - while (parser.hasNext()) { - var printableString = parser.nextObject() as ASN1TeletextString; - sb.write(printableString.stringValue); - elements!.add(printableString); - } - stringValue = sb.toString(); - } else { - stringValue = ascii.decode(valueBytes!); - } - } - - /// - /// Encodes this ASN1Object depending on the given [encodingRule] - /// - /// If no [ASN1EncodingRule] is given, ENCODING_DER will be used. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// * [ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM] - /// * [ASN1EncodingRule.ENCODING_BER_CONSTRUCTED] - /// * [ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH] - /// - /// Throws an [UnsupportedAsn1EncodingRuleException] if the given [encodingRule] is not supported. - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - switch (encodingRule) { - case ASN1EncodingRule.ENCODING_DER: - case ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM: - var octets = ascii.encode(stringValue!); - valueByteLength = octets.length; - valueBytes = Uint8List.fromList(octets); - break; - case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH: - case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED: - valueByteLength = 0; - if (elements == null) { - elements!.add(ASN1TeletextString(stringValue: stringValue)); - } - valueByteLength = _childLength( - isIndefinite: encodingRule == - ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH); - valueBytes = Uint8List(valueByteLength!); - var i = 0; - for (var obj in elements!) { - var b = obj.encode(); - valueBytes!.setRange(i, i + b.length, b); - i += b.length; - } - break; - case ASN1EncodingRule.ENCODING_BER_PADDED: - throw UnsupportedAsn1EncodingRuleException(encodingRule); - } - - return super.encode(encodingRule: encodingRule); - } - - /// - /// Calculate encoded length of all children - /// - int _childLength({bool isIndefinite = false}) { - var l = 0; - for (var obj in elements!) { - l += obj.encode().length; - } - if (isIndefinite) { - return l + 2; - } - return l; - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - if (isConstructed!) { - sb.write('T61STRING (${elements!.length} elem)'); - for (var e in elements!) { - var dump = e.dump(spaces: spaces + dumpIndent); - sb.write('\n $dump'); - } - } else { - sb.write('T61STRING $stringValue'); - } - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_utc_time.dart b/pointycastle/lib/asn1/primitives/asn1_utc_time.dart deleted file mode 100644 index e160832..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_utc_time.dart +++ /dev/null @@ -1,94 +0,0 @@ -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; - -/// -/// An ASN1 Utc Time object -/// -/// **Note**: It is not recommended to use the UTC Time in the far future because this will not work anymore after the year 2075, -/// due to the fact that the UTC Time only uses 2 digits to represent the year.! -/// -/// Use the **GeneralizedTime** instead! -/// -class ASN1UtcTime extends ASN1Object { - /// - /// The decoded DateTime value - /// - DateTime? time; - - /// - /// Creates an [ASN1UtcTime] entity with the given [time]. - /// - ASN1UtcTime(this.time, {int tag = ASN1Tags.UTC_TIME}) : super(tag: tag); - - /// - /// Creates an [ASN1UtcTime] entity from the given [encodedBytes]. - /// - ASN1UtcTime.fromBytes(Uint8List super.encodedBytes) : super.fromBytes() { - var stringValue = ascii.decode(valueBytes!); - var formatedStringValue = _format(stringValue); - time = DateTime.parse(formatedStringValue); - } - - /// - /// Encodes this ASN1Object depending on the given [encodingRule] - /// - /// If no [ASN1EncodingRule] is given, ENCODING_DER will be used. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// - /// Throws an [UnsupportedAsn1EncodingRuleException] if the given [encodingRule] is not supported. - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - if (encodingRule != ASN1EncodingRule.ENCODING_DER) { - throw UnsupportedAsn1EncodingRuleException(encodingRule); - } - var utc = time!.toUtc(); - var year = utc.year.toString().substring(2).padLeft(2, '0'); - var month = utc.month.toString().padLeft(2, '0'); - var day = utc.day.toString().padLeft(2, '0'); - var hour = utc.hour.toString().padLeft(2, '0'); - var minute = utc.minute.toString().padLeft(2, '0'); - var second = utc.second.toString().padLeft(2, '0'); - // Encode string to YYMMDDhhmm[ss]Z - var utcString = '$year$month$day$hour$minute${second}Z'; - valueBytes = ascii.encode(utcString); - valueByteLength = valueBytes!.length; - return super.encode(); - } - - /// - /// Formats the given [stringValue]. - /// - /// This needs to be done, due to the fact that the UTC Time only uses 2 digits to represent the year. - /// To use the DateTime.parse() method we have to add the century. - /// - /// **Note**: It is not recommended to use the UTC Time in the future because this will not work anymore after the year 2075! Use the GeneralizedTime instead. - /// - String _format(String stringValue) { - var y2 = int.parse(stringValue.substring(0, 2)); - if (y2 > 75) { - stringValue = '19$stringValue'; - } else { - stringValue = '20$stringValue'; - } - return '${stringValue.substring(0, 8)}T${stringValue.substring(8)}'; - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - sb.write('UTCTIME ${time!.toIso8601String()}'); - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/primitives/asn1_utf8_string.dart b/pointycastle/lib/asn1/primitives/asn1_utf8_string.dart deleted file mode 100644 index 8bb6b91..0000000 --- a/pointycastle/lib/asn1/primitives/asn1_utf8_string.dart +++ /dev/null @@ -1,130 +0,0 @@ -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; -import 'package:pointycastle/asn1/asn1_object.dart'; -import 'package:pointycastle/asn1/asn1_parser.dart'; -import 'package:pointycastle/asn1/asn1_tags.dart'; -import 'package:pointycastle/asn1/asn1_utils.dart'; -import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; - -/// -/// An ASN1 UTF8 String object -/// -class ASN1UTF8String extends ASN1Object { - /// - /// The decoded string value - /// - String? utf8StringValue; - - /// - /// A list of elements. Only set if this ASN1UTF8String is constructed, otherwhise null. - /// - List? elements; - - /// - /// Creates an empty [ASN1UTF8String] entity with only the [tag] set. - /// - ASN1UTF8String( - {this.utf8StringValue, this.elements, int tag = ASN1Tags.UTF8_STRING}) - : super(tag: tag); - - /// - /// Creates an [ASN1UTF8String] entity from the given [encodedBytes]. - /// - ASN1UTF8String.fromBytes(Uint8List encodedBytes) - : super.fromBytes(encodedBytes) { - if (ASN1Utils.isConstructed(encodedBytes.elementAt(0))) { - elements = []; - var parser = ASN1Parser(valueBytes); - var sb = StringBuffer(); - while (parser.hasNext()) { - var utf8String = parser.nextObject() as ASN1UTF8String; - sb.write(utf8String.utf8StringValue); - elements!.add(utf8String); - } - utf8StringValue = sb.toString(); - } else { - utf8StringValue = utf8.decode(valueBytes!); - } - } - - /// - /// Encodes this ASN1Object depending on the given [encodingRule] - /// - /// If no [ASN1EncodingRule] is given, ENCODING_DER will be used. - /// - /// Supported encoding rules are : - /// * [ASN1EncodingRule.ENCODING_DER] - /// * [ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM] - /// * [ASN1EncodingRule.ENCODING_BER_CONSTRUCTED] - /// * [ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH] - /// - /// Throws an [UnsupportedAsn1EncodingRuleException] if the given [encodingRule] is not supported. - /// - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - switch (encodingRule) { - case ASN1EncodingRule.ENCODING_DER: - case ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM: - var octets = utf8.encode(utf8StringValue!); - valueByteLength = octets.length; - valueBytes = Uint8List.fromList(octets); - break; - case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH: - case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED: - valueByteLength = 0; - if (elements == null) { - elements!.add(ASN1UTF8String(utf8StringValue: utf8StringValue)); - } - valueByteLength = _childLength( - isIndefinite: encodingRule == - ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH); - valueBytes = Uint8List(valueByteLength!); - var i = 0; - for (var obj in elements!) { - var b = obj.encode(); - valueBytes!.setRange(i, i + b.length, b); - i += b.length; - } - break; - case ASN1EncodingRule.ENCODING_BER_PADDED: - throw UnsupportedAsn1EncodingRuleException(encodingRule); - } - - return super.encode(encodingRule: encodingRule); - } - - /// - /// Calculate encoded length of all children - /// - int _childLength({bool isIndefinite = false}) { - var l = 0; - for (var obj in elements!) { - l += obj.encode().length; - } - if (isIndefinite) { - return l + 2; - } - return l; - } - - @override - String dump({int spaces = 0}) { - var sb = StringBuffer(); - for (var i = 0; i < spaces; i++) { - sb.write(' '); - } - if (isConstructed!) { - sb.write('UTF8STRING (${elements!.length} elem)'); - for (var e in elements!) { - var dump = e.dump(spaces: spaces + dumpIndent); - sb.write('\n$dump'); - } - } else { - sb.write('UTF8STRING $utf8StringValue'); - } - return sb.toString(); - } -} diff --git a/pointycastle/lib/asn1/unsupported_asn1_encoding_rule_exception.dart b/pointycastle/lib/asn1/unsupported_asn1_encoding_rule_exception.dart deleted file mode 100644 index 2d4b81a..0000000 --- a/pointycastle/lib/asn1/unsupported_asn1_encoding_rule_exception.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; - -/// -/// Exception that indicates that the given [ASN1EncodingRule] is not supported -/// -class UnsupportedAsn1EncodingRuleException implements Exception { - ASN1EncodingRule rule; - - UnsupportedAsn1EncodingRuleException(this.rule); - - @override - String toString() => - 'UnsupportedAsn1EncodingRuleException: Encoding $rule is not supported by this ASN1Object.'; -} diff --git a/pointycastle/lib/asn1/unsupported_asn1_tag_exception.dart b/pointycastle/lib/asn1/unsupported_asn1_tag_exception.dart deleted file mode 100644 index 8c09fdb..0000000 --- a/pointycastle/lib/asn1/unsupported_asn1_tag_exception.dart +++ /dev/null @@ -1,12 +0,0 @@ -/// -/// Exception that indicates that the given tag is not supported -/// -class UnsupportedASN1TagException implements Exception { - int tag; - - UnsupportedASN1TagException(this.tag); - - @override - String toString() => - 'UnsupportedASN1TagException: Tag $tag is not supported yet'; -} diff --git a/pointycastle/lib/asn1/unsupported_object_identifier_exception.dart b/pointycastle/lib/asn1/unsupported_object_identifier_exception.dart deleted file mode 100644 index 700e6ce..0000000 --- a/pointycastle/lib/asn1/unsupported_object_identifier_exception.dart +++ /dev/null @@ -1,12 +0,0 @@ -/// -/// Exception that indicates that the given object identifier is not supported -/// -class UnsupportedObjectIdentifierException implements Exception { - String? oiString; - - UnsupportedObjectIdentifierException(this.oiString); - - @override - String toString() => - 'UnsupportedObjectIdentifierException: ObjectIdentifier $oiString is not supported yet'; -} diff --git a/pointycastle/lib/asn1/x501/asn1_attribute_type_and_value.dart b/pointycastle/lib/asn1/x501/asn1_attribute_type_and_value.dart deleted file mode 100644 index 7d7631c..0000000 --- a/pointycastle/lib/asn1/x501/asn1_attribute_type_and_value.dart +++ /dev/null @@ -1,59 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// AttributeTypeAndValue ::= SEQUENCE { -/// type AttributeType, -/// value AttributeValue -/// } -///``` -/// -class ASN1AttributeTypeAndValue extends ASN1Object { - late ASN1ObjectIdentifier type; - - /// - /// The value. Can be one of the following objects - /// * [ASN1TeletextString] - /// * [ASN1PrintableString] - /// * [ASN1UTF8String] - /// * [ASN1BMPString] - /// - late ASN1Object value; - - ASN1AttributeTypeAndValue(this.type, this.value); - - ASN1AttributeTypeAndValue.fromSequence(ASN1Sequence seq) { - if (seq.elements == null || seq.elements!.length != 2) { - throw ArgumentError(''); - } - if (seq.elements!.elementAt(0) is! ASN1ObjectIdentifier) { - throw ArgumentError('Element at index 0 has to be ASN1ObjectIdentifier'); - } - if (seq.elements!.elementAt(1) is ASN1TeletextString || - seq.elements!.elementAt(1) is ASN1TeletextString || - seq.elements!.elementAt(1) is ASN1UTF8String || - seq.elements!.elementAt(1) is ASN1BMPString) { - // VALID TYPES - } else { - throw ArgumentError( - 'Element at index 1 has to be ASN1TeletextString, ASN1TeletextString, ASN1UTF8String or ASN1BMPString'); - } - - type = seq.elements!.elementAt(0) as ASN1ObjectIdentifier; - value = seq.elements!.elementAt(1); - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence( - elements: [ - type, - value, - ], - ); - return tmp.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asn1/x501/asn1_name.dart b/pointycastle/lib/asn1/x501/asn1_name.dart deleted file mode 100644 index ec351b2..0000000 --- a/pointycastle/lib/asn1/x501/asn1_name.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'dart:typed_data'; -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// Name ::= CHOICE { -- only one possibility for now -- -/// rdnSequence RDNSequence -/// } -/// -/// RDNSequence ::= SEQUENCE OF RelativeDistinguishedName -///``` -/// -class ASN1Name extends ASN1Object { - late List rdnSequence; - - ASN1Name(this.rdnSequence); - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence( - elements: rdnSequence, - ); - return tmp.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asn1/x501/asn1_rdn.dart b/pointycastle/lib/asn1/x501/asn1_rdn.dart deleted file mode 100644 index 75c8a84..0000000 --- a/pointycastle/lib/asn1/x501/asn1_rdn.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// RelativeDistinguishedName ::= SET SIZE (1..MAX) OF AttributeTypeAndValue -///``` -/// -class ASN1RDN extends ASN1Object { - /// Values for the RDN. Elements should be of [AttributeTypeAndValue] - late ASN1Set values; - - ASN1RDN(this.values); - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - return values.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asn1/x509/asn1_algorithm_identifier.dart b/pointycastle/lib/asn1/x509/asn1_algorithm_identifier.dart deleted file mode 100644 index 025ac29..0000000 --- a/pointycastle/lib/asn1/x509/asn1_algorithm_identifier.dart +++ /dev/null @@ -1,49 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/asn1.dart'; - -/// -///``` -/// AlgorithmIdentifier ::= SEQUENCE { -/// algorithm OBJECT IDENTIFIER, -/// parameters ANY DEFINED BY algorithm OPTIONAL -/// } -///``` -/// -class ASN1AlgorithmIdentifier extends ASN1Object { - late ASN1ObjectIdentifier algorithm; - ASN1Object? parameters; - - ASN1AlgorithmIdentifier(this.algorithm, {this.parameters}); - - /// - /// Creates a AlgorithmIdentifier instance from the given [identifier] like "1.3.14.3.2.26". - /// - ASN1AlgorithmIdentifier.fromIdentifier(String identifier, {this.parameters}) { - algorithm = ASN1ObjectIdentifier.fromIdentifierString(identifier); - } - - /// - /// Creates a AlgorithmIdentifier instance from the given [name] like "sha1". - /// - ASN1AlgorithmIdentifier.fromName(String name, {this.parameters}) { - algorithm = ASN1ObjectIdentifier.fromName(name); - } - - ASN1AlgorithmIdentifier.fromSequence(ASN1Sequence seq) { - algorithm = seq.elements!.elementAt(0) as ASN1ObjectIdentifier; - if (seq.elements!.length >= 2) { - parameters = seq.elements!.elementAt(1); - } - } - - @override - Uint8List encode( - {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { - var tmp = ASN1Sequence(elements: [ - algorithm, - parameters ?? ASN1Null(), - ]); - return tmp.encode(encodingRule: encodingRule); - } -} diff --git a/pointycastle/lib/asymmetric/api.dart b/pointycastle/lib/asymmetric/api.dart deleted file mode 100644 index 8805826..0000000 --- a/pointycastle/lib/asymmetric/api.dart +++ /dev/null @@ -1,158 +0,0 @@ -// See file LICENSE for more information. - -library api.asymmetric; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; - -/// Base class for asymmetric keys in RSA -abstract class RSAAsymmetricKey implements AsymmetricKey { - // The parameters of this key - final BigInt? modulus; - final BigInt? exponent; - - /// Create an asymmetric key for the given domain parameters - RSAAsymmetricKey(this.modulus, this.exponent); - - /// Get modulus [n] = p·q - BigInt? get n => modulus; -} - -/// Private keys in RSA -class RSAPrivateKey extends RSAAsymmetricKey implements PrivateKey { - // The secret prime factors of n - final BigInt? p; - final BigInt? q; - BigInt? _pubExp; - - /// Create an RSA private key for the given parameters. - /// - /// The optional public exponent parameter has been deprecated. It does not - /// have to be provided, because it can be calculated from the other values. - /// The optional parameter is retained for backward compatibility, but it - /// does not need to be provided. - - RSAPrivateKey(BigInt modulus, BigInt privateExponent, this.p, this.q, - [@Deprecated('Public exponent is calculated from the other values') - BigInt? publicExponent]) - : super(modulus, privateExponent) { - // Check RSA relationship between p, q and modulus hold true. - - if (p! * q! != modulus) { - throw ArgumentError.value('modulus inconsistent with RSA p and q'); - } - - // Calculate the correct RSA public exponent - - _pubExp = privateExponent.modInverse((p! - BigInt.one) * (q! - BigInt.one)); - - // If explicitly provided, the public exponent value must be correct. - if (publicExponent != null && publicExponent != _pubExp) { - throw ArgumentError( - 'public exponent inconsistent with RSA private exponent, p and q'); - } - } - - /// Get private exponent [d] = e^-1 - @Deprecated('Use privateExponent.') - BigInt? get d => exponent; - - /// Get the private exponent (d) - BigInt? get privateExponent => exponent; - - /// Get the public exponent (e) - BigInt? get publicExponent => _pubExp; - - /// Get the public exponent (e) - @Deprecated('Use publicExponent.') - BigInt? get pubExponent => publicExponent; - - @override - bool operator ==(Object other) { - if (other is RSAPrivateKey) { - return other.privateExponent == privateExponent && - other.modulus == modulus; - } - return false; - } - - @override - int get hashCode => modulus.hashCode + privateExponent.hashCode; -} - -/// Public keys in RSA -class RSAPublicKey extends RSAAsymmetricKey implements PublicKey { - /// Create an RSA public key for the given parameters. - RSAPublicKey(BigInt super.modulus, BigInt super.exponent); - - /// Get public exponent [e] - @Deprecated('Use get publicExponent') - BigInt? get e => exponent; - - /// Get the public exponent. - BigInt? get publicExponent => exponent; - - @override - bool operator ==(Object other) { - if (other is RSAPublicKey) { - return (other.modulus == modulus) && - (other.publicExponent == publicExponent); - } - return false; - } - - @override - int get hashCode => modulus.hashCode + publicExponent.hashCode; -} - -/// A [Signature] created with RSA. -class RSASignature implements Signature { - final Uint8List bytes; - - RSASignature(this.bytes); - - @override - String toString() => bytes.toString(); - @override - bool operator ==(Object other) { - if (other is! RSASignature) return false; - if (other.bytes.length != bytes.length) return false; - - for (var i = 0; i < bytes.length; i++) { - if (bytes[i] != other.bytes[i]) { - return false; - } - } - return true; - } - - @override - int get hashCode => bytes.hashCode; -} - -/// A [Signature] created with PSS. -class PSSSignature implements Signature { - final Uint8List bytes; - - PSSSignature(this.bytes); - - @override - String toString() => bytes.toString(); - - @override - bool operator ==(Object other) { - if (other is! PSSSignature) return false; - if (other.bytes.length != bytes.length) return false; - - for (var i = 0; i < bytes.length; i++) { - if (bytes[i] != other.bytes[i]) { - return false; - } - } - return true; - } - - @override - int get hashCode => bytes.hashCode; -} diff --git a/pointycastle/lib/asymmetric/ec_elgamal.dart b/pointycastle/lib/asymmetric/ec_elgamal.dart deleted file mode 100644 index 7d9f36c..0000000 --- a/pointycastle/lib/asymmetric/ec_elgamal.dart +++ /dev/null @@ -1,80 +0,0 @@ -// See file LICENSE for more information. - -library impl.asymmetric.ecc.elgamal; - -import 'package:pointycastle/export.dart'; -import 'package:pointycastle/src/platform_check/platform_check.dart'; - -BigInt _generateK(BigInt n, SecureRandom random) { - var nBitLength = n.bitLength; - BigInt k; - do { - k = random.nextBigInteger(nBitLength); - } while ((k == BigInt.zero) || (k.compareTo(n) >= 0)); - return k; -} - -SecureRandom _newSecureRandom() => FortunaRandom() - ..seed(KeyParameter(Platform.instance.platformEntropySource().getBytes(32))); - -/// The basic ElGamal encryptor using Elliptic Curve -class ECElGamalEncryptor implements ECEncryptor { - ECPublicKey? _key; - late SecureRandom _random; - - /// Process a single EC [point] using the basic ElGamal algorithm. - @override - ECPair encrypt(ECPoint point) { - if (_key == null) { - throw StateError('ECElGamalEncryptor is not initialised'); - } - var key = _key!; - var ec = key.parameters!; - var k = _generateK(ec.n, _random); - return ECPair( - (ec.G * k)!, - ((key.Q! * k)! + point)!, - ); - } - - @override - void init(CipherParameters params) { - AsymmetricKeyParameter akparams; - if (params is ParametersWithRandom) { - akparams = params.parameters as AsymmetricKeyParameter; - _random = params.random; - } else { - akparams = params as AsymmetricKeyParameter; - _random = _newSecureRandom(); - } - var k = akparams.key as ECAsymmetricKey; - if (k is! ECPublicKey) { - throw ArgumentError('ECPublicKey is required for encryption.'); - } - _key = k; - } -} - -/// The basic ElGamal decryptor using Elliptic Curve -class ECElGamalDecryptor implements ECDecryptor { - ECPrivateKey? _key; - - /// Decrypt an EC [pair] producing the original [ECPoint]. - @override - ECPoint decrypt(ECPair pair) { - if (_key == null) { - throw StateError('ECElGamalEncryptor is not initialised'); - } - return (pair.y - (pair.x * _key!.d)!)!; - } - - @override - void init(CipherParameters params) { - var akparams = params as AsymmetricKeyParameter; - var k = akparams.key as ECAsymmetricKey; - if (k is! ECPrivateKey) { - throw ArgumentError('ECPrivateKey is required for decryption.'); - } - _key = k; - } -} diff --git a/pointycastle/lib/asymmetric/oaep.dart b/pointycastle/lib/asymmetric/oaep.dart deleted file mode 100644 index d8cfaf8..0000000 --- a/pointycastle/lib/asymmetric/oaep.dart +++ /dev/null @@ -1,527 +0,0 @@ -// See file LICENSE for more information. - -library impl.asymmetric_block_cipher.oeap; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/digests/sha1.dart'; -import 'package:pointycastle/digests/sha256.dart'; -import 'package:pointycastle/digests/sha512.dart'; -import 'package:pointycastle/random/fortuna_random.dart'; -import 'package:pointycastle/src/impl/base_asymmetric_block_cipher.dart'; -import 'package:pointycastle/src/platform_check/platform_check.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -typedef DigestFactory = Digest Function(); - -/// RSAES-OAEP v2.0 -/// -/// This implementation is based on the RSAES-OAEP (RSA Encryption Scheme - -/// Optimal Asymmetric Encryption Padding) as specified in section 7.1 of -/// [RFC 2437](https://tools.ietf.org/html/rfc2437#section-7.1) -/// _PKCS #1: RSA Cryptography Specifications Version 2.0_. -/// -/// **Important:** this is **not** compatible with RSAES-OAEP v2.1 or later (as -/// specified in RFC 3447, RFC 8017, etc.) Those newer versions have an extra -/// 0x00 byte at the beginning of the encoded message (EM) that is passed -/// to the RSA encryption primitive. Therefore, this implementation is -/// incompatible with it, since this is an implementation of v2.0 which does -/// not have that 0x00 byte. A breaking change in the standard! -/// -/// Currently, this implementation has the following restrictions: -/// -/// - the hash function is hard-coded to be SHA-1 or SHA-256; -/// - the mask generation function is hard-coded to MGF1; and -/// - it cannot accept any _encoding parameters_ (that is, _P_ is always empty) - -class OAEPEncoding extends BaseAsymmetricBlockCipher { - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - AsymmetricBlockCipher, - '/OAEP', - (_, final Match match) => () { - var underlyingCipher = AsymmetricBlockCipher(match.group(1)!); - return OAEPEncoding(underlyingCipher); - }); - - /// Hash function used by the EME-OAEP (Encoding Method for Encryption OAEP). - Digest hash; - - /// Hash function used by the MGF1 Mask Generation Function. - late Digest mgf1Hash; - - /// Default hash of the encoding parameters, - /// all zero octets - Uint8List defHash; - - /// The encoding params, or P, as specified in - /// [RFC 2437](https://tools.ietf.org/html/rfc2437#section-7.1.1) - Uint8List? encodingParams; - - final AsymmetricBlockCipher _engine; - late SecureRandom _random; - late bool _forEncryption; - - OAEPEncoding._(DigestFactory digestFactory, this._engine, - [this.encodingParams]) - : hash = digestFactory(), - defHash = Uint8List(digestFactory().digestSize) { - digestFactory().doFinal(defHash, 0); - } - - factory OAEPEncoding(AsymmetricBlockCipher engine, - [Uint8List? encodingParams]) => - OAEPEncoding.withSHA1(engine, encodingParams); - - factory OAEPEncoding.withSHA1(AsymmetricBlockCipher engine, - [Uint8List? encodingParams]) => - OAEPEncoding._(() => SHA1Digest(), engine, encodingParams); - - factory OAEPEncoding.withSHA256(AsymmetricBlockCipher engine, - [Uint8List? encodingParams]) => - OAEPEncoding._(() => SHA256Digest(), engine, encodingParams); - - factory OAEPEncoding.withSHA512(AsymmetricBlockCipher engine, - [Uint8List? encodingParams]) => - OAEPEncoding._(() => SHA512Digest(), engine, encodingParams); - - factory OAEPEncoding.withCustomDigest( - DigestFactory digestFactory, AsymmetricBlockCipher engine, - [Uint8List? encodingParams]) => - OAEPEncoding._(digestFactory, engine, encodingParams); - - @override - String get algorithmName => '${_engine.algorithmName}/OAEP'; - - @override - void reset() {} - - Uint8List _seed() { - var seed = Platform.instance.platformEntropySource().getBytes(32); - return seed; - } - - // for compat cleaner translation from java source - Uint8List _arraycopy( - Uint8List src, int srcPos, Uint8List dest, int destPos, int length) { - dest.setRange( - destPos, destPos + length, src.sublist(srcPos, srcPos + length)); - return dest; - } - - @override - void init(bool forEncryption, CipherParameters params) { - AsymmetricKeyParameter akparams; - mgf1Hash = hash; - if (params is ParametersWithRandom) { - var paramswr = params; - _random = paramswr.random; - akparams = paramswr.parameters as AsymmetricKeyParameter; - } else { - _random = FortunaRandom(); - _random.seed(KeyParameter(_seed())); - akparams = params as AsymmetricKeyParameter; - } - _engine.init(forEncryption, akparams); - _forEncryption = forEncryption; - - // Check type of key provided is suitable - // Note: the _engine can't do this check, because the engine could be used - // for both encryption/decryption and signature/verification (which reverses - // the keys), so its `init` method accepts both types of keys. For example, - // [RSAEngine.init]. - - if (forEncryption) { - if (akparams.key is! PublicKey) { - throw ArgumentError.value( - 'OAEP encryption needs PublicKey: not ${akparams.key.runtimeType}'); - } - } else { - if (akparams.key is! PrivateKey) { - throw ArgumentError.value( - 'OAEP decryption needs PrivateKey: not ${akparams.key.runtimeType}'); - } - } - } - - @override - int get inputBlockSize { - var baseBlockSize = _engine.inputBlockSize; - if (_forEncryption) { - return baseBlockSize - 1 - 2 * defHash.length; - } else { - return baseBlockSize; - } - } - - @override - int get outputBlockSize { - var baseBlockSize = _engine.outputBlockSize; - if (_forEncryption) { - return baseBlockSize; - } else { - return baseBlockSize - 1 - (2 * defHash.length); - } - } - - @override - int processBlock( - Uint8List inp, int inpOff, int len, Uint8List out, int outOff) { - if (_forEncryption) { - return _encodeBlock(inp, inpOff, len, out, outOff); - } else { - return _decodeBlock(inp, inpOff, len, out, outOff); - } - } - - /// RSAES-OAEP encryption operation - /// - /// Implements the _RSA Encryption Scheme with Optimal Asymmetric Encryption - /// Padding_ (RSAES-OAEP) **encryption operation**. This encryption operation - /// combines the _Encoding Method for Encryption OAEP_ (EME-OAEP) - /// **encoding operation** with the _RSA Encryption Primitive_ (RSAEP). - /// - /// This method performs the EME-OAEP encoding operation, and then invokes its - /// [AsymmetricBlockCipher] engine to perform RSAEP to encrypt it. - /// - /// The RSAES-OAEP encryption operation is specified in section 7.1.1 of - /// [RFC 2437](https://tools.ietf.org/html/rfc2437#section-7.1.1) and the - /// EME-OAEP encoding operation it uses is specified in section 9.1.1.1 of - /// [RFC 2437](https://tools.ietf.org/html/rfc2437#section-9.1.1.1). - /// - /// The message to be encoded and encrypted is the octet string consisting of - /// [inpLen] bytes from [inp], starting at the [inpOff] offset. - /// - /// It returns the ciphertext. - - int _encodeBlock( - Uint8List inp, int inpOff, int inpLen, Uint8List out, int outOff) { - if (inpLen > inputBlockSize) { - throw ArgumentError('message too long'); - } - - // The numbered steps below correspond to the steps in RFC 2437. - // Names in _italics_ refers to names in the RFC 2437 and names in square - // brackets refers to variables in this code. - - // 3. Generate PS (padding string containing just zero octets) - // - // In this implementation, the length of PS is always zero. That is, there - // is no bytes in _PS_. - - // 4. Calculate _pHash_ = Hash(P) - // - // The result _pHash_ is stored into [pHash]. - // - // Note: If no encodingParams are set - // the [defHash] is used as is (which was initialized to be a hash of no - // bytes) - var pHash = - encodingParams != null ? hash.process(encodingParams!) : defHash; - - // 5. Calculate _DB_ = pHash || PS || 01 || M - // - // It is the concatenation of _pHash_, _PS_, 0x01 and the message. - // Note: RFC 2437 also includes 'other padding', but that is an error that - // does not appear in subsequent versions of PKCS #1 (e.g. RFC 3447). - // - // The result _DB_ is stored into [block] starting at offset _hLen_ to the - // end. - - var block = Uint8List(inputBlockSize + 1 + 2 * pHash.length); - - // M: copy the message into the end of the block. - // - // block.setRange(inpOff, block.length - inpLen, inp.sublist(inpLen)); - block = _arraycopy(inp, inpOff, block, block.length - inpLen, inpLen); - - // 01: add the sentinel byte - // - block[block.length - inpLen - 1] = 0x01; - - // PS: since a Uint8List is initialized with 0x00, PS is already zeroed - - // pHash: add the hash of the encoding params. - // - block = _arraycopy(pHash, 0, block, pHash.length, pHash.length); - - // 6. Generate a random octet string _seed_ of length _hLen_. - // - // The _seed_ is stored in [seed]. - - var seed = _random.nextBytes(pHash.length); - - // 7. Calculate _dbMask_ = MGF(seed, emLen - hLen) - // - // The _seed_ comes from [seed]. The result _dbMask_ is stored into [mask]. - - var mask = _maskGeneratorFunction1( - seed, 0, seed.length, block.length - pHash.length); - - // 8. Calculate _maskedDB_ = DB XOR dbMask - // - // The _DB_ comes from [block], starting at offset _hLen_ to the end. The - // _dbMask_ comes from [mask]. The result _maskedDB_ is stored into [block] - // starting at offset _hLen_ to the end (overwriting the _DB_). - - for (var i = pHash.length; i != block.length; i++) { - block[i] ^= mask[i - pHash.length]; - } - - // Temporally store the _seed_ in the first _hLen_ bytes of the [block] - // so it can be used later. - - block = _arraycopy(seed, 0, block, 0, pHash.length); - - // 9. Calculate _seedMask_ = MGF(maskedDB, hLen) - // - // The _maskedDB_ comes from [block], starting at offset _hLen_ to the end. - // The result _seedMask_ is stored into [mask] (replacing the _dbMask_ which - // is no longer needed). - - mask = _maskGeneratorFunction1( - block, pHash.length, block.length - pHash.length, pHash.length); - - // 10. Calculate _maskedSeed_ = seed XOR seedMask - // - // The _seed_ comes from [block], the first _hLen_ bytes (where it was - // temporally stored). The _seedMask_ comes from [mask]. The result - // _maskedSeed_ is stored into [block], the first _hLen_ bytes (overwriting - // the temporary _seed_). - - for (var i = 0; i != pHash.length; i++) { - block[i] ^= mask[i]; - } - - // 11. Calculate _EM_ = maskedSeed || maskedDB - // - // The [block] already contains the concatenated value, since they were both - // calculated in the first. - - // EME-OAEP-ENCODE completed. - - // Use the [_engine] to finish the RSAES-OAEP. That is, it will convert the - // _EM_ into an integer, apply the RSA Encryption Primitive (RSAEP) to the - // public key, and convert the resulting integer ciphertext representation - // into octets. The octets will be written into [out] starting at [outOff]. - // - // Returns the number of bytes in the output ciphertext. - - return _engine.processBlock(block, 0, block.length, out, outOff); - } - - /// RSAES-OAEP decryption operation - /// - /// Implements the _RSA Encryption Scheme with Optimal Asymmetric Encryption - /// Padding_ (RSAES-OAEP) **decryption operation**. This decryption operation - /// combines the _RSA Decryption Primitive_ (RSADP) with the _Encoding Method - /// for Encryption OAEP_ (EME-OAEP) **decoding operation**. - /// - /// This method invokes its [AsymmetricBlockCipher] engine to perform RSADP, - /// and then performs the EME-OAEP decoding operation on the decrypted data. - /// - /// The RSAES-OAEP decryption operation is specified in section 7.1.2 of - /// [RFC 2437](https://tools.ietf.org/html/rfc2437#section-7.1.2) and the - /// EME-OAEP decoding operation it uses is specified in section 9.1.1.2 of - /// [RFC 2437](https://tools.ietf.org/html/rfc2437#section-9.1.1.2). - /// - /// The ciphertext to be decrypted and decoded is the octet string consisting - /// of [inpLen] bytes from [inp], starting at the [inpOff] offset. - /// - /// It returns the message in [out] starting at offset [outOff]. - - int _decodeBlock( - Uint8List inp, int inpOff, int inpLen, Uint8List out, int outOff) { - // The numbered steps below correspond to the steps from section 7.1.2 of - // [RFC 2437](https://tools.ietf.org/html/rfc2437#section-7.1.2). - // - // Names in _italics_ refers to names in the RFC 2437 and names in square - // brackets refers to variables in this code. - - // 1. Length checking - - if (inpLen != _engine.inputBlockSize) { - throw ArgumentError.value(inpLen, 'inpLen', 'decryption error'); - } - - // 2, 3. RSA decryption - - var block = Uint8List(_engine.outputBlockSize); - - var decryptFailed = false; - try { - var len = _engine.processBlock(inp, inpOff, inpLen, block, 0); - - // 4. EM = I2OSP(m, k-1) - - if (len < block.length) { - // Decrypted bytes is shorter than expected. Add 0x00 bytes at the - // beginning of the block (i.e. ensure it is k-1 long). This is needed - // when there were 0x00 in the leading bytes of the block that was - // originally encrypted. - - // Note: do not use [_arrayCopy] or [SetRange], since the source and - // destination may overlap. Those methods will corrupt the data. - - // Copy [len] data bytes from beginning of block to its end. I.e. from - // block[block.length - 1] <- block[len - 1] through to - // block[block.len - len] <- block[0] - for (var x = 0; x < len; x++) { - block[block.length - 1 - x] = block[len - 1 - x]; - } - // Put 0x00 in those beginning bytes. Important: do this AFTER copying - block.fillRange(0, block.length - len, 0x00); - } - } on ArgumentError { - decryptFailed = true; - } - - // 5. EME-OAEP decoding - // - // In these 5.x numbered steps, the x refers to steps from section 9.1.1.2 - // of [RFC 2437](https://tools.ietf.org/html/rfc2437#section-9.1.1.2) - - // 5.2 Check length - - var wrongData = block.length < (2 * defHash.length) + 1; - - // 5.4 Calculate _seedMask_ = MGF(maskedDB, hLen) - // - // The _maskedDB_ comes from [block] starting at _hLen_ to the end. - // The result _seedMask_ is stored in [mask]. - - var mask = _maskGeneratorFunction1( - block, defHash.length, block.length - defHash.length, defHash.length); - - // 5.5 Calculate _seed_ = maskedSeed XOR seedMask - // - // THe _maskedSeed_ comes from the first _hLen_ bytes of [block] and the - // _seedMask_ comes from [mask]. - // The result _seed_ is stored in the first _hLen_ bytes of [block] - // (overwriting the maskedSeed_ that was previously there). - - for (var i = 0; i != defHash.length; i++) { - block[i] ^= mask[i]; - } - - // 5.6 Calculate _dbMask_ = MGF(seed, length of EM - hLen) - - mask = _maskGeneratorFunction1( - block, 0, defHash.length, block.length - defHash.length); - - // 5.7 Calculate _DB_ = maskedDB XOR dbMask - // - // The _maskedDB_ comes from [block], from _hLen_ to the end, and the - // _dbMask_ comes from [mask]. The result _DB_ is stored in [block] from - // _hLen_ to the end (overwriting the _maskedDB_ that was previously there). - - for (var i = defHash.length; i != block.length; i++) { - block[i] ^= mask[i - defHash.length]; - } - - // 5.8 pHash = Hash(P) - var pHash = - encodingParams != null ? hash.process(encodingParams!) : defHash; - - // 5.10 Check _pHash'_ to _pHash_ - // - // check the hash of the encoding params. - // long check to try to avoid this been a source of a timing attack. - // - // The _pHash'_ comes from the first _hLen_ bytes of [block] - - var pHashWrong = false; - - for (var i = 0; i != pHash.length; i++) { - pHashWrong |= pHash[i] != block[pHash.length + i]; - } - - // 5.9 Split _DB_ into pHash1 || PS || 0x01 || M - // - // Skip over the _PS_ (which are all 0x00 bytes). Finding the first non-zero - // byte from hash.digestLength * 2 to the end of [block]. Setting [start] - // to that first non-zero byte (or will be block.length if none found). - - var start = block.length; - for (var index = 2 * pHash.length; index != block.length; index++) { - if ((block[index] != 0) & (start == block.length)) { - start = index; - } - } - - // The data-start-is-wrong if the rest of the [block] contains all 0x00 - // bytes or that first non-zero byte is not 0x01. - - var dataStartWrong = (start > (block.length - 1)) | - (start < block.length && block[start] != 0x01); - start++; - - if (decryptFailed || pHashWrong || wrongData || dataStartWrong) { - block.fillRange(0, block.length, 0); - throw ArgumentError('decoding error'); - } - - // 5.11 Output M - // - // The _M_ are all the bytes from after the 0x01 byte (i.e. offset [start]) - // to the end of [block]. Copy those bytes into [out] starting at [outOff]. - - final mLen = block.length - start; - _arraycopy(block, start, out, outOff, mLen); - return mLen; - } - - // ignore: slash_for_doc_comments - /// int to octet string. - Uint8List _itoOSP(int i, Uint8List sp) { - sp[0] = i >> 24; - sp[1] = i >> 16; - sp[2] = i >> 8; - sp[3] = i >> 0; - return sp; - } - - /// Implementation of MGF1 (the Mask Generation Function from PKCS #1 v2.0). - /// - /// See section 10.2.1 of - /// [RFC 2437](https://tools.ietf.org/html/rfc2437#section-10.2.1). - /// - /// MGF1 is defined to take a hash function as an option. This implementation - /// uses [mgf1Hash] for that hash function. - /// - /// MGF1 hsa two inputs: a seed and an intended length. The seed is the - /// sequence of bytes in [Z], starting at [zOff] for [zLen] bytes. - /// The intended length is in [length]. - /// - /// Returns the calculated mask. A Uint8List that contains [length] bytes. - - Uint8List _maskGeneratorFunction1( - Uint8List Z, int zOff, int zLen, int length) { - var mask = Uint8List(length); - var hashBuf = Uint8List(mgf1Hash.digestSize); - var C = Uint8List(4); - var counter = 0; - mgf1Hash.reset(); - - while (counter < (length / hashBuf.length).floor()) { - _itoOSP(counter, C); - mgf1Hash.update(Z, zOff, zLen); - mgf1Hash.update(C, 0, C.length); - mgf1Hash.doFinal(hashBuf, 0); - mask = _arraycopy( - hashBuf, 0, mask, counter * hashBuf.length, hashBuf.length); - counter++; - } - - if ((counter * hashBuf.length) < length) { - _itoOSP(counter, C); - mgf1Hash.update(Z, zOff, zLen); - mgf1Hash.update(C, 0, C.length); - mgf1Hash.doFinal(hashBuf, 0); - mask = _arraycopy(hashBuf, 0, mask, counter * hashBuf.length, - mask.length - (counter * hashBuf.length)); - } - return mask; - } -} diff --git a/pointycastle/lib/asymmetric/pkcs1.dart b/pointycastle/lib/asymmetric/pkcs1.dart deleted file mode 100644 index e0834c5..0000000 --- a/pointycastle/lib/asymmetric/pkcs1.dart +++ /dev/null @@ -1,173 +0,0 @@ -// See file LICENSE for more information. - -library impl.asymmetric_block_cipher.pkcs1; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/random/fortuna_random.dart'; -import 'package:pointycastle/src/impl/base_asymmetric_block_cipher.dart'; -import 'package:pointycastle/src/platform_check/platform_check.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -class PKCS1Encoding extends BaseAsymmetricBlockCipher { - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - AsymmetricBlockCipher, - '/PKCS1', - (_, final Match match) => () { - var underlyingCipher = AsymmetricBlockCipher(match.group(1)!); - return PKCS1Encoding(underlyingCipher); - }); - - static const _HEADER_LENGTH = 10; - - final AsymmetricBlockCipher _engine; - - late SecureRandom _random; - late bool _forEncryption; - late bool _forPrivateKey; - - PKCS1Encoding(this._engine); - - @override - String get algorithmName => '${_engine.algorithmName}/PKCS1'; - - @override - void reset() {} - - Uint8List _seed() { - return Platform.instance.platformEntropySource().getBytes(32); - } - - @override - void init(bool forEncryption, CipherParameters params) { - AsymmetricKeyParameter akparams; - - if (params is ParametersWithRandom) { - var paramswr = params; - - _random = paramswr.random; - akparams = paramswr.parameters as AsymmetricKeyParameter; - } else { - _random = FortunaRandom(); - _random.seed(KeyParameter(_seed())); - akparams = params as AsymmetricKeyParameter; - } - - _engine.init(forEncryption, akparams); - - _forPrivateKey = akparams.key is PrivateKey; - _forEncryption = forEncryption; - } - - @override - int get inputBlockSize { - var baseBlockSize = _engine.inputBlockSize; - - if (_forEncryption) { - return baseBlockSize - _HEADER_LENGTH; - } else { - return baseBlockSize; - } - } - - @override - int get outputBlockSize { - var baseBlockSize = _engine.outputBlockSize; - - if (_forEncryption) { - return baseBlockSize; - } else { - return baseBlockSize - _HEADER_LENGTH; - } - } - - @override - int processBlock( - Uint8List inp, int inpOff, int len, Uint8List out, int outOff) { - if (_forEncryption) { - return _encodeBlock(inp, inpOff, len, out, outOff); - } else { - return _decodeBlock(inp, inpOff, len, out, outOff); - } - } - - int _encodeBlock( - Uint8List inp, int inpOff, int inpLen, Uint8List out, int outOff) { - if (inpLen > inputBlockSize) { - throw ArgumentError('Input data too large'); - } - - var block = Uint8List(_engine.inputBlockSize); - var padLength = block.length - inpLen - 1; - - if (_forPrivateKey) { - block[0] = 0x01; // type code 1 - block.fillRange(1, padLength, 0xFF); - } else { - block[0] = 0x02; // type code 2 - block.setRange(1, padLength, _random.nextBytes(padLength - 1)); - - // a zero byte marks the end of the padding, so all - // the pad bytes must be non-zero. - for (var i = 1; i < padLength; i++) { - while (block[i] == 0) { - block[i] = _random.nextUint8(); - } - } - } - - block[padLength] = 0x00; // mark the end of the padding - block.setRange(padLength + 1, block.length, inp.sublist(inpOff)); - - return _engine.processBlock(block, 0, block.length, out, outOff); - } - - int _decodeBlock( - Uint8List inp, int inpOff, int inpLen, Uint8List out, int outOff) { - var block = Uint8List(_engine.inputBlockSize); - var len = _engine.processBlock(inp, inpOff, inpLen, block, 0); - block = block.sublist(0, len); - - if (block.length < outputBlockSize) { - throw ArgumentError('Block truncated'); - } - - var type = block[0]; - - if (_forPrivateKey && (type != 2)) { - throw ArgumentError('Unsupported block type for private key: $type'); - } - if (!_forPrivateKey && (type != 1)) { - throw ArgumentError('Unsupported block type for public key: $type'); - } - if (block.length != _engine.outputBlockSize) { - throw ArgumentError('Block size is incorrect: ${block.length}'); - } - - // find and extract the message block. - int start; - - for (start = 1; start < block.length; start++) { - var pad = block[start]; - - if (pad == 0) { - break; - } - if (type == 1 && (pad != 0xFF)) { - throw ArgumentError('Incorrect block padding'); - } - } - - start++; // data should start at the next byte - - if ((start > block.length) || (start < _HEADER_LENGTH)) { - throw ArgumentError('No data found in block, only padding'); - } - - var rlen = block.length - start; - out.setRange(outOff, outOff + rlen, block.sublist(start)); - return rlen; - } -} diff --git a/pointycastle/lib/asymmetric/rsa.dart b/pointycastle/lib/asymmetric/rsa.dart deleted file mode 100644 index e01ece1..0000000 --- a/pointycastle/lib/asymmetric/rsa.dart +++ /dev/null @@ -1,163 +0,0 @@ -// See file LICENSE for more information. - -library impl.asymmetric_block_cipher.rsa; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/asymmetric/api.dart'; -import 'package:pointycastle/src/impl/base_asymmetric_block_cipher.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/utils.dart' as utils; - -class RSAEngine extends BaseAsymmetricBlockCipher { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(AsymmetricBlockCipher, 'RSA', () => RSAEngine()); - - late bool _forEncryption; - RSAAsymmetricKey? _key; - late BigInt _dP; - late BigInt _dQ; - late BigInt _qInv; - - @override - String get algorithmName => 'RSA'; - - @override - int get inputBlockSize { - if (_key == null) { - throw StateError( - 'Input block size cannot be calculated until init() called'); - } - - var bitSize = _key!.modulus!.bitLength; - if (_forEncryption) { - return ((bitSize + 7) ~/ 8) - 1; - } else { - return (bitSize + 7) ~/ 8; - } - } - - @override - int get outputBlockSize { - if (_key == null) { - throw StateError( - 'Output block size cannot be calculated until init() called'); - } - - var bitSize = _key!.modulus!.bitLength; - if (_forEncryption) { - return (bitSize + 7) ~/ 8; - } else { - return ((bitSize + 7) ~/ 8) - 1; - } - } - - @override - void reset() {} - - @override - void init(bool forEncryption, - covariant AsymmetricKeyParameter params) { - _forEncryption = forEncryption; - _key = params.key; - - if (_key is RSAPrivateKey) { - var privKey = _key as RSAPrivateKey; - var pSub1 = privKey.p! - BigInt.one; - var qSub1 = privKey.q! - BigInt.one; - _dP = privKey.privateExponent!.remainder(pSub1); - _dQ = privKey.privateExponent!.remainder(qSub1); - _qInv = privKey.q!.modInverse(privKey.p!); - } - } - - @override - Uint8List process(Uint8List data) { - // Expand the output block size by an extra byte to handle cases where - // the output is larger than expected. - var out = Uint8List(outputBlockSize + 1); - var len = processBlock(data, 0, data.length, out, 0); - return out.sublist(0, len); - } - - @override - int processBlock( - Uint8List inp, int inpOff, int len, Uint8List out, int outOff) { - var input = _convertInput(inp, inpOff, len); - var output = _processBigInteger(input); - return _convertOutput(output, out, outOff); - } - - BigInt _convertInput(Uint8List inp, int inpOff, int len) { - var inpLen = inp.length; - - if (inpLen < inpOff + len) { - throw ArgumentError.value(inpOff, 'inpOff', - 'Not enough data for RSA cipher (length=$len, available=$inpLen)'); - } - - if (inputBlockSize + 1 < len) { - throw ArgumentError.value(len, 'len', - 'Too large for maximum RSA cipher input block size ($inputBlockSize)'); - } - - var res = utils.decodeBigIntWithSign(1, inp.sublist(inpOff, inpOff + len)); - if (res >= _key!.modulus!) { - throw ArgumentError('Input block too large for RSA key size'); - } - - return res; - } - - int _convertOutput(BigInt result, Uint8List out, int outOff) { - final output = utils.encodeBigInt(result); - - if (_forEncryption) { - if ((output[0] == 0) && (output.length > outputBlockSize)) { - // have ended up with an extra zero byte, copy down. - var len = output.length - 1; - out.setRange(outOff, outOff + len, output.sublist(1)); - return len; - } - if (output.length < outputBlockSize) { - // have ended up with less bytes than normal, lengthen - var len = outputBlockSize; - out.setRange(outOff + len - output.length, outOff + len, output); - return len; - } - } else { - if (output[0] == 0) { - // have ended up with an extra zero byte, copy down. - var len = output.length - 1; - out.setRange(outOff, outOff + len, output.sublist(1)); - return len; - } - } - - out.setAll(outOff, output); - return output.length; - } - - BigInt _processBigInteger(BigInt input) { - if (_key is RSAPrivateKey) { - var privKey = _key as RSAPrivateKey; - BigInt mP, mQ, h, m; - - mP = input.remainder(privKey.p!).modPow(_dP, privKey.p!); - - mQ = input.remainder(privKey.q!).modPow(_dQ, privKey.q!); - - h = mP - mQ; - h = h * _qInv; - h = h % privKey.p!; - - m = h * privKey.q!; - m = m + mQ; - - return m; - } else { - return input.modPow(_key!.exponent!, _key!.modulus!); - } - } -} diff --git a/pointycastle/lib/block/aes.dart b/pointycastle/lib/block/aes.dart deleted file mode 100644 index 5a10634..0000000 --- a/pointycastle/lib/block/aes.dart +++ /dev/null @@ -1,1551 +0,0 @@ -// See file LICENSE for more information. - -library impl.block_cipher.aes; - -import 'dart:core'; -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_block_cipher.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -class AESEngine extends BaseBlockCipher { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(BlockCipher, 'AES', () => AESEngine()); - - int _ROUNDS = 0; - late List> _WorkingKey; - bool _forEncryption = false; - - List _s = List.empty(); - - static const _S = [ - 99, - 124, - 119, - 123, - 242, - 107, - 111, - 197, - 48, - 1, - 103, - 43, - 254, - 215, - 171, - 118, - 202, - 130, - 201, - 125, - 250, - 89, - 71, - 240, - 173, - 212, - 162, - 175, - 156, - 164, - 114, - 192, - 183, - 253, - 147, - 38, - 54, - 63, - 247, - 204, - 52, - 165, - 229, - 241, - 113, - 216, - 49, - 21, - 4, - 199, - 35, - 195, - 24, - 150, - 5, - 154, - 7, - 18, - 128, - 226, - 235, - 39, - 178, - 117, - 9, - 131, - 44, - 26, - 27, - 110, - 90, - 160, - 82, - 59, - 214, - 179, - 41, - 227, - 47, - 132, - 83, - 209, - 0, - 237, - 32, - 252, - 177, - 91, - 106, - 203, - 190, - 57, - 74, - 76, - 88, - 207, - 208, - 239, - 170, - 251, - 67, - 77, - 51, - 133, - 69, - 249, - 2, - 127, - 80, - 60, - 159, - 168, - 81, - 163, - 64, - 143, - 146, - 157, - 56, - 245, - 188, - 182, - 218, - 33, - 16, - 255, - 243, - 210, - 205, - 12, - 19, - 236, - 95, - 151, - 68, - 23, - 196, - 167, - 126, - 61, - 100, - 93, - 25, - 115, - 96, - 129, - 79, - 220, - 34, - 42, - 144, - 136, - 70, - 238, - 184, - 20, - 222, - 94, - 11, - 219, - 224, - 50, - 58, - 10, - 73, - 6, - 36, - 92, - 194, - 211, - 172, - 98, - 145, - 149, - 228, - 121, - 231, - 200, - 55, - 109, - 141, - 213, - 78, - 169, - 108, - 86, - 244, - 234, - 101, - 122, - 174, - 8, - 186, - 120, - 37, - 46, - 28, - 166, - 180, - 198, - 232, - 221, - 116, - 31, - 75, - 189, - 139, - 138, - 112, - 62, - 181, - 102, - 72, - 3, - 246, - 14, - 97, - 53, - 87, - 185, - 134, - 193, - 29, - 158, - 225, - 248, - 152, - 17, - 105, - 217, - 142, - 148, - 155, - 30, - 135, - 233, - 206, - 85, - 40, - 223, - 140, - 161, - 137, - 13, - 191, - 230, - 66, - 104, - 65, - 153, - 45, - 15, - 176, - 84, - 187, - 22, - ]; - - static const _Si = [ - 82, - 9, - 106, - 213, - 48, - 54, - 165, - 56, - 191, - 64, - 163, - 158, - 129, - 243, - 215, - 251, - 124, - 227, - 57, - 130, - 155, - 47, - 255, - 135, - 52, - 142, - 67, - 68, - 196, - 222, - 233, - 203, - 84, - 123, - 148, - 50, - 166, - 194, - 35, - 61, - 238, - 76, - 149, - 11, - 66, - 250, - 195, - 78, - 8, - 46, - 161, - 102, - 40, - 217, - 36, - 178, - 118, - 91, - 162, - 73, - 109, - 139, - 209, - 37, - 114, - 248, - 246, - 100, - 134, - 104, - 152, - 22, - 212, - 164, - 92, - 204, - 93, - 101, - 182, - 146, - 108, - 112, - 72, - 80, - 253, - 237, - 185, - 218, - 94, - 21, - 70, - 87, - 167, - 141, - 157, - 132, - 144, - 216, - 171, - 0, - 140, - 188, - 211, - 10, - 247, - 228, - 88, - 5, - 184, - 179, - 69, - 6, - 208, - 44, - 30, - 143, - 202, - 63, - 15, - 2, - 193, - 175, - 189, - 3, - 1, - 19, - 138, - 107, - 58, - 145, - 17, - 65, - 79, - 103, - 220, - 234, - 151, - 242, - 207, - 206, - 240, - 180, - 230, - 115, - 150, - 172, - 116, - 34, - 231, - 173, - 53, - 133, - 226, - 249, - 55, - 232, - 28, - 117, - 223, - 110, - 71, - 241, - 26, - 113, - 29, - 41, - 197, - 137, - 111, - 183, - 98, - 14, - 170, - 24, - 190, - 27, - 252, - 86, - 62, - 75, - 198, - 210, - 121, - 32, - 154, - 219, - 192, - 254, - 120, - 205, - 90, - 244, - 31, - 221, - 168, - 51, - 136, - 7, - 199, - 49, - 177, - 18, - 16, - 89, - 39, - 128, - 236, - 95, - 96, - 81, - 127, - 169, - 25, - 181, - 74, - 13, - 45, - 229, - 122, - 159, - 147, - 201, - 156, - 239, - 160, - 224, - 59, - 77, - 174, - 42, - 245, - 176, - 200, - 235, - 187, - 60, - 131, - 83, - 153, - 97, - 23, - 43, - 4, - 126, - 186, - 119, - 214, - 38, - 225, - 105, - 20, - 99, - 85, - 33, - 12, - 125, - ]; - - static const _rcon = [ - 0x01, - 0x02, - 0x04, - 0x08, - 0x10, - 0x20, - 0x40, - 0x80, - 0x1b, - 0x36, - 0x6c, - 0xd8, - 0xab, - 0x4d, - 0x9a, - 0x2f, - 0x5e, - 0xbc, - 0x63, - 0xc6, - 0x97, - 0x35, - 0x6a, - 0xd4, - 0xb3, - 0x7d, - 0xfa, - 0xef, - 0xc5, - 0x91 - ]; - - static const _T0 = [ - 0xa56363c6, - 0x847c7cf8, - 0x997777ee, - 0x8d7b7bf6, - 0x0df2f2ff, - 0xbd6b6bd6, - 0xb16f6fde, - 0x54c5c591, - 0x50303060, - 0x03010102, - 0xa96767ce, - 0x7d2b2b56, - 0x19fefee7, - 0x62d7d7b5, - 0xe6abab4d, - 0x9a7676ec, - 0x45caca8f, - 0x9d82821f, - 0x40c9c989, - 0x877d7dfa, - 0x15fafaef, - 0xeb5959b2, - 0xc947478e, - 0x0bf0f0fb, - 0xecadad41, - 0x67d4d4b3, - 0xfda2a25f, - 0xeaafaf45, - 0xbf9c9c23, - 0xf7a4a453, - 0x967272e4, - 0x5bc0c09b, - 0xc2b7b775, - 0x1cfdfde1, - 0xae93933d, - 0x6a26264c, - 0x5a36366c, - 0x413f3f7e, - 0x02f7f7f5, - 0x4fcccc83, - 0x5c343468, - 0xf4a5a551, - 0x34e5e5d1, - 0x08f1f1f9, - 0x937171e2, - 0x73d8d8ab, - 0x53313162, - 0x3f15152a, - 0x0c040408, - 0x52c7c795, - 0x65232346, - 0x5ec3c39d, - 0x28181830, - 0xa1969637, - 0x0f05050a, - 0xb59a9a2f, - 0x0907070e, - 0x36121224, - 0x9b80801b, - 0x3de2e2df, - 0x26ebebcd, - 0x6927274e, - 0xcdb2b27f, - 0x9f7575ea, - 0x1b090912, - 0x9e83831d, - 0x742c2c58, - 0x2e1a1a34, - 0x2d1b1b36, - 0xb26e6edc, - 0xee5a5ab4, - 0xfba0a05b, - 0xf65252a4, - 0x4d3b3b76, - 0x61d6d6b7, - 0xceb3b37d, - 0x7b292952, - 0x3ee3e3dd, - 0x712f2f5e, - 0x97848413, - 0xf55353a6, - 0x68d1d1b9, - 0x00000000, - 0x2cededc1, - 0x60202040, - 0x1ffcfce3, - 0xc8b1b179, - 0xed5b5bb6, - 0xbe6a6ad4, - 0x46cbcb8d, - 0xd9bebe67, - 0x4b393972, - 0xde4a4a94, - 0xd44c4c98, - 0xe85858b0, - 0x4acfcf85, - 0x6bd0d0bb, - 0x2aefefc5, - 0xe5aaaa4f, - 0x16fbfbed, - 0xc5434386, - 0xd74d4d9a, - 0x55333366, - 0x94858511, - 0xcf45458a, - 0x10f9f9e9, - 0x06020204, - 0x817f7ffe, - 0xf05050a0, - 0x443c3c78, - 0xba9f9f25, - 0xe3a8a84b, - 0xf35151a2, - 0xfea3a35d, - 0xc0404080, - 0x8a8f8f05, - 0xad92923f, - 0xbc9d9d21, - 0x48383870, - 0x04f5f5f1, - 0xdfbcbc63, - 0xc1b6b677, - 0x75dadaaf, - 0x63212142, - 0x30101020, - 0x1affffe5, - 0x0ef3f3fd, - 0x6dd2d2bf, - 0x4ccdcd81, - 0x140c0c18, - 0x35131326, - 0x2fececc3, - 0xe15f5fbe, - 0xa2979735, - 0xcc444488, - 0x3917172e, - 0x57c4c493, - 0xf2a7a755, - 0x827e7efc, - 0x473d3d7a, - 0xac6464c8, - 0xe75d5dba, - 0x2b191932, - 0x957373e6, - 0xa06060c0, - 0x98818119, - 0xd14f4f9e, - 0x7fdcdca3, - 0x66222244, - 0x7e2a2a54, - 0xab90903b, - 0x8388880b, - 0xca46468c, - 0x29eeeec7, - 0xd3b8b86b, - 0x3c141428, - 0x79dedea7, - 0xe25e5ebc, - 0x1d0b0b16, - 0x76dbdbad, - 0x3be0e0db, - 0x56323264, - 0x4e3a3a74, - 0x1e0a0a14, - 0xdb494992, - 0x0a06060c, - 0x6c242448, - 0xe45c5cb8, - 0x5dc2c29f, - 0x6ed3d3bd, - 0xefacac43, - 0xa66262c4, - 0xa8919139, - 0xa4959531, - 0x37e4e4d3, - 0x8b7979f2, - 0x32e7e7d5, - 0x43c8c88b, - 0x5937376e, - 0xb76d6dda, - 0x8c8d8d01, - 0x64d5d5b1, - 0xd24e4e9c, - 0xe0a9a949, - 0xb46c6cd8, - 0xfa5656ac, - 0x07f4f4f3, - 0x25eaeacf, - 0xaf6565ca, - 0x8e7a7af4, - 0xe9aeae47, - 0x18080810, - 0xd5baba6f, - 0x887878f0, - 0x6f25254a, - 0x722e2e5c, - 0x241c1c38, - 0xf1a6a657, - 0xc7b4b473, - 0x51c6c697, - 0x23e8e8cb, - 0x7cdddda1, - 0x9c7474e8, - 0x211f1f3e, - 0xdd4b4b96, - 0xdcbdbd61, - 0x868b8b0d, - 0x858a8a0f, - 0x907070e0, - 0x423e3e7c, - 0xc4b5b571, - 0xaa6666cc, - 0xd8484890, - 0x05030306, - 0x01f6f6f7, - 0x120e0e1c, - 0xa36161c2, - 0x5f35356a, - 0xf95757ae, - 0xd0b9b969, - 0x91868617, - 0x58c1c199, - 0x271d1d3a, - 0xb99e9e27, - 0x38e1e1d9, - 0x13f8f8eb, - 0xb398982b, - 0x33111122, - 0xbb6969d2, - 0x70d9d9a9, - 0x898e8e07, - 0xa7949433, - 0xb69b9b2d, - 0x221e1e3c, - 0x92878715, - 0x20e9e9c9, - 0x49cece87, - 0xff5555aa, - 0x78282850, - 0x7adfdfa5, - 0x8f8c8c03, - 0xf8a1a159, - 0x80898909, - 0x170d0d1a, - 0xdabfbf65, - 0x31e6e6d7, - 0xc6424284, - 0xb86868d0, - 0xc3414182, - 0xb0999929, - 0x772d2d5a, - 0x110f0f1e, - 0xcbb0b07b, - 0xfc5454a8, - 0xd6bbbb6d, - 0x3a16162c - ]; - - static const _Tinv0 = [ - 0x50a7f451, - 0x5365417e, - 0xc3a4171a, - 0x965e273a, - 0xcb6bab3b, - 0xf1459d1f, - 0xab58faac, - 0x9303e34b, - 0x55fa3020, - 0xf66d76ad, - 0x9176cc88, - 0x254c02f5, - 0xfcd7e54f, - 0xd7cb2ac5, - 0x80443526, - 0x8fa362b5, - 0x495ab1de, - 0x671bba25, - 0x980eea45, - 0xe1c0fe5d, - 0x02752fc3, - 0x12f04c81, - 0xa397468d, - 0xc6f9d36b, - 0xe75f8f03, - 0x959c9215, - 0xeb7a6dbf, - 0xda595295, - 0x2d83bed4, - 0xd3217458, - 0x2969e049, - 0x44c8c98e, - 0x6a89c275, - 0x78798ef4, - 0x6b3e5899, - 0xdd71b927, - 0xb64fe1be, - 0x17ad88f0, - 0x66ac20c9, - 0xb43ace7d, - 0x184adf63, - 0x82311ae5, - 0x60335197, - 0x457f5362, - 0xe07764b1, - 0x84ae6bbb, - 0x1ca081fe, - 0x942b08f9, - 0x58684870, - 0x19fd458f, - 0x876cde94, - 0xb7f87b52, - 0x23d373ab, - 0xe2024b72, - 0x578f1fe3, - 0x2aab5566, - 0x0728ebb2, - 0x03c2b52f, - 0x9a7bc586, - 0xa50837d3, - 0xf2872830, - 0xb2a5bf23, - 0xba6a0302, - 0x5c8216ed, - 0x2b1ccf8a, - 0x92b479a7, - 0xf0f207f3, - 0xa1e2694e, - 0xcdf4da65, - 0xd5be0506, - 0x1f6234d1, - 0x8afea6c4, - 0x9d532e34, - 0xa055f3a2, - 0x32e18a05, - 0x75ebf6a4, - 0x39ec830b, - 0xaaef6040, - 0x069f715e, - 0x51106ebd, - 0xf98a213e, - 0x3d06dd96, - 0xae053edd, - 0x46bde64d, - 0xb58d5491, - 0x055dc471, - 0x6fd40604, - 0xff155060, - 0x24fb9819, - 0x97e9bdd6, - 0xcc434089, - 0x779ed967, - 0xbd42e8b0, - 0x888b8907, - 0x385b19e7, - 0xdbeec879, - 0x470a7ca1, - 0xe90f427c, - 0xc91e84f8, - 0x00000000, - 0x83868009, - 0x48ed2b32, - 0xac70111e, - 0x4e725a6c, - 0xfbff0efd, - 0x5638850f, - 0x1ed5ae3d, - 0x27392d36, - 0x64d90f0a, - 0x21a65c68, - 0xd1545b9b, - 0x3a2e3624, - 0xb1670a0c, - 0x0fe75793, - 0xd296eeb4, - 0x9e919b1b, - 0x4fc5c080, - 0xa220dc61, - 0x694b775a, - 0x161a121c, - 0x0aba93e2, - 0xe52aa0c0, - 0x43e0223c, - 0x1d171b12, - 0x0b0d090e, - 0xadc78bf2, - 0xb9a8b62d, - 0xc8a91e14, - 0x8519f157, - 0x4c0775af, - 0xbbdd99ee, - 0xfd607fa3, - 0x9f2601f7, - 0xbcf5725c, - 0xc53b6644, - 0x347efb5b, - 0x7629438b, - 0xdcc623cb, - 0x68fcedb6, - 0x63f1e4b8, - 0xcadc31d7, - 0x10856342, - 0x40229713, - 0x2011c684, - 0x7d244a85, - 0xf83dbbd2, - 0x1132f9ae, - 0x6da129c7, - 0x4b2f9e1d, - 0xf330b2dc, - 0xec52860d, - 0xd0e3c177, - 0x6c16b32b, - 0x99b970a9, - 0xfa489411, - 0x2264e947, - 0xc48cfca8, - 0x1a3ff0a0, - 0xd82c7d56, - 0xef903322, - 0xc74e4987, - 0xc1d138d9, - 0xfea2ca8c, - 0x360bd498, - 0xcf81f5a6, - 0x28de7aa5, - 0x268eb7da, - 0xa4bfad3f, - 0xe49d3a2c, - 0x0d927850, - 0x9bcc5f6a, - 0x62467e54, - 0xc2138df6, - 0xe8b8d890, - 0x5ef7392e, - 0xf5afc382, - 0xbe805d9f, - 0x7c93d069, - 0xa92dd56f, - 0xb31225cf, - 0x3b99acc8, - 0xa77d1810, - 0x6e639ce8, - 0x7bbb3bdb, - 0x097826cd, - 0xf418596e, - 0x01b79aec, - 0xa89a4f83, - 0x656e95e6, - 0x7ee6ffaa, - 0x08cfbc21, - 0xe6e815ef, - 0xd99be7ba, - 0xce366f4a, - 0xd4099fea, - 0xd67cb029, - 0xafb2a431, - 0x31233f2a, - 0x3094a5c6, - 0xc066a235, - 0x37bc4e74, - 0xa6ca82fc, - 0xb0d090e0, - 0x15d8a733, - 0x4a9804f1, - 0xf7daec41, - 0x0e50cd7f, - 0x2ff69117, - 0x8dd64d76, - 0x4db0ef43, - 0x544daacc, - 0xdf0496e4, - 0xe3b5d19e, - 0x1b886a4c, - 0xb81f2cc1, - 0x7f516546, - 0x04ea5e9d, - 0x5d358c01, - 0x737487fa, - 0x2e410bfb, - 0x5a1d67b3, - 0x52d2db92, - 0x335610e9, - 0x1347d66d, - 0x8c61d79a, - 0x7a0ca137, - 0x8e14f859, - 0x893c13eb, - 0xee27a9ce, - 0x35c961b7, - 0xede51ce1, - 0x3cb1477a, - 0x59dfd29c, - 0x3f73f255, - 0x79ce1418, - 0xbf37c773, - 0xeacdf753, - 0x5baafd5f, - 0x146f3ddf, - 0x86db4478, - 0x81f3afca, - 0x3ec468b9, - 0x2c342438, - 0x5f40a3c2, - 0x72c31d16, - 0x0c25e2bc, - 0x8b493c28, - 0x41950dff, - 0x7101a839, - 0xdeb30c08, - 0x9ce4b4d8, - 0x90c15664, - 0x6184cb7b, - 0x70b632d5, - 0x745c6c48, - 0x4257b8d0 - ]; - - int _shift(int r, int shift) => rotr32(r, shift); - - static const int _m1 = 0x80808080; - static const int _m2 = 0x7f7f7f7f; - static const int _m3 = 0x0000001b; - static const int _m4 = 0xC0C0C0C0; - static const int _m5 = 0x3f3f3f3f; - - int _fFmulX(int x) { - var lsr = shiftr32(x & _m1, 7); - return ((x & _m2) << 1) ^ lsr * _m3; - } - - int _fFmulX2(int x) { - var t0 = shiftl32(x & _m5, 2); // int t0 = (x & m5) << 2; - var t1 = x & _m4; - t1 ^= shiftr32(t1, 1); - return t0 ^ shiftr32(t1, 2) ^ shiftr32(t1, 5); - } - - /// - /// The following defines provide alternative definitions of FFmulX that might - /// give improved performance if a fast 32-bit multiply is not available. - /// private int FFmulX(int x) { int u = x & m1; u |= (u >> 1); return ((x & m2) << 1) ^ ((u >>> 3) | (u >>> 6)); } - /// private static final int m4 = 0x1b1b1b1b; - /// private int FFmulX(int x) { int u = x & m1; return ((x & m2) << 1) ^ ((u - (u >>> 7)) & m4); } - /// - int _invMcol(int x) { - int t0, t1; - t0 = x; - t1 = t0 ^ _shift(t0, 8); - t0 ^= _fFmulX(t1); - t1 ^= _fFmulX2(t0); - t0 ^= t1 ^ _shift(t1, 16); - return t0; - } - - int _subWord(int x) { - return _S[x & 255] & 255 | - ((_S[(x >> 8) & 255] & 255) << 8) | - ((_S[(x >> 16) & 255] & 255) << 16) | - _S[(x >> 24) & 255] << 24; - } - - static const _BLOCK_SIZE = 16; - - @override - String get algorithmName => 'AES'; - - @override - int get blockSize => _BLOCK_SIZE; - - @override - void reset() {} - - @override - void init(bool forEncryption, covariant KeyParameter params) { - _forEncryption = forEncryption; - - _WorkingKey = generateWorkingKey(forEncryption, params); - - if (_forEncryption) { - _s = List.from(_S); - } else { - _s = List.from(_Si); - } - } - - List> generateWorkingKey(bool forEncryption, KeyParameter params) { - var key = params.key; - var keyLen = key.length; - if (keyLen < 16 || keyLen > 32 || (keyLen & 7) != 0) { - throw ArgumentError('Key length not 128/192/256 bits.'); - } - - var KC = shiftr32(keyLen, 2); - _ROUNDS = KC + - 6; // This is not always true for the generalized Rijndael that allows larger block sizes - - var W = List.generate( - _ROUNDS + 1, - (int i) => - List.filled(4, 0, growable: false)); // 4 words in a block - - switch (KC) { - case 4: - var col0 = unpack32(key, 0, Endian.little); - W[0][0] = col0; - var col1 = unpack32(key, 4, Endian.little); - W[0][1] = col1; - var col2 = unpack32(key, 8, Endian.little); - W[0][2] = col2; - var col3 = unpack32(key, 12, Endian.little); - W[0][3] = col3; - - for (var i = 1; i <= 10; ++i) { - var colx = _subWord(_shift(col3, 8)) ^ _rcon[i - 1]; - col0 ^= colx; - W[i][0] = col0; - col1 ^= col0; - W[i][1] = col1; - col2 ^= col1; - W[i][2] = col2; - col3 ^= col2; - W[i][3] = col3; - } - break; - case 6: - var col0 = unpack32(key, 0, Endian.little); - W[0][0] = col0; - var col1 = unpack32(key, 4, Endian.little); - W[0][1] = col1; - var col2 = unpack32(key, 8, Endian.little); - W[0][2] = col2; - var col3 = unpack32(key, 12, Endian.little); - W[0][3] = col3; - - var col4 = unpack32(key, 16, Endian.little); - var col5 = unpack32(key, 20, Endian.little); - - int i = 1, rcon = 1, colx; - for (;;) { - W[i][0] = col4; - W[i][1] = col5; - colx = _subWord(_shift(col5, 8)) ^ rcon; - rcon <<= 1; - col0 ^= colx; - W[i][2] = col0; - col1 ^= col0; - W[i][3] = col1; - - col2 ^= col1; - W[i + 1][0] = col2; - col3 ^= col2; - W[i + 1][1] = col3; - col4 ^= col3; - W[i + 1][2] = col4; - col5 ^= col4; - W[i + 1][3] = col5; - - colx = _subWord(_shift(col5, 8)) ^ rcon; - rcon <<= 1; - col0 ^= colx; - W[i + 2][0] = col0; - col1 ^= col0; - W[i + 2][1] = col1; - col2 ^= col1; - W[i + 2][2] = col2; - col3 ^= col2; - W[i + 2][3] = col3; - - if ((i += 3) >= 13) { - break; - } - - col4 ^= col3; - col5 ^= col4; - } - - break; - - case 8: - { - var col0 = unpack32(key, 0, Endian.little); - W[0][0] = col0; - var col1 = unpack32(key, 4, Endian.little); - W[0][1] = col1; - var col2 = unpack32(key, 8, Endian.little); - W[0][2] = col2; - var col3 = unpack32(key, 12, Endian.little); - W[0][3] = col3; - - var col4 = unpack32(key, 16, Endian.little); - W[1][0] = col4; - var col5 = unpack32(key, 20, Endian.little); - W[1][1] = col5; - var col6 = unpack32(key, 24, Endian.little); - W[1][2] = col6; - var col7 = unpack32(key, 28, Endian.little); - W[1][3] = col7; - - int i = 2, rcon = 1, colx; - for (;;) { - colx = _subWord(_shift(col7, 8)) ^ rcon; - rcon <<= 1; - col0 ^= colx; - W[i][0] = col0; - col1 ^= col0; - W[i][1] = col1; - col2 ^= col1; - W[i][2] = col2; - col3 ^= col2; - W[i][3] = col3; - ++i; - - if (i >= 15) { - break; - } - - colx = _subWord(col3); - col4 ^= colx; - W[i][0] = col4; - col5 ^= col4; - W[i][1] = col5; - col6 ^= col5; - W[i][2] = col6; - col7 ^= col6; - W[i][3] = col7; - ++i; - } - - break; - } - default: - { - throw StateError('Should never get here'); - } - } - - if (!forEncryption) { - for (var j = 1; j < _ROUNDS; j++) { - for (var i = 0; i < 4; i++) { - W[j][i] = _invMcol(W[j][i]); - } - } - } - - return W; - } - - @override - int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { - if ((inpOff + (32 / 2)) > inp.lengthInBytes) { - throw ArgumentError('Input buffer too short'); - } - - if ((outOff + (32 / 2)) > out.lengthInBytes) { - throw ArgumentError('Output buffer too short'); - } - - if (_forEncryption) { - _encryptBlock(inp, inpOff, out, outOff, _WorkingKey); - } else { - _decryptBlock(inp, inpOff, out, outOff, _WorkingKey); - } - - return _BLOCK_SIZE; - } - - void _encryptBlock( - input, int inOff, Uint8List out, int outOff, List> KW) { - var C0 = unpack32(input, inOff + 0, Endian.little); - var C1 = unpack32(input, inOff + 4, Endian.little); - var C2 = unpack32(input, inOff + 8, Endian.little); - var C3 = unpack32(input, inOff + 12, Endian.little); - - var t0 = C0 ^ KW[0][0]; - var t1 = C1 ^ KW[0][1]; - var t2 = C2 ^ KW[0][2]; - - int r = 1, r0, r1, r2, r3 = C3 ^ KW[0][3]; - - while (r < _ROUNDS - 1) { - r0 = _T0[t0 & 255] ^ - _shift(_T0[(t1 >> 8) & 255], 24) ^ - _shift(_T0[(t2 >> 16) & 255], 16) ^ - _shift(_T0[(r3 >> 24) & 255], 8) ^ - KW[r][0]; - r1 = _T0[t1 & 255] ^ - _shift(_T0[(t2 >> 8) & 255], 24) ^ - _shift(_T0[(r3 >> 16) & 255], 16) ^ - _shift(_T0[(t0 >> 24) & 255], 8) ^ - KW[r][1]; - r2 = _T0[t2 & 255] ^ - _shift(_T0[(r3 >> 8) & 255], 24) ^ - _shift(_T0[(t0 >> 16) & 255], 16) ^ - _shift(_T0[(t1 >> 24) & 255], 8) ^ - KW[r][2]; - r3 = _T0[r3 & 255] ^ - _shift(_T0[(t0 >> 8) & 255], 24) ^ - _shift(_T0[(t1 >> 16) & 255], 16) ^ - _shift(_T0[(t2 >> 24) & 255], 8) ^ - KW[r++][3]; - t0 = _T0[r0 & 255] ^ - _shift(_T0[(r1 >> 8) & 255], 24) ^ - _shift(_T0[(r2 >> 16) & 255], 16) ^ - _shift(_T0[(r3 >> 24) & 255], 8) ^ - KW[r][0]; - t1 = _T0[r1 & 255] ^ - _shift(_T0[(r2 >> 8) & 255], 24) ^ - _shift(_T0[(r3 >> 16) & 255], 16) ^ - _shift(_T0[(r0 >> 24) & 255], 8) ^ - KW[r][1]; - t2 = _T0[r2 & 255] ^ - _shift(_T0[(r3 >> 8) & 255], 24) ^ - _shift(_T0[(r0 >> 16) & 255], 16) ^ - _shift(_T0[(r1 >> 24) & 255], 8) ^ - KW[r][2]; - r3 = _T0[r3 & 255] ^ - _shift(_T0[(r0 >> 8) & 255], 24) ^ - _shift(_T0[(r1 >> 16) & 255], 16) ^ - _shift(_T0[(r2 >> 24) & 255], 8) ^ - KW[r++][3]; - } - - r0 = _T0[t0 & 255] ^ - _shift(_T0[(t1 >> 8) & 255], 24) ^ - _shift(_T0[(t2 >> 16) & 255], 16) ^ - _shift(_T0[(r3 >> 24) & 255], 8) ^ - KW[r][0]; - r1 = _T0[t1 & 255] ^ - _shift(_T0[(t2 >> 8) & 255], 24) ^ - _shift(_T0[(r3 >> 16) & 255], 16) ^ - _shift(_T0[(t0 >> 24) & 255], 8) ^ - KW[r][1]; - r2 = _T0[t2 & 255] ^ - _shift(_T0[(r3 >> 8) & 255], 24) ^ - _shift(_T0[(t0 >> 16) & 255], 16) ^ - _shift(_T0[(t1 >> 24) & 255], 8) ^ - KW[r][2]; - r3 = _T0[r3 & 255] ^ - _shift(_T0[(t0 >> 8) & 255], 24) ^ - _shift(_T0[(t1 >> 16) & 255], 16) ^ - _shift(_T0[(t2 >> 24) & 255], 8) ^ - KW[r++][3]; - - // the final round's table is a simple function of S so we don't use a whole other four tables for it - - C0 = (_S[r0 & 255] & 255) ^ - ((_S[(r1 >> 8) & 255] & 255) << 8) ^ - ((_s[(r2 >> 16) & 255] & 255) << 16) ^ - (_s[(r3 >> 24) & 255] << 24) ^ - KW[r][0]; - C1 = (_s[r1 & 255] & 255) ^ - ((_S[(r2 >> 8) & 255] & 255) << 8) ^ - ((_S[(r3 >> 16) & 255] & 255) << 16) ^ - (_s[(r0 >> 24) & 255] << 24) ^ - KW[r][1]; - C2 = (_s[r2 & 255] & 255) ^ - ((_S[(r3 >> 8) & 255] & 255) << 8) ^ - ((_S[(r0 >> 16) & 255] & 255) << 16) ^ - (_S[(r1 >> 24) & 255] << 24) ^ - KW[r][2]; - C3 = (_s[r3 & 255] & 255) ^ - ((_s[(r0 >> 8) & 255] & 255) << 8) ^ - ((_s[(r1 >> 16) & 255] & 255) << 16) ^ - (_S[(r2 >> 24) & 255] << 24) ^ - KW[r][3]; - - pack32(C0, out, outOff + 0, Endian.little); - pack32(C1, out, outOff + 4, Endian.little); - pack32(C2, out, outOff + 8, Endian.little); - pack32(C3, out, outOff + 12, Endian.little); - } - - void _decryptBlock( - input, int inOff, Uint8List out, int outOff, List> KW) { - var C0 = unpack32(input, inOff + 0, Endian.little); - var C1 = unpack32(input, inOff + 4, Endian.little); - var C2 = unpack32(input, inOff + 8, Endian.little); - var C3 = unpack32(input, inOff + 12, Endian.little); - - var t0 = C0 ^ KW[_ROUNDS][0]; - var t1 = C1 ^ KW[_ROUNDS][1]; - var t2 = C2 ^ KW[_ROUNDS][2]; - - int r = _ROUNDS - 1, r0, r1, r2, r3 = C3 ^ KW[_ROUNDS][3]; - while (r > 1) { - r0 = _Tinv0[t0 & 255] ^ - _shift(_Tinv0[(r3 >> 8) & 255], 24) ^ - _shift(_Tinv0[(t2 >> 16) & 255], 16) ^ - _shift(_Tinv0[(t1 >> 24) & 255], 8) ^ - KW[r][0]; - r1 = _Tinv0[t1 & 255] ^ - _shift(_Tinv0[(t0 >> 8) & 255], 24) ^ - _shift(_Tinv0[(r3 >> 16) & 255], 16) ^ - _shift(_Tinv0[(t2 >> 24) & 255], 8) ^ - KW[r][1]; - r2 = _Tinv0[t2 & 255] ^ - _shift(_Tinv0[(t1 >> 8) & 255], 24) ^ - _shift(_Tinv0[(t0 >> 16) & 255], 16) ^ - _shift(_Tinv0[(r3 >> 24) & 255], 8) ^ - KW[r][2]; - r3 = _Tinv0[r3 & 255] ^ - _shift(_Tinv0[(t2 >> 8) & 255], 24) ^ - _shift(_Tinv0[(t1 >> 16) & 255], 16) ^ - _shift(_Tinv0[(t0 >> 24) & 255], 8) ^ - KW[r--][3]; - t0 = _Tinv0[r0 & 255] ^ - _shift(_Tinv0[(r3 >> 8) & 255], 24) ^ - _shift(_Tinv0[(r2 >> 16) & 255], 16) ^ - _shift(_Tinv0[(r1 >> 24) & 255], 8) ^ - KW[r][0]; - t1 = _Tinv0[r1 & 255] ^ - _shift(_Tinv0[(r0 >> 8) & 255], 24) ^ - _shift(_Tinv0[(r3 >> 16) & 255], 16) ^ - _shift(_Tinv0[(r2 >> 24) & 255], 8) ^ - KW[r][1]; - t2 = _Tinv0[r2 & 255] ^ - _shift(_Tinv0[(r1 >> 8) & 255], 24) ^ - _shift(_Tinv0[(r0 >> 16) & 255], 16) ^ - _shift(_Tinv0[(r3 >> 24) & 255], 8) ^ - KW[r][2]; - r3 = _Tinv0[r3 & 255] ^ - _shift(_Tinv0[(r2 >> 8) & 255], 24) ^ - _shift(_Tinv0[(r1 >> 16) & 255], 16) ^ - _shift(_Tinv0[(r0 >> 24) & 255], 8) ^ - KW[r--][3]; - } - - r0 = _Tinv0[t0 & 255] ^ - _shift(_Tinv0[(r3 >> 8) & 255], 24) ^ - _shift(_Tinv0[(t2 >> 16) & 255], 16) ^ - _shift(_Tinv0[(t1 >> 24) & 255], 8) ^ - KW[r][0]; - r1 = _Tinv0[t1 & 255] ^ - _shift(_Tinv0[(t0 >> 8) & 255], 24) ^ - _shift(_Tinv0[(r3 >> 16) & 255], 16) ^ - _shift(_Tinv0[(t2 >> 24) & 255], 8) ^ - KW[r][1]; - r2 = _Tinv0[t2 & 255] ^ - _shift(_Tinv0[(t1 >> 8) & 255], 24) ^ - _shift(_Tinv0[(t0 >> 16) & 255], 16) ^ - _shift(_Tinv0[(r3 >> 24) & 255], 8) ^ - KW[r][2]; - r3 = _Tinv0[r3 & 255] ^ - _shift(_Tinv0[(t2 >> 8) & 255], 24) ^ - _shift(_Tinv0[(t1 >> 16) & 255], 16) ^ - _shift(_Tinv0[(t0 >> 24) & 255], 8) ^ - KW[r][3]; - - // the final round's table is a simple function of Si so we don't use a whole other four tables for it - - C0 = (_Si[r0 & 255] & 255) ^ - ((_s[(r3 >> 8) & 255] & 255) << 8) ^ - ((_s[(r2 >> 16) & 255] & 255) << 16) ^ - (_Si[(r1 >> 24) & 255] << 24) ^ - KW[0][0]; - C1 = (_s[r1 & 255] & 255) ^ - ((_s[(r0 >> 8) & 255] & 255) << 8) ^ - ((_Si[(r3 >> 16) & 255] & 255) << 16) ^ - (_s[(r2 >> 24) & 255] << 24) ^ - KW[0][1]; - C2 = (_s[r2 & 255] & 255) ^ - ((_Si[(r1 >> 8) & 255] & 255) << 8) ^ - ((_Si[(r0 >> 16) & 255] & 255) << 16) ^ - (_s[(r3 >> 24) & 255] << 24) ^ - KW[0][2]; - C3 = (_Si[r3 & 255] & 255) ^ - ((_s[(r2 >> 8) & 255] & 255) << 8) ^ - ((_s[(r1 >> 16) & 255] & 255) << 16) ^ - (_s[(r0 >> 24) & 255] << 24) ^ - KW[0][3]; - - pack32(C0, out, outOff + 0, Endian.little); - pack32(C1, out, outOff + 4, Endian.little); - pack32(C2, out, outOff + 8, Endian.little); - pack32(C3, out, outOff + 12, Endian.little); - } -} diff --git a/pointycastle/lib/block/aes_fast.dart b/pointycastle/lib/block/aes_fast.dart deleted file mode 100644 index d514187..0000000 --- a/pointycastle/lib/block/aes_fast.dart +++ /dev/null @@ -1,3000 +0,0 @@ -// See file LICENSE for more information. - -library impl.block_cipher.aes_fast; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_block_cipher.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// An implementation of the AES (Rijndael), from FIPS-197. -/// -/// For further details see: [http://csrc.nist.gov/encryption/aes/] -/// -/// This implementation is based on optimizations from Dr. Brian Gladman's paper -/// and C code at [http://fp.gladman.plus.com/cryptography_technology/rijndael/] -/// deprecated: Unfortunately this class is has a few side channel issues. -/// In an environment where encryption/decryption may be closely observed it -/// should not be used. -@Deprecated('Has side-channel issues.') -class AESFastEngine extends BaseBlockCipher { - static const _BLOCK_SIZE = 16; - - late bool _forEncryption; - List>? _workingKey; - late int _rounds; - late int _c0, _c1, _c2, _c3; - - @override - String get algorithmName => 'AES_FAST_'; - - @override - int get blockSize => _BLOCK_SIZE; - - @override - void reset() { - _rounds = 0; - _c0 = _c1 = _c2 = _c3 = 0; - _forEncryption = false; - _workingKey = null; - } - - @override - void init(bool forEncryption, covariant KeyParameter params) { - var key = params.key; - - var kc = (key.lengthInBytes / 4).floor(); // key length in words - if (((kc != 4) && (kc != 6) && (kc != 8)) || - ((kc * 4) != key.lengthInBytes)) { - throw ArgumentError('Key length must be 128/192/256 bits'); - } - - _forEncryption = forEncryption; - _rounds = kc + - 6; // This is not always true for the generalized Rijndael that allows larger block sizes - _workingKey = List.generate( - _rounds + 1, - (int i) => - List.filled(4, 0, growable: false)); // 4 words in a block - - // Copy the key into the round key array. - var keyView = ByteData.view( - params.key.buffer, params.key.offsetInBytes, params.key.length); - for (var i = 0, t = 0; i < key.lengthInBytes; i += 4, t++) { - var value = unpack32(keyView, i, Endian.little); - _workingKey![t >> 2][t & 3] = value; - } - - // While not enough round key material calculated calculate values. - var k = (_rounds + 1) << 2; - for (var i = kc; i < k; i++) { - var temp = _workingKey![(i - 1) >> 2][(i - 1) & 3].toInt(); - if ((i % kc) == 0) { - temp = _subWord(_shift(temp, 8)) ^ _rcon[((i / kc) - 1).floor()]; - } else if ((kc > 6) && ((i % kc) == 4)) { - temp = _subWord(temp); - } - - var value = _workingKey![(i - kc) >> 2][(i - kc) & 3] ^ temp; - _workingKey![i >> 2][i & 3] = value; - } - - if (!forEncryption) { - for (var j = 1; j < _rounds; j++) { - for (var i = 0; i < 4; i++) { - var value = _invMcol(_workingKey![j][i].toInt()); - _workingKey![j][i] = value; - } - } - } - } - - @override - int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { - if (_workingKey == null) { - throw StateError('AES engine not initialised'); - } - - if ((inpOff + (32 / 2)) > inp.lengthInBytes) { - throw ArgumentError('Input buffer too short'); - } - - if ((outOff + (32 / 2)) > out.lengthInBytes) { - throw ArgumentError('Output buffer too short'); - } - - var inpView = ByteData.view(inp.buffer, inp.offsetInBytes, inp.length); - var outView = ByteData.view(out.buffer, out.offsetInBytes, out.length); - if (_forEncryption) { - _unpackBlock(inpView, inpOff); - _encryptBlock(_workingKey!); - _packBlock(outView, outOff); - } else { - _unpackBlock(inpView, inpOff); - _decryptBlock(_workingKey!); - _packBlock(outView, outOff); - } - - return _BLOCK_SIZE; - } - - void _encryptBlock(List> kw) { - int r, r0, r1, r2, r3; - - _c0 ^= kw[0][0]!.toInt(); - _c1 ^= kw[0][1]!.toInt(); - _c2 ^= kw[0][2]!.toInt(); - _c3 ^= kw[0][3]!.toInt(); - - r = 1; - while (r < _rounds - 1) { - r0 = _t0[_c0 & 255] ^ - _t1[(_c1 >> 8) & 255] ^ - _t2[(_c2 >> 16) & 255] ^ - _t3[(_c3 >> 24) & 255] ^ - kw[r][0]!.toInt(); - r1 = _t0[_c1 & 255] ^ - _t1[(_c2 >> 8) & 255] ^ - _t2[(_c3 >> 16) & 255] ^ - _t3[(_c0 >> 24) & 255] ^ - kw[r][1]!.toInt(); - r2 = _t0[_c2 & 255] ^ - _t1[(_c3 >> 8) & 255] ^ - _t2[(_c0 >> 16) & 255] ^ - _t3[(_c1 >> 24) & 255] ^ - kw[r][2]!.toInt(); - r3 = _t0[_c3 & 255] ^ - _t1[(_c0 >> 8) & 255] ^ - _t2[(_c1 >> 16) & 255] ^ - _t3[(_c2 >> 24) & 255] ^ - kw[r][3]!.toInt(); - r++; - _c0 = _t0[r0 & 255] ^ - _t1[(r1 >> 8) & 255] ^ - _t2[(r2 >> 16) & 255] ^ - _t3[(r3 >> 24) & 255] ^ - kw[r][0]!.toInt(); - _c1 = _t0[r1 & 255] ^ - _t1[(r2 >> 8) & 255] ^ - _t2[(r3 >> 16) & 255] ^ - _t3[(r0 >> 24) & 255] ^ - kw[r][1]!.toInt(); - _c2 = _t0[r2 & 255] ^ - _t1[(r3 >> 8) & 255] ^ - _t2[(r0 >> 16) & 255] ^ - _t3[(r1 >> 24) & 255] ^ - kw[r][2]!.toInt(); - _c3 = _t0[r3 & 255] ^ - _t1[(r0 >> 8) & 255] ^ - _t2[(r1 >> 16) & 255] ^ - _t3[(r2 >> 24) & 255] ^ - kw[r][3]!.toInt(); - r++; - } - - r0 = _t0[_c0 & 255] ^ - _t1[(_c1 >> 8) & 255] ^ - _t2[(_c2 >> 16) & 255] ^ - _t3[(_c3 >> 24) & 255] ^ - kw[r][0]!.toInt(); - r1 = _t0[_c1 & 255] ^ - _t1[(_c2 >> 8) & 255] ^ - _t2[(_c3 >> 16) & 255] ^ - _t3[(_c0 >> 24) & 255] ^ - kw[r][1]!.toInt(); - r2 = _t0[_c2 & 255] ^ - _t1[(_c3 >> 8) & 255] ^ - _t2[(_c0 >> 16) & 255] ^ - _t3[(_c1 >> 24) & 255] ^ - kw[r][2]!.toInt(); - r3 = _t0[_c3 & 255] ^ - _t1[(_c0 >> 8) & 255] ^ - _t2[(_c1 >> 16) & 255] ^ - _t3[(_c2 >> 24) & 255] ^ - kw[r][3]!.toInt(); - r++; - - // the final round's table is a simple function of S so we don't use a whole other four tables for it - _c0 = (_s[r0 & 255] & 255) ^ - ((_s[(r1 >> 8) & 255] & 255) << 8) ^ - ((_s[(r2 >> 16) & 255] & 255) << 16) ^ - (_s[(r3 >> 24) & 255] << 24) ^ - kw[r][0]!.toInt(); - _c1 = (_s[r1 & 255] & 255) ^ - ((_s[(r2 >> 8) & 255] & 255) << 8) ^ - ((_s[(r3 >> 16) & 255] & 255) << 16) ^ - (_s[(r0 >> 24) & 255] << 24) ^ - kw[r][1]!.toInt(); - _c2 = (_s[r2 & 255] & 255) ^ - ((_s[(r3 >> 8) & 255] & 255) << 8) ^ - ((_s[(r0 >> 16) & 255] & 255) << 16) ^ - (_s[(r1 >> 24) & 255] << 24) ^ - kw[r][2]!.toInt(); - _c3 = (_s[r3 & 255] & 255) ^ - ((_s[(r0 >> 8) & 255] & 255) << 8) ^ - ((_s[(r1 >> 16) & 255] & 255) << 16) ^ - (_s[(r2 >> 24) & 255] << 24) ^ - kw[r][3]!.toInt(); - } - - void _decryptBlock(List> kw) { - int r, r0, r1, r2, r3; - - _c0 ^= kw[_rounds][0]!.toInt(); - _c1 ^= kw[_rounds][1]!.toInt(); - _c2 ^= kw[_rounds][2]!.toInt(); - _c3 ^= kw[_rounds][3]!.toInt(); - - r = _rounds - 1; - while (r > 1) { - r0 = _tinv0[_c0 & 255] ^ - _tinv1[(_c3 >> 8) & 255] ^ - _tinv2[(_c2 >> 16) & 255] ^ - _tinv3[(_c1 >> 24) & 255] ^ - kw[r][0]!.toInt(); - r1 = _tinv0[_c1 & 255] ^ - _tinv1[(_c0 >> 8) & 255] ^ - _tinv2[(_c3 >> 16) & 255] ^ - _tinv3[(_c2 >> 24) & 255] ^ - kw[r][1]!.toInt(); - r2 = _tinv0[_c2 & 255] ^ - _tinv1[(_c1 >> 8) & 255] ^ - _tinv2[(_c0 >> 16) & 255] ^ - _tinv3[(_c3 >> 24) & 255] ^ - kw[r][2]!.toInt(); - r3 = _tinv0[_c3 & 255] ^ - _tinv1[(_c2 >> 8) & 255] ^ - _tinv2[(_c1 >> 16) & 255] ^ - _tinv3[(_c0 >> 24) & 255] ^ - kw[r][3]!.toInt(); - r--; - _c0 = _tinv0[r0 & 255] ^ - _tinv1[(r3 >> 8) & 255] ^ - _tinv2[(r2 >> 16) & 255] ^ - _tinv3[(r1 >> 24) & 255] ^ - kw[r][0]!.toInt(); - _c1 = _tinv0[r1 & 255] ^ - _tinv1[(r0 >> 8) & 255] ^ - _tinv2[(r3 >> 16) & 255] ^ - _tinv3[(r2 >> 24) & 255] ^ - kw[r][1]!.toInt(); - _c2 = _tinv0[r2 & 255] ^ - _tinv1[(r1 >> 8) & 255] ^ - _tinv2[(r0 >> 16) & 255] ^ - _tinv3[(r3 >> 24) & 255] ^ - kw[r][2]!.toInt(); - _c3 = _tinv0[r3 & 255] ^ - _tinv1[(r2 >> 8) & 255] ^ - _tinv2[(r1 >> 16) & 255] ^ - _tinv3[(r0 >> 24) & 255] ^ - kw[r][3]!.toInt(); - r--; - } - - r0 = _tinv0[_c0 & 255] ^ - _tinv1[(_c3 >> 8) & 255] ^ - _tinv2[(_c2 >> 16) & 255] ^ - _tinv3[(_c1 >> 24) & 255] ^ - kw[r][0]!.toInt(); - r1 = _tinv0[_c1 & 255] ^ - _tinv1[(_c0 >> 8) & 255] ^ - _tinv2[(_c3 >> 16) & 255] ^ - _tinv3[(_c2 >> 24) & 255] ^ - kw[r][1]!.toInt(); - r2 = _tinv0[_c2 & 255] ^ - _tinv1[(_c1 >> 8) & 255] ^ - _tinv2[(_c0 >> 16) & 255] ^ - _tinv3[(_c3 >> 24) & 255] ^ - kw[r][2]!.toInt(); - r3 = _tinv0[_c3 & 255] ^ - _tinv1[(_c2 >> 8) & 255] ^ - _tinv2[(_c1 >> 16) & 255] ^ - _tinv3[(_c0 >> 24) & 255] ^ - kw[r][3]!.toInt(); - - // the final round's table is a simple function of Si so we don't use a whole other four tables for it - _c0 = (_si[r0 & 255] & 255) ^ - ((_si[(r3 >> 8) & 255] & 255) << 8) ^ - ((_si[(r2 >> 16) & 255] & 255) << 16) ^ - (_si[(r1 >> 24) & 255] << 24) ^ - kw[0][0]!.toInt(); - _c1 = (_si[r1 & 255] & 255) ^ - ((_si[(r0 >> 8) & 255] & 255) << 8) ^ - ((_si[(r3 >> 16) & 255] & 255) << 16) ^ - (_si[(r2 >> 24) & 255] << 24) ^ - kw[0][1]!.toInt(); - _c2 = (_si[r2 & 255] & 255) ^ - ((_si[(r1 >> 8) & 255] & 255) << 8) ^ - ((_si[(r0 >> 16) & 255] & 255) << 16) ^ - (_si[(r3 >> 24) & 255] << 24) ^ - kw[0][2]!.toInt(); - _c3 = (_si[r3 & 255] & 255) ^ - ((_si[(r2 >> 8) & 255] & 255) << 8) ^ - ((_si[(r1 >> 16) & 255] & 255) << 16) ^ - (_si[(r0 >> 24) & 255] << 24) ^ - kw[0][3]!.toInt(); - } - - void _unpackBlock(ByteData view, int off) { - _c0 = unpack32(view, off, Endian.little); - _c1 = unpack32(view, off + 4, Endian.little); - _c2 = unpack32(view, off + 8, Endian.little); - _c3 = unpack32(view, off + 12, Endian.little); - } - - void _packBlock(ByteData view, int off) { - pack32(_c0, view, off, Endian.little); - pack32(_c1, view, off + 4, Endian.little); - pack32(_c2, view, off + 8, Endian.little); - pack32(_c3, view, off + 12, Endian.little); - } -} - -int _shift(int r, int shift) => rotr32(r, shift); - -/* multiply four bytes in GF(2^8) by 'x' {02} in parallel */ - -const int _m1 = 0x80808080; -const int _m2 = 0x7f7f7f7f; -const int _m3 = 0x0000001b; - -int _fFmulX(int x) { - var lsr = shiftr32(x & _m1, 7); - return ((x & _m2) << 1) ^ lsr * _m3; -} - -/// -/// The following defines provide alternative definitions of FFmulX that might -/// give improved performance if a fast 32-bit multiply is not available. -/// private int FFmulX(int x) { int u = x & m1; u |= (u >> 1); return ((x & m2) << 1) ^ ((u >>> 3) | (u >>> 6)); } -/// private static final int m4 = 0x1b1b1b1b; -/// private int FFmulX(int x) { int u = x & m1; return ((x & m2) << 1) ^ ((u - (u >>> 7)) & m4); } -/// -int _invMcol(int x) { - var f2 = _fFmulX(x); - var f4 = _fFmulX(f2); - var f8 = _fFmulX(f4); - var f9 = x ^ f8; - - return f2 ^ - f4 ^ - f8 ^ - _shift(f2 ^ f9, 8) ^ - _shift(f4 ^ f9, 16) ^ - _shift(f9, 24); -} - -int _subWord(int x) { - return _s[x & 255] & 255 | - ((_s[(x >> 8) & 255] & 255) << 8) | - ((_s[(x >> 16) & 255] & 255) << 16) | - _s[(x >> 24) & 255] << 24; -} - -// The S box -final _s = [ - 99, - 124, - 119, - 123, - 242, - 107, - 111, - 197, - 48, - 1, - 103, - 43, - 254, - 215, - 171, - 118, - 202, - 130, - 201, - 125, - 250, - 89, - 71, - 240, - 173, - 212, - 162, - 175, - 156, - 164, - 114, - 192, - 183, - 253, - 147, - 38, - 54, - 63, - 247, - 204, - 52, - 165, - 229, - 241, - 113, - 216, - 49, - 21, - 4, - 199, - 35, - 195, - 24, - 150, - 5, - 154, - 7, - 18, - 128, - 226, - 235, - 39, - 178, - 117, - 9, - 131, - 44, - 26, - 27, - 110, - 90, - 160, - 82, - 59, - 214, - 179, - 41, - 227, - 47, - 132, - 83, - 209, - 0, - 237, - 32, - 252, - 177, - 91, - 106, - 203, - 190, - 57, - 74, - 76, - 88, - 207, - 208, - 239, - 170, - 251, - 67, - 77, - 51, - 133, - 69, - 249, - 2, - 127, - 80, - 60, - 159, - 168, - 81, - 163, - 64, - 143, - 146, - 157, - 56, - 245, - 188, - 182, - 218, - 33, - 16, - 255, - 243, - 210, - 205, - 12, - 19, - 236, - 95, - 151, - 68, - 23, - 196, - 167, - 126, - 61, - 100, - 93, - 25, - 115, - 96, - 129, - 79, - 220, - 34, - 42, - 144, - 136, - 70, - 238, - 184, - 20, - 222, - 94, - 11, - 219, - 224, - 50, - 58, - 10, - 73, - 6, - 36, - 92, - 194, - 211, - 172, - 98, - 145, - 149, - 228, - 121, - 231, - 200, - 55, - 109, - 141, - 213, - 78, - 169, - 108, - 86, - 244, - 234, - 101, - 122, - 174, - 8, - 186, - 120, - 37, - 46, - 28, - 166, - 180, - 198, - 232, - 221, - 116, - 31, - 75, - 189, - 139, - 138, - 112, - 62, - 181, - 102, - 72, - 3, - 246, - 14, - 97, - 53, - 87, - 185, - 134, - 193, - 29, - 158, - 225, - 248, - 152, - 17, - 105, - 217, - 142, - 148, - 155, - 30, - 135, - 233, - 206, - 85, - 40, - 223, - 140, - 161, - 137, - 13, - 191, - 230, - 66, - 104, - 65, - 153, - 45, - 15, - 176, - 84, - 187, - 22 -]; - -// The inverse S-box -final _si = [ - 82, - 9, - 106, - 213, - 48, - 54, - 165, - 56, - 191, - 64, - 163, - 158, - 129, - 243, - 215, - 251, - 124, - 227, - 57, - 130, - 155, - 47, - 255, - 135, - 52, - 142, - 67, - 68, - 196, - 222, - 233, - 203, - 84, - 123, - 148, - 50, - 166, - 194, - 35, - 61, - 238, - 76, - 149, - 11, - 66, - 250, - 195, - 78, - 8, - 46, - 161, - 102, - 40, - 217, - 36, - 178, - 118, - 91, - 162, - 73, - 109, - 139, - 209, - 37, - 114, - 248, - 246, - 100, - 134, - 104, - 152, - 22, - 212, - 164, - 92, - 204, - 93, - 101, - 182, - 146, - 108, - 112, - 72, - 80, - 253, - 237, - 185, - 218, - 94, - 21, - 70, - 87, - 167, - 141, - 157, - 132, - 144, - 216, - 171, - 0, - 140, - 188, - 211, - 10, - 247, - 228, - 88, - 5, - 184, - 179, - 69, - 6, - 208, - 44, - 30, - 143, - 202, - 63, - 15, - 2, - 193, - 175, - 189, - 3, - 1, - 19, - 138, - 107, - 58, - 145, - 17, - 65, - 79, - 103, - 220, - 234, - 151, - 242, - 207, - 206, - 240, - 180, - 230, - 115, - 150, - 172, - 116, - 34, - 231, - 173, - 53, - 133, - 226, - 249, - 55, - 232, - 28, - 117, - 223, - 110, - 71, - 241, - 26, - 113, - 29, - 41, - 197, - 137, - 111, - 183, - 98, - 14, - 170, - 24, - 190, - 27, - 252, - 86, - 62, - 75, - 198, - 210, - 121, - 32, - 154, - 219, - 192, - 254, - 120, - 205, - 90, - 244, - 31, - 221, - 168, - 51, - 136, - 7, - 199, - 49, - 177, - 18, - 16, - 89, - 39, - 128, - 236, - 95, - 96, - 81, - 127, - 169, - 25, - 181, - 74, - 13, - 45, - 229, - 122, - 159, - 147, - 201, - 156, - 239, - 160, - 224, - 59, - 77, - 174, - 42, - 245, - 176, - 200, - 235, - 187, - 60, - 131, - 83, - 153, - 97, - 23, - 43, - 4, - 126, - 186, - 119, - 214, - 38, - 225, - 105, - 20, - 99, - 85, - 33, - 12, - 125, -]; - -// vector used in calculating key schedule (powers of x in GF(256)) -final _rcon = [ - 0x01, - 0x02, - 0x04, - 0x08, - 0x10, - 0x20, - 0x40, - 0x80, - 0x1b, - 0x36, - 0x6c, - 0xd8, - 0xab, - 0x4d, - 0x9a, - 0x2f, - 0x5e, - 0xbc, - 0x63, - 0xc6, - 0x97, - 0x35, - 0x6a, - 0xd4, - 0xb3, - 0x7d, - 0xfa, - 0xef, - 0xc5, - 0x91 -]; - -// precomputation tables of calculations for rounds -final _t0 = [ - 0xa56363c6, - 0x847c7cf8, - 0x997777ee, - 0x8d7b7bf6, - 0x0df2f2ff, - 0xbd6b6bd6, - 0xb16f6fde, - 0x54c5c591, - 0x50303060, - 0x03010102, - 0xa96767ce, - 0x7d2b2b56, - 0x19fefee7, - 0x62d7d7b5, - 0xe6abab4d, - 0x9a7676ec, - 0x45caca8f, - 0x9d82821f, - 0x40c9c989, - 0x877d7dfa, - 0x15fafaef, - 0xeb5959b2, - 0xc947478e, - 0x0bf0f0fb, - 0xecadad41, - 0x67d4d4b3, - 0xfda2a25f, - 0xeaafaf45, - 0xbf9c9c23, - 0xf7a4a453, - 0x967272e4, - 0x5bc0c09b, - 0xc2b7b775, - 0x1cfdfde1, - 0xae93933d, - 0x6a26264c, - 0x5a36366c, - 0x413f3f7e, - 0x02f7f7f5, - 0x4fcccc83, - 0x5c343468, - 0xf4a5a551, - 0x34e5e5d1, - 0x08f1f1f9, - 0x937171e2, - 0x73d8d8ab, - 0x53313162, - 0x3f15152a, - 0x0c040408, - 0x52c7c795, - 0x65232346, - 0x5ec3c39d, - 0x28181830, - 0xa1969637, - 0x0f05050a, - 0xb59a9a2f, - 0x0907070e, - 0x36121224, - 0x9b80801b, - 0x3de2e2df, - 0x26ebebcd, - 0x6927274e, - 0xcdb2b27f, - 0x9f7575ea, - 0x1b090912, - 0x9e83831d, - 0x742c2c58, - 0x2e1a1a34, - 0x2d1b1b36, - 0xb26e6edc, - 0xee5a5ab4, - 0xfba0a05b, - 0xf65252a4, - 0x4d3b3b76, - 0x61d6d6b7, - 0xceb3b37d, - 0x7b292952, - 0x3ee3e3dd, - 0x712f2f5e, - 0x97848413, - 0xf55353a6, - 0x68d1d1b9, - 0x00000000, - 0x2cededc1, - 0x60202040, - 0x1ffcfce3, - 0xc8b1b179, - 0xed5b5bb6, - 0xbe6a6ad4, - 0x46cbcb8d, - 0xd9bebe67, - 0x4b393972, - 0xde4a4a94, - 0xd44c4c98, - 0xe85858b0, - 0x4acfcf85, - 0x6bd0d0bb, - 0x2aefefc5, - 0xe5aaaa4f, - 0x16fbfbed, - 0xc5434386, - 0xd74d4d9a, - 0x55333366, - 0x94858511, - 0xcf45458a, - 0x10f9f9e9, - 0x06020204, - 0x817f7ffe, - 0xf05050a0, - 0x443c3c78, - 0xba9f9f25, - 0xe3a8a84b, - 0xf35151a2, - 0xfea3a35d, - 0xc0404080, - 0x8a8f8f05, - 0xad92923f, - 0xbc9d9d21, - 0x48383870, - 0x04f5f5f1, - 0xdfbcbc63, - 0xc1b6b677, - 0x75dadaaf, - 0x63212142, - 0x30101020, - 0x1affffe5, - 0x0ef3f3fd, - 0x6dd2d2bf, - 0x4ccdcd81, - 0x140c0c18, - 0x35131326, - 0x2fececc3, - 0xe15f5fbe, - 0xa2979735, - 0xcc444488, - 0x3917172e, - 0x57c4c493, - 0xf2a7a755, - 0x827e7efc, - 0x473d3d7a, - 0xac6464c8, - 0xe75d5dba, - 0x2b191932, - 0x957373e6, - 0xa06060c0, - 0x98818119, - 0xd14f4f9e, - 0x7fdcdca3, - 0x66222244, - 0x7e2a2a54, - 0xab90903b, - 0x8388880b, - 0xca46468c, - 0x29eeeec7, - 0xd3b8b86b, - 0x3c141428, - 0x79dedea7, - 0xe25e5ebc, - 0x1d0b0b16, - 0x76dbdbad, - 0x3be0e0db, - 0x56323264, - 0x4e3a3a74, - 0x1e0a0a14, - 0xdb494992, - 0x0a06060c, - 0x6c242448, - 0xe45c5cb8, - 0x5dc2c29f, - 0x6ed3d3bd, - 0xefacac43, - 0xa66262c4, - 0xa8919139, - 0xa4959531, - 0x37e4e4d3, - 0x8b7979f2, - 0x32e7e7d5, - 0x43c8c88b, - 0x5937376e, - 0xb76d6dda, - 0x8c8d8d01, - 0x64d5d5b1, - 0xd24e4e9c, - 0xe0a9a949, - 0xb46c6cd8, - 0xfa5656ac, - 0x07f4f4f3, - 0x25eaeacf, - 0xaf6565ca, - 0x8e7a7af4, - 0xe9aeae47, - 0x18080810, - 0xd5baba6f, - 0x887878f0, - 0x6f25254a, - 0x722e2e5c, - 0x241c1c38, - 0xf1a6a657, - 0xc7b4b473, - 0x51c6c697, - 0x23e8e8cb, - 0x7cdddda1, - 0x9c7474e8, - 0x211f1f3e, - 0xdd4b4b96, - 0xdcbdbd61, - 0x868b8b0d, - 0x858a8a0f, - 0x907070e0, - 0x423e3e7c, - 0xc4b5b571, - 0xaa6666cc, - 0xd8484890, - 0x05030306, - 0x01f6f6f7, - 0x120e0e1c, - 0xa36161c2, - 0x5f35356a, - 0xf95757ae, - 0xd0b9b969, - 0x91868617, - 0x58c1c199, - 0x271d1d3a, - 0xb99e9e27, - 0x38e1e1d9, - 0x13f8f8eb, - 0xb398982b, - 0x33111122, - 0xbb6969d2, - 0x70d9d9a9, - 0x898e8e07, - 0xa7949433, - 0xb69b9b2d, - 0x221e1e3c, - 0x92878715, - 0x20e9e9c9, - 0x49cece87, - 0xff5555aa, - 0x78282850, - 0x7adfdfa5, - 0x8f8c8c03, - 0xf8a1a159, - 0x80898909, - 0x170d0d1a, - 0xdabfbf65, - 0x31e6e6d7, - 0xc6424284, - 0xb86868d0, - 0xc3414182, - 0xb0999929, - 0x772d2d5a, - 0x110f0f1e, - 0xcbb0b07b, - 0xfc5454a8, - 0xd6bbbb6d, - 0x3a16162c -]; - -final _t1 = [ - 0x6363c6a5, - 0x7c7cf884, - 0x7777ee99, - 0x7b7bf68d, - 0xf2f2ff0d, - 0x6b6bd6bd, - 0x6f6fdeb1, - 0xc5c59154, - 0x30306050, - 0x01010203, - 0x6767cea9, - 0x2b2b567d, - 0xfefee719, - 0xd7d7b562, - 0xabab4de6, - 0x7676ec9a, - 0xcaca8f45, - 0x82821f9d, - 0xc9c98940, - 0x7d7dfa87, - 0xfafaef15, - 0x5959b2eb, - 0x47478ec9, - 0xf0f0fb0b, - 0xadad41ec, - 0xd4d4b367, - 0xa2a25ffd, - 0xafaf45ea, - 0x9c9c23bf, - 0xa4a453f7, - 0x7272e496, - 0xc0c09b5b, - 0xb7b775c2, - 0xfdfde11c, - 0x93933dae, - 0x26264c6a, - 0x36366c5a, - 0x3f3f7e41, - 0xf7f7f502, - 0xcccc834f, - 0x3434685c, - 0xa5a551f4, - 0xe5e5d134, - 0xf1f1f908, - 0x7171e293, - 0xd8d8ab73, - 0x31316253, - 0x15152a3f, - 0x0404080c, - 0xc7c79552, - 0x23234665, - 0xc3c39d5e, - 0x18183028, - 0x969637a1, - 0x05050a0f, - 0x9a9a2fb5, - 0x07070e09, - 0x12122436, - 0x80801b9b, - 0xe2e2df3d, - 0xebebcd26, - 0x27274e69, - 0xb2b27fcd, - 0x7575ea9f, - 0x0909121b, - 0x83831d9e, - 0x2c2c5874, - 0x1a1a342e, - 0x1b1b362d, - 0x6e6edcb2, - 0x5a5ab4ee, - 0xa0a05bfb, - 0x5252a4f6, - 0x3b3b764d, - 0xd6d6b761, - 0xb3b37dce, - 0x2929527b, - 0xe3e3dd3e, - 0x2f2f5e71, - 0x84841397, - 0x5353a6f5, - 0xd1d1b968, - 0x00000000, - 0xededc12c, - 0x20204060, - 0xfcfce31f, - 0xb1b179c8, - 0x5b5bb6ed, - 0x6a6ad4be, - 0xcbcb8d46, - 0xbebe67d9, - 0x3939724b, - 0x4a4a94de, - 0x4c4c98d4, - 0x5858b0e8, - 0xcfcf854a, - 0xd0d0bb6b, - 0xefefc52a, - 0xaaaa4fe5, - 0xfbfbed16, - 0x434386c5, - 0x4d4d9ad7, - 0x33336655, - 0x85851194, - 0x45458acf, - 0xf9f9e910, - 0x02020406, - 0x7f7ffe81, - 0x5050a0f0, - 0x3c3c7844, - 0x9f9f25ba, - 0xa8a84be3, - 0x5151a2f3, - 0xa3a35dfe, - 0x404080c0, - 0x8f8f058a, - 0x92923fad, - 0x9d9d21bc, - 0x38387048, - 0xf5f5f104, - 0xbcbc63df, - 0xb6b677c1, - 0xdadaaf75, - 0x21214263, - 0x10102030, - 0xffffe51a, - 0xf3f3fd0e, - 0xd2d2bf6d, - 0xcdcd814c, - 0x0c0c1814, - 0x13132635, - 0xececc32f, - 0x5f5fbee1, - 0x979735a2, - 0x444488cc, - 0x17172e39, - 0xc4c49357, - 0xa7a755f2, - 0x7e7efc82, - 0x3d3d7a47, - 0x6464c8ac, - 0x5d5dbae7, - 0x1919322b, - 0x7373e695, - 0x6060c0a0, - 0x81811998, - 0x4f4f9ed1, - 0xdcdca37f, - 0x22224466, - 0x2a2a547e, - 0x90903bab, - 0x88880b83, - 0x46468cca, - 0xeeeec729, - 0xb8b86bd3, - 0x1414283c, - 0xdedea779, - 0x5e5ebce2, - 0x0b0b161d, - 0xdbdbad76, - 0xe0e0db3b, - 0x32326456, - 0x3a3a744e, - 0x0a0a141e, - 0x494992db, - 0x06060c0a, - 0x2424486c, - 0x5c5cb8e4, - 0xc2c29f5d, - 0xd3d3bd6e, - 0xacac43ef, - 0x6262c4a6, - 0x919139a8, - 0x959531a4, - 0xe4e4d337, - 0x7979f28b, - 0xe7e7d532, - 0xc8c88b43, - 0x37376e59, - 0x6d6ddab7, - 0x8d8d018c, - 0xd5d5b164, - 0x4e4e9cd2, - 0xa9a949e0, - 0x6c6cd8b4, - 0x5656acfa, - 0xf4f4f307, - 0xeaeacf25, - 0x6565caaf, - 0x7a7af48e, - 0xaeae47e9, - 0x08081018, - 0xbaba6fd5, - 0x7878f088, - 0x25254a6f, - 0x2e2e5c72, - 0x1c1c3824, - 0xa6a657f1, - 0xb4b473c7, - 0xc6c69751, - 0xe8e8cb23, - 0xdddda17c, - 0x7474e89c, - 0x1f1f3e21, - 0x4b4b96dd, - 0xbdbd61dc, - 0x8b8b0d86, - 0x8a8a0f85, - 0x7070e090, - 0x3e3e7c42, - 0xb5b571c4, - 0x6666ccaa, - 0x484890d8, - 0x03030605, - 0xf6f6f701, - 0x0e0e1c12, - 0x6161c2a3, - 0x35356a5f, - 0x5757aef9, - 0xb9b969d0, - 0x86861791, - 0xc1c19958, - 0x1d1d3a27, - 0x9e9e27b9, - 0xe1e1d938, - 0xf8f8eb13, - 0x98982bb3, - 0x11112233, - 0x6969d2bb, - 0xd9d9a970, - 0x8e8e0789, - 0x949433a7, - 0x9b9b2db6, - 0x1e1e3c22, - 0x87871592, - 0xe9e9c920, - 0xcece8749, - 0x5555aaff, - 0x28285078, - 0xdfdfa57a, - 0x8c8c038f, - 0xa1a159f8, - 0x89890980, - 0x0d0d1a17, - 0xbfbf65da, - 0xe6e6d731, - 0x424284c6, - 0x6868d0b8, - 0x414182c3, - 0x999929b0, - 0x2d2d5a77, - 0x0f0f1e11, - 0xb0b07bcb, - 0x5454a8fc, - 0xbbbb6dd6, - 0x16162c3a -]; - -final _t2 = [ - 0x63c6a563, - 0x7cf8847c, - 0x77ee9977, - 0x7bf68d7b, - 0xf2ff0df2, - 0x6bd6bd6b, - 0x6fdeb16f, - 0xc59154c5, - 0x30605030, - 0x01020301, - 0x67cea967, - 0x2b567d2b, - 0xfee719fe, - 0xd7b562d7, - 0xab4de6ab, - 0x76ec9a76, - 0xca8f45ca, - 0x821f9d82, - 0xc98940c9, - 0x7dfa877d, - 0xfaef15fa, - 0x59b2eb59, - 0x478ec947, - 0xf0fb0bf0, - 0xad41ecad, - 0xd4b367d4, - 0xa25ffda2, - 0xaf45eaaf, - 0x9c23bf9c, - 0xa453f7a4, - 0x72e49672, - 0xc09b5bc0, - 0xb775c2b7, - 0xfde11cfd, - 0x933dae93, - 0x264c6a26, - 0x366c5a36, - 0x3f7e413f, - 0xf7f502f7, - 0xcc834fcc, - 0x34685c34, - 0xa551f4a5, - 0xe5d134e5, - 0xf1f908f1, - 0x71e29371, - 0xd8ab73d8, - 0x31625331, - 0x152a3f15, - 0x04080c04, - 0xc79552c7, - 0x23466523, - 0xc39d5ec3, - 0x18302818, - 0x9637a196, - 0x050a0f05, - 0x9a2fb59a, - 0x070e0907, - 0x12243612, - 0x801b9b80, - 0xe2df3de2, - 0xebcd26eb, - 0x274e6927, - 0xb27fcdb2, - 0x75ea9f75, - 0x09121b09, - 0x831d9e83, - 0x2c58742c, - 0x1a342e1a, - 0x1b362d1b, - 0x6edcb26e, - 0x5ab4ee5a, - 0xa05bfba0, - 0x52a4f652, - 0x3b764d3b, - 0xd6b761d6, - 0xb37dceb3, - 0x29527b29, - 0xe3dd3ee3, - 0x2f5e712f, - 0x84139784, - 0x53a6f553, - 0xd1b968d1, - 0x00000000, - 0xedc12ced, - 0x20406020, - 0xfce31ffc, - 0xb179c8b1, - 0x5bb6ed5b, - 0x6ad4be6a, - 0xcb8d46cb, - 0xbe67d9be, - 0x39724b39, - 0x4a94de4a, - 0x4c98d44c, - 0x58b0e858, - 0xcf854acf, - 0xd0bb6bd0, - 0xefc52aef, - 0xaa4fe5aa, - 0xfbed16fb, - 0x4386c543, - 0x4d9ad74d, - 0x33665533, - 0x85119485, - 0x458acf45, - 0xf9e910f9, - 0x02040602, - 0x7ffe817f, - 0x50a0f050, - 0x3c78443c, - 0x9f25ba9f, - 0xa84be3a8, - 0x51a2f351, - 0xa35dfea3, - 0x4080c040, - 0x8f058a8f, - 0x923fad92, - 0x9d21bc9d, - 0x38704838, - 0xf5f104f5, - 0xbc63dfbc, - 0xb677c1b6, - 0xdaaf75da, - 0x21426321, - 0x10203010, - 0xffe51aff, - 0xf3fd0ef3, - 0xd2bf6dd2, - 0xcd814ccd, - 0x0c18140c, - 0x13263513, - 0xecc32fec, - 0x5fbee15f, - 0x9735a297, - 0x4488cc44, - 0x172e3917, - 0xc49357c4, - 0xa755f2a7, - 0x7efc827e, - 0x3d7a473d, - 0x64c8ac64, - 0x5dbae75d, - 0x19322b19, - 0x73e69573, - 0x60c0a060, - 0x81199881, - 0x4f9ed14f, - 0xdca37fdc, - 0x22446622, - 0x2a547e2a, - 0x903bab90, - 0x880b8388, - 0x468cca46, - 0xeec729ee, - 0xb86bd3b8, - 0x14283c14, - 0xdea779de, - 0x5ebce25e, - 0x0b161d0b, - 0xdbad76db, - 0xe0db3be0, - 0x32645632, - 0x3a744e3a, - 0x0a141e0a, - 0x4992db49, - 0x060c0a06, - 0x24486c24, - 0x5cb8e45c, - 0xc29f5dc2, - 0xd3bd6ed3, - 0xac43efac, - 0x62c4a662, - 0x9139a891, - 0x9531a495, - 0xe4d337e4, - 0x79f28b79, - 0xe7d532e7, - 0xc88b43c8, - 0x376e5937, - 0x6ddab76d, - 0x8d018c8d, - 0xd5b164d5, - 0x4e9cd24e, - 0xa949e0a9, - 0x6cd8b46c, - 0x56acfa56, - 0xf4f307f4, - 0xeacf25ea, - 0x65caaf65, - 0x7af48e7a, - 0xae47e9ae, - 0x08101808, - 0xba6fd5ba, - 0x78f08878, - 0x254a6f25, - 0x2e5c722e, - 0x1c38241c, - 0xa657f1a6, - 0xb473c7b4, - 0xc69751c6, - 0xe8cb23e8, - 0xdda17cdd, - 0x74e89c74, - 0x1f3e211f, - 0x4b96dd4b, - 0xbd61dcbd, - 0x8b0d868b, - 0x8a0f858a, - 0x70e09070, - 0x3e7c423e, - 0xb571c4b5, - 0x66ccaa66, - 0x4890d848, - 0x03060503, - 0xf6f701f6, - 0x0e1c120e, - 0x61c2a361, - 0x356a5f35, - 0x57aef957, - 0xb969d0b9, - 0x86179186, - 0xc19958c1, - 0x1d3a271d, - 0x9e27b99e, - 0xe1d938e1, - 0xf8eb13f8, - 0x982bb398, - 0x11223311, - 0x69d2bb69, - 0xd9a970d9, - 0x8e07898e, - 0x9433a794, - 0x9b2db69b, - 0x1e3c221e, - 0x87159287, - 0xe9c920e9, - 0xce8749ce, - 0x55aaff55, - 0x28507828, - 0xdfa57adf, - 0x8c038f8c, - 0xa159f8a1, - 0x89098089, - 0x0d1a170d, - 0xbf65dabf, - 0xe6d731e6, - 0x4284c642, - 0x68d0b868, - 0x4182c341, - 0x9929b099, - 0x2d5a772d, - 0x0f1e110f, - 0xb07bcbb0, - 0x54a8fc54, - 0xbb6dd6bb, - 0x162c3a16 -]; - -final _t3 = [ - 0xc6a56363, - 0xf8847c7c, - 0xee997777, - 0xf68d7b7b, - 0xff0df2f2, - 0xd6bd6b6b, - 0xdeb16f6f, - 0x9154c5c5, - 0x60503030, - 0x02030101, - 0xcea96767, - 0x567d2b2b, - 0xe719fefe, - 0xb562d7d7, - 0x4de6abab, - 0xec9a7676, - 0x8f45caca, - 0x1f9d8282, - 0x8940c9c9, - 0xfa877d7d, - 0xef15fafa, - 0xb2eb5959, - 0x8ec94747, - 0xfb0bf0f0, - 0x41ecadad, - 0xb367d4d4, - 0x5ffda2a2, - 0x45eaafaf, - 0x23bf9c9c, - 0x53f7a4a4, - 0xe4967272, - 0x9b5bc0c0, - 0x75c2b7b7, - 0xe11cfdfd, - 0x3dae9393, - 0x4c6a2626, - 0x6c5a3636, - 0x7e413f3f, - 0xf502f7f7, - 0x834fcccc, - 0x685c3434, - 0x51f4a5a5, - 0xd134e5e5, - 0xf908f1f1, - 0xe2937171, - 0xab73d8d8, - 0x62533131, - 0x2a3f1515, - 0x080c0404, - 0x9552c7c7, - 0x46652323, - 0x9d5ec3c3, - 0x30281818, - 0x37a19696, - 0x0a0f0505, - 0x2fb59a9a, - 0x0e090707, - 0x24361212, - 0x1b9b8080, - 0xdf3de2e2, - 0xcd26ebeb, - 0x4e692727, - 0x7fcdb2b2, - 0xea9f7575, - 0x121b0909, - 0x1d9e8383, - 0x58742c2c, - 0x342e1a1a, - 0x362d1b1b, - 0xdcb26e6e, - 0xb4ee5a5a, - 0x5bfba0a0, - 0xa4f65252, - 0x764d3b3b, - 0xb761d6d6, - 0x7dceb3b3, - 0x527b2929, - 0xdd3ee3e3, - 0x5e712f2f, - 0x13978484, - 0xa6f55353, - 0xb968d1d1, - 0x00000000, - 0xc12ceded, - 0x40602020, - 0xe31ffcfc, - 0x79c8b1b1, - 0xb6ed5b5b, - 0xd4be6a6a, - 0x8d46cbcb, - 0x67d9bebe, - 0x724b3939, - 0x94de4a4a, - 0x98d44c4c, - 0xb0e85858, - 0x854acfcf, - 0xbb6bd0d0, - 0xc52aefef, - 0x4fe5aaaa, - 0xed16fbfb, - 0x86c54343, - 0x9ad74d4d, - 0x66553333, - 0x11948585, - 0x8acf4545, - 0xe910f9f9, - 0x04060202, - 0xfe817f7f, - 0xa0f05050, - 0x78443c3c, - 0x25ba9f9f, - 0x4be3a8a8, - 0xa2f35151, - 0x5dfea3a3, - 0x80c04040, - 0x058a8f8f, - 0x3fad9292, - 0x21bc9d9d, - 0x70483838, - 0xf104f5f5, - 0x63dfbcbc, - 0x77c1b6b6, - 0xaf75dada, - 0x42632121, - 0x20301010, - 0xe51affff, - 0xfd0ef3f3, - 0xbf6dd2d2, - 0x814ccdcd, - 0x18140c0c, - 0x26351313, - 0xc32fecec, - 0xbee15f5f, - 0x35a29797, - 0x88cc4444, - 0x2e391717, - 0x9357c4c4, - 0x55f2a7a7, - 0xfc827e7e, - 0x7a473d3d, - 0xc8ac6464, - 0xbae75d5d, - 0x322b1919, - 0xe6957373, - 0xc0a06060, - 0x19988181, - 0x9ed14f4f, - 0xa37fdcdc, - 0x44662222, - 0x547e2a2a, - 0x3bab9090, - 0x0b838888, - 0x8cca4646, - 0xc729eeee, - 0x6bd3b8b8, - 0x283c1414, - 0xa779dede, - 0xbce25e5e, - 0x161d0b0b, - 0xad76dbdb, - 0xdb3be0e0, - 0x64563232, - 0x744e3a3a, - 0x141e0a0a, - 0x92db4949, - 0x0c0a0606, - 0x486c2424, - 0xb8e45c5c, - 0x9f5dc2c2, - 0xbd6ed3d3, - 0x43efacac, - 0xc4a66262, - 0x39a89191, - 0x31a49595, - 0xd337e4e4, - 0xf28b7979, - 0xd532e7e7, - 0x8b43c8c8, - 0x6e593737, - 0xdab76d6d, - 0x018c8d8d, - 0xb164d5d5, - 0x9cd24e4e, - 0x49e0a9a9, - 0xd8b46c6c, - 0xacfa5656, - 0xf307f4f4, - 0xcf25eaea, - 0xcaaf6565, - 0xf48e7a7a, - 0x47e9aeae, - 0x10180808, - 0x6fd5baba, - 0xf0887878, - 0x4a6f2525, - 0x5c722e2e, - 0x38241c1c, - 0x57f1a6a6, - 0x73c7b4b4, - 0x9751c6c6, - 0xcb23e8e8, - 0xa17cdddd, - 0xe89c7474, - 0x3e211f1f, - 0x96dd4b4b, - 0x61dcbdbd, - 0x0d868b8b, - 0x0f858a8a, - 0xe0907070, - 0x7c423e3e, - 0x71c4b5b5, - 0xccaa6666, - 0x90d84848, - 0x06050303, - 0xf701f6f6, - 0x1c120e0e, - 0xc2a36161, - 0x6a5f3535, - 0xaef95757, - 0x69d0b9b9, - 0x17918686, - 0x9958c1c1, - 0x3a271d1d, - 0x27b99e9e, - 0xd938e1e1, - 0xeb13f8f8, - 0x2bb39898, - 0x22331111, - 0xd2bb6969, - 0xa970d9d9, - 0x07898e8e, - 0x33a79494, - 0x2db69b9b, - 0x3c221e1e, - 0x15928787, - 0xc920e9e9, - 0x8749cece, - 0xaaff5555, - 0x50782828, - 0xa57adfdf, - 0x038f8c8c, - 0x59f8a1a1, - 0x09808989, - 0x1a170d0d, - 0x65dabfbf, - 0xd731e6e6, - 0x84c64242, - 0xd0b86868, - 0x82c34141, - 0x29b09999, - 0x5a772d2d, - 0x1e110f0f, - 0x7bcbb0b0, - 0xa8fc5454, - 0x6dd6bbbb, - 0x2c3a1616 -]; - -final _tinv0 = [ - 0x50a7f451, - 0x5365417e, - 0xc3a4171a, - 0x965e273a, - 0xcb6bab3b, - 0xf1459d1f, - 0xab58faac, - 0x9303e34b, - 0x55fa3020, - 0xf66d76ad, - 0x9176cc88, - 0x254c02f5, - 0xfcd7e54f, - 0xd7cb2ac5, - 0x80443526, - 0x8fa362b5, - 0x495ab1de, - 0x671bba25, - 0x980eea45, - 0xe1c0fe5d, - 0x02752fc3, - 0x12f04c81, - 0xa397468d, - 0xc6f9d36b, - 0xe75f8f03, - 0x959c9215, - 0xeb7a6dbf, - 0xda595295, - 0x2d83bed4, - 0xd3217458, - 0x2969e049, - 0x44c8c98e, - 0x6a89c275, - 0x78798ef4, - 0x6b3e5899, - 0xdd71b927, - 0xb64fe1be, - 0x17ad88f0, - 0x66ac20c9, - 0xb43ace7d, - 0x184adf63, - 0x82311ae5, - 0x60335197, - 0x457f5362, - 0xe07764b1, - 0x84ae6bbb, - 0x1ca081fe, - 0x942b08f9, - 0x58684870, - 0x19fd458f, - 0x876cde94, - 0xb7f87b52, - 0x23d373ab, - 0xe2024b72, - 0x578f1fe3, - 0x2aab5566, - 0x0728ebb2, - 0x03c2b52f, - 0x9a7bc586, - 0xa50837d3, - 0xf2872830, - 0xb2a5bf23, - 0xba6a0302, - 0x5c8216ed, - 0x2b1ccf8a, - 0x92b479a7, - 0xf0f207f3, - 0xa1e2694e, - 0xcdf4da65, - 0xd5be0506, - 0x1f6234d1, - 0x8afea6c4, - 0x9d532e34, - 0xa055f3a2, - 0x32e18a05, - 0x75ebf6a4, - 0x39ec830b, - 0xaaef6040, - 0x069f715e, - 0x51106ebd, - 0xf98a213e, - 0x3d06dd96, - 0xae053edd, - 0x46bde64d, - 0xb58d5491, - 0x055dc471, - 0x6fd40604, - 0xff155060, - 0x24fb9819, - 0x97e9bdd6, - 0xcc434089, - 0x779ed967, - 0xbd42e8b0, - 0x888b8907, - 0x385b19e7, - 0xdbeec879, - 0x470a7ca1, - 0xe90f427c, - 0xc91e84f8, - 0x00000000, - 0x83868009, - 0x48ed2b32, - 0xac70111e, - 0x4e725a6c, - 0xfbff0efd, - 0x5638850f, - 0x1ed5ae3d, - 0x27392d36, - 0x64d90f0a, - 0x21a65c68, - 0xd1545b9b, - 0x3a2e3624, - 0xb1670a0c, - 0x0fe75793, - 0xd296eeb4, - 0x9e919b1b, - 0x4fc5c080, - 0xa220dc61, - 0x694b775a, - 0x161a121c, - 0x0aba93e2, - 0xe52aa0c0, - 0x43e0223c, - 0x1d171b12, - 0x0b0d090e, - 0xadc78bf2, - 0xb9a8b62d, - 0xc8a91e14, - 0x8519f157, - 0x4c0775af, - 0xbbdd99ee, - 0xfd607fa3, - 0x9f2601f7, - 0xbcf5725c, - 0xc53b6644, - 0x347efb5b, - 0x7629438b, - 0xdcc623cb, - 0x68fcedb6, - 0x63f1e4b8, - 0xcadc31d7, - 0x10856342, - 0x40229713, - 0x2011c684, - 0x7d244a85, - 0xf83dbbd2, - 0x1132f9ae, - 0x6da129c7, - 0x4b2f9e1d, - 0xf330b2dc, - 0xec52860d, - 0xd0e3c177, - 0x6c16b32b, - 0x99b970a9, - 0xfa489411, - 0x2264e947, - 0xc48cfca8, - 0x1a3ff0a0, - 0xd82c7d56, - 0xef903322, - 0xc74e4987, - 0xc1d138d9, - 0xfea2ca8c, - 0x360bd498, - 0xcf81f5a6, - 0x28de7aa5, - 0x268eb7da, - 0xa4bfad3f, - 0xe49d3a2c, - 0x0d927850, - 0x9bcc5f6a, - 0x62467e54, - 0xc2138df6, - 0xe8b8d890, - 0x5ef7392e, - 0xf5afc382, - 0xbe805d9f, - 0x7c93d069, - 0xa92dd56f, - 0xb31225cf, - 0x3b99acc8, - 0xa77d1810, - 0x6e639ce8, - 0x7bbb3bdb, - 0x097826cd, - 0xf418596e, - 0x01b79aec, - 0xa89a4f83, - 0x656e95e6, - 0x7ee6ffaa, - 0x08cfbc21, - 0xe6e815ef, - 0xd99be7ba, - 0xce366f4a, - 0xd4099fea, - 0xd67cb029, - 0xafb2a431, - 0x31233f2a, - 0x3094a5c6, - 0xc066a235, - 0x37bc4e74, - 0xa6ca82fc, - 0xb0d090e0, - 0x15d8a733, - 0x4a9804f1, - 0xf7daec41, - 0x0e50cd7f, - 0x2ff69117, - 0x8dd64d76, - 0x4db0ef43, - 0x544daacc, - 0xdf0496e4, - 0xe3b5d19e, - 0x1b886a4c, - 0xb81f2cc1, - 0x7f516546, - 0x04ea5e9d, - 0x5d358c01, - 0x737487fa, - 0x2e410bfb, - 0x5a1d67b3, - 0x52d2db92, - 0x335610e9, - 0x1347d66d, - 0x8c61d79a, - 0x7a0ca137, - 0x8e14f859, - 0x893c13eb, - 0xee27a9ce, - 0x35c961b7, - 0xede51ce1, - 0x3cb1477a, - 0x59dfd29c, - 0x3f73f255, - 0x79ce1418, - 0xbf37c773, - 0xeacdf753, - 0x5baafd5f, - 0x146f3ddf, - 0x86db4478, - 0x81f3afca, - 0x3ec468b9, - 0x2c342438, - 0x5f40a3c2, - 0x72c31d16, - 0x0c25e2bc, - 0x8b493c28, - 0x41950dff, - 0x7101a839, - 0xdeb30c08, - 0x9ce4b4d8, - 0x90c15664, - 0x6184cb7b, - 0x70b632d5, - 0x745c6c48, - 0x4257b8d0 -]; - -final _tinv1 = [ - 0xa7f45150, - 0x65417e53, - 0xa4171ac3, - 0x5e273a96, - 0x6bab3bcb, - 0x459d1ff1, - 0x58faacab, - 0x03e34b93, - 0xfa302055, - 0x6d76adf6, - 0x76cc8891, - 0x4c02f525, - 0xd7e54ffc, - 0xcb2ac5d7, - 0x44352680, - 0xa362b58f, - 0x5ab1de49, - 0x1bba2567, - 0x0eea4598, - 0xc0fe5de1, - 0x752fc302, - 0xf04c8112, - 0x97468da3, - 0xf9d36bc6, - 0x5f8f03e7, - 0x9c921595, - 0x7a6dbfeb, - 0x595295da, - 0x83bed42d, - 0x217458d3, - 0x69e04929, - 0xc8c98e44, - 0x89c2756a, - 0x798ef478, - 0x3e58996b, - 0x71b927dd, - 0x4fe1beb6, - 0xad88f017, - 0xac20c966, - 0x3ace7db4, - 0x4adf6318, - 0x311ae582, - 0x33519760, - 0x7f536245, - 0x7764b1e0, - 0xae6bbb84, - 0xa081fe1c, - 0x2b08f994, - 0x68487058, - 0xfd458f19, - 0x6cde9487, - 0xf87b52b7, - 0xd373ab23, - 0x024b72e2, - 0x8f1fe357, - 0xab55662a, - 0x28ebb207, - 0xc2b52f03, - 0x7bc5869a, - 0x0837d3a5, - 0x872830f2, - 0xa5bf23b2, - 0x6a0302ba, - 0x8216ed5c, - 0x1ccf8a2b, - 0xb479a792, - 0xf207f3f0, - 0xe2694ea1, - 0xf4da65cd, - 0xbe0506d5, - 0x6234d11f, - 0xfea6c48a, - 0x532e349d, - 0x55f3a2a0, - 0xe18a0532, - 0xebf6a475, - 0xec830b39, - 0xef6040aa, - 0x9f715e06, - 0x106ebd51, - 0x8a213ef9, - 0x06dd963d, - 0x053eddae, - 0xbde64d46, - 0x8d5491b5, - 0x5dc47105, - 0xd406046f, - 0x155060ff, - 0xfb981924, - 0xe9bdd697, - 0x434089cc, - 0x9ed96777, - 0x42e8b0bd, - 0x8b890788, - 0x5b19e738, - 0xeec879db, - 0x0a7ca147, - 0x0f427ce9, - 0x1e84f8c9, - 0x00000000, - 0x86800983, - 0xed2b3248, - 0x70111eac, - 0x725a6c4e, - 0xff0efdfb, - 0x38850f56, - 0xd5ae3d1e, - 0x392d3627, - 0xd90f0a64, - 0xa65c6821, - 0x545b9bd1, - 0x2e36243a, - 0x670a0cb1, - 0xe757930f, - 0x96eeb4d2, - 0x919b1b9e, - 0xc5c0804f, - 0x20dc61a2, - 0x4b775a69, - 0x1a121c16, - 0xba93e20a, - 0x2aa0c0e5, - 0xe0223c43, - 0x171b121d, - 0x0d090e0b, - 0xc78bf2ad, - 0xa8b62db9, - 0xa91e14c8, - 0x19f15785, - 0x0775af4c, - 0xdd99eebb, - 0x607fa3fd, - 0x2601f79f, - 0xf5725cbc, - 0x3b6644c5, - 0x7efb5b34, - 0x29438b76, - 0xc623cbdc, - 0xfcedb668, - 0xf1e4b863, - 0xdc31d7ca, - 0x85634210, - 0x22971340, - 0x11c68420, - 0x244a857d, - 0x3dbbd2f8, - 0x32f9ae11, - 0xa129c76d, - 0x2f9e1d4b, - 0x30b2dcf3, - 0x52860dec, - 0xe3c177d0, - 0x16b32b6c, - 0xb970a999, - 0x489411fa, - 0x64e94722, - 0x8cfca8c4, - 0x3ff0a01a, - 0x2c7d56d8, - 0x903322ef, - 0x4e4987c7, - 0xd138d9c1, - 0xa2ca8cfe, - 0x0bd49836, - 0x81f5a6cf, - 0xde7aa528, - 0x8eb7da26, - 0xbfad3fa4, - 0x9d3a2ce4, - 0x9278500d, - 0xcc5f6a9b, - 0x467e5462, - 0x138df6c2, - 0xb8d890e8, - 0xf7392e5e, - 0xafc382f5, - 0x805d9fbe, - 0x93d0697c, - 0x2dd56fa9, - 0x1225cfb3, - 0x99acc83b, - 0x7d1810a7, - 0x639ce86e, - 0xbb3bdb7b, - 0x7826cd09, - 0x18596ef4, - 0xb79aec01, - 0x9a4f83a8, - 0x6e95e665, - 0xe6ffaa7e, - 0xcfbc2108, - 0xe815efe6, - 0x9be7bad9, - 0x366f4ace, - 0x099fead4, - 0x7cb029d6, - 0xb2a431af, - 0x233f2a31, - 0x94a5c630, - 0x66a235c0, - 0xbc4e7437, - 0xca82fca6, - 0xd090e0b0, - 0xd8a73315, - 0x9804f14a, - 0xdaec41f7, - 0x50cd7f0e, - 0xf691172f, - 0xd64d768d, - 0xb0ef434d, - 0x4daacc54, - 0x0496e4df, - 0xb5d19ee3, - 0x886a4c1b, - 0x1f2cc1b8, - 0x5165467f, - 0xea5e9d04, - 0x358c015d, - 0x7487fa73, - 0x410bfb2e, - 0x1d67b35a, - 0xd2db9252, - 0x5610e933, - 0x47d66d13, - 0x61d79a8c, - 0x0ca1377a, - 0x14f8598e, - 0x3c13eb89, - 0x27a9ceee, - 0xc961b735, - 0xe51ce1ed, - 0xb1477a3c, - 0xdfd29c59, - 0x73f2553f, - 0xce141879, - 0x37c773bf, - 0xcdf753ea, - 0xaafd5f5b, - 0x6f3ddf14, - 0xdb447886, - 0xf3afca81, - 0xc468b93e, - 0x3424382c, - 0x40a3c25f, - 0xc31d1672, - 0x25e2bc0c, - 0x493c288b, - 0x950dff41, - 0x01a83971, - 0xb30c08de, - 0xe4b4d89c, - 0xc1566490, - 0x84cb7b61, - 0xb632d570, - 0x5c6c4874, - 0x57b8d042 -]; - -final _tinv2 = [ - 0xf45150a7, - 0x417e5365, - 0x171ac3a4, - 0x273a965e, - 0xab3bcb6b, - 0x9d1ff145, - 0xfaacab58, - 0xe34b9303, - 0x302055fa, - 0x76adf66d, - 0xcc889176, - 0x02f5254c, - 0xe54ffcd7, - 0x2ac5d7cb, - 0x35268044, - 0x62b58fa3, - 0xb1de495a, - 0xba25671b, - 0xea45980e, - 0xfe5de1c0, - 0x2fc30275, - 0x4c8112f0, - 0x468da397, - 0xd36bc6f9, - 0x8f03e75f, - 0x9215959c, - 0x6dbfeb7a, - 0x5295da59, - 0xbed42d83, - 0x7458d321, - 0xe0492969, - 0xc98e44c8, - 0xc2756a89, - 0x8ef47879, - 0x58996b3e, - 0xb927dd71, - 0xe1beb64f, - 0x88f017ad, - 0x20c966ac, - 0xce7db43a, - 0xdf63184a, - 0x1ae58231, - 0x51976033, - 0x5362457f, - 0x64b1e077, - 0x6bbb84ae, - 0x81fe1ca0, - 0x08f9942b, - 0x48705868, - 0x458f19fd, - 0xde94876c, - 0x7b52b7f8, - 0x73ab23d3, - 0x4b72e202, - 0x1fe3578f, - 0x55662aab, - 0xebb20728, - 0xb52f03c2, - 0xc5869a7b, - 0x37d3a508, - 0x2830f287, - 0xbf23b2a5, - 0x0302ba6a, - 0x16ed5c82, - 0xcf8a2b1c, - 0x79a792b4, - 0x07f3f0f2, - 0x694ea1e2, - 0xda65cdf4, - 0x0506d5be, - 0x34d11f62, - 0xa6c48afe, - 0x2e349d53, - 0xf3a2a055, - 0x8a0532e1, - 0xf6a475eb, - 0x830b39ec, - 0x6040aaef, - 0x715e069f, - 0x6ebd5110, - 0x213ef98a, - 0xdd963d06, - 0x3eddae05, - 0xe64d46bd, - 0x5491b58d, - 0xc471055d, - 0x06046fd4, - 0x5060ff15, - 0x981924fb, - 0xbdd697e9, - 0x4089cc43, - 0xd967779e, - 0xe8b0bd42, - 0x8907888b, - 0x19e7385b, - 0xc879dbee, - 0x7ca1470a, - 0x427ce90f, - 0x84f8c91e, - 0x00000000, - 0x80098386, - 0x2b3248ed, - 0x111eac70, - 0x5a6c4e72, - 0x0efdfbff, - 0x850f5638, - 0xae3d1ed5, - 0x2d362739, - 0x0f0a64d9, - 0x5c6821a6, - 0x5b9bd154, - 0x36243a2e, - 0x0a0cb167, - 0x57930fe7, - 0xeeb4d296, - 0x9b1b9e91, - 0xc0804fc5, - 0xdc61a220, - 0x775a694b, - 0x121c161a, - 0x93e20aba, - 0xa0c0e52a, - 0x223c43e0, - 0x1b121d17, - 0x090e0b0d, - 0x8bf2adc7, - 0xb62db9a8, - 0x1e14c8a9, - 0xf1578519, - 0x75af4c07, - 0x99eebbdd, - 0x7fa3fd60, - 0x01f79f26, - 0x725cbcf5, - 0x6644c53b, - 0xfb5b347e, - 0x438b7629, - 0x23cbdcc6, - 0xedb668fc, - 0xe4b863f1, - 0x31d7cadc, - 0x63421085, - 0x97134022, - 0xc6842011, - 0x4a857d24, - 0xbbd2f83d, - 0xf9ae1132, - 0x29c76da1, - 0x9e1d4b2f, - 0xb2dcf330, - 0x860dec52, - 0xc177d0e3, - 0xb32b6c16, - 0x70a999b9, - 0x9411fa48, - 0xe9472264, - 0xfca8c48c, - 0xf0a01a3f, - 0x7d56d82c, - 0x3322ef90, - 0x4987c74e, - 0x38d9c1d1, - 0xca8cfea2, - 0xd498360b, - 0xf5a6cf81, - 0x7aa528de, - 0xb7da268e, - 0xad3fa4bf, - 0x3a2ce49d, - 0x78500d92, - 0x5f6a9bcc, - 0x7e546246, - 0x8df6c213, - 0xd890e8b8, - 0x392e5ef7, - 0xc382f5af, - 0x5d9fbe80, - 0xd0697c93, - 0xd56fa92d, - 0x25cfb312, - 0xacc83b99, - 0x1810a77d, - 0x9ce86e63, - 0x3bdb7bbb, - 0x26cd0978, - 0x596ef418, - 0x9aec01b7, - 0x4f83a89a, - 0x95e6656e, - 0xffaa7ee6, - 0xbc2108cf, - 0x15efe6e8, - 0xe7bad99b, - 0x6f4ace36, - 0x9fead409, - 0xb029d67c, - 0xa431afb2, - 0x3f2a3123, - 0xa5c63094, - 0xa235c066, - 0x4e7437bc, - 0x82fca6ca, - 0x90e0b0d0, - 0xa73315d8, - 0x04f14a98, - 0xec41f7da, - 0xcd7f0e50, - 0x91172ff6, - 0x4d768dd6, - 0xef434db0, - 0xaacc544d, - 0x96e4df04, - 0xd19ee3b5, - 0x6a4c1b88, - 0x2cc1b81f, - 0x65467f51, - 0x5e9d04ea, - 0x8c015d35, - 0x87fa7374, - 0x0bfb2e41, - 0x67b35a1d, - 0xdb9252d2, - 0x10e93356, - 0xd66d1347, - 0xd79a8c61, - 0xa1377a0c, - 0xf8598e14, - 0x13eb893c, - 0xa9ceee27, - 0x61b735c9, - 0x1ce1ede5, - 0x477a3cb1, - 0xd29c59df, - 0xf2553f73, - 0x141879ce, - 0xc773bf37, - 0xf753eacd, - 0xfd5f5baa, - 0x3ddf146f, - 0x447886db, - 0xafca81f3, - 0x68b93ec4, - 0x24382c34, - 0xa3c25f40, - 0x1d1672c3, - 0xe2bc0c25, - 0x3c288b49, - 0x0dff4195, - 0xa8397101, - 0x0c08deb3, - 0xb4d89ce4, - 0x566490c1, - 0xcb7b6184, - 0x32d570b6, - 0x6c48745c, - 0xb8d04257 -]; - -final _tinv3 = [ - 0x5150a7f4, - 0x7e536541, - 0x1ac3a417, - 0x3a965e27, - 0x3bcb6bab, - 0x1ff1459d, - 0xacab58fa, - 0x4b9303e3, - 0x2055fa30, - 0xadf66d76, - 0x889176cc, - 0xf5254c02, - 0x4ffcd7e5, - 0xc5d7cb2a, - 0x26804435, - 0xb58fa362, - 0xde495ab1, - 0x25671bba, - 0x45980eea, - 0x5de1c0fe, - 0xc302752f, - 0x8112f04c, - 0x8da39746, - 0x6bc6f9d3, - 0x03e75f8f, - 0x15959c92, - 0xbfeb7a6d, - 0x95da5952, - 0xd42d83be, - 0x58d32174, - 0x492969e0, - 0x8e44c8c9, - 0x756a89c2, - 0xf478798e, - 0x996b3e58, - 0x27dd71b9, - 0xbeb64fe1, - 0xf017ad88, - 0xc966ac20, - 0x7db43ace, - 0x63184adf, - 0xe582311a, - 0x97603351, - 0x62457f53, - 0xb1e07764, - 0xbb84ae6b, - 0xfe1ca081, - 0xf9942b08, - 0x70586848, - 0x8f19fd45, - 0x94876cde, - 0x52b7f87b, - 0xab23d373, - 0x72e2024b, - 0xe3578f1f, - 0x662aab55, - 0xb20728eb, - 0x2f03c2b5, - 0x869a7bc5, - 0xd3a50837, - 0x30f28728, - 0x23b2a5bf, - 0x02ba6a03, - 0xed5c8216, - 0x8a2b1ccf, - 0xa792b479, - 0xf3f0f207, - 0x4ea1e269, - 0x65cdf4da, - 0x06d5be05, - 0xd11f6234, - 0xc48afea6, - 0x349d532e, - 0xa2a055f3, - 0x0532e18a, - 0xa475ebf6, - 0x0b39ec83, - 0x40aaef60, - 0x5e069f71, - 0xbd51106e, - 0x3ef98a21, - 0x963d06dd, - 0xddae053e, - 0x4d46bde6, - 0x91b58d54, - 0x71055dc4, - 0x046fd406, - 0x60ff1550, - 0x1924fb98, - 0xd697e9bd, - 0x89cc4340, - 0x67779ed9, - 0xb0bd42e8, - 0x07888b89, - 0xe7385b19, - 0x79dbeec8, - 0xa1470a7c, - 0x7ce90f42, - 0xf8c91e84, - 0x00000000, - 0x09838680, - 0x3248ed2b, - 0x1eac7011, - 0x6c4e725a, - 0xfdfbff0e, - 0x0f563885, - 0x3d1ed5ae, - 0x3627392d, - 0x0a64d90f, - 0x6821a65c, - 0x9bd1545b, - 0x243a2e36, - 0x0cb1670a, - 0x930fe757, - 0xb4d296ee, - 0x1b9e919b, - 0x804fc5c0, - 0x61a220dc, - 0x5a694b77, - 0x1c161a12, - 0xe20aba93, - 0xc0e52aa0, - 0x3c43e022, - 0x121d171b, - 0x0e0b0d09, - 0xf2adc78b, - 0x2db9a8b6, - 0x14c8a91e, - 0x578519f1, - 0xaf4c0775, - 0xeebbdd99, - 0xa3fd607f, - 0xf79f2601, - 0x5cbcf572, - 0x44c53b66, - 0x5b347efb, - 0x8b762943, - 0xcbdcc623, - 0xb668fced, - 0xb863f1e4, - 0xd7cadc31, - 0x42108563, - 0x13402297, - 0x842011c6, - 0x857d244a, - 0xd2f83dbb, - 0xae1132f9, - 0xc76da129, - 0x1d4b2f9e, - 0xdcf330b2, - 0x0dec5286, - 0x77d0e3c1, - 0x2b6c16b3, - 0xa999b970, - 0x11fa4894, - 0x472264e9, - 0xa8c48cfc, - 0xa01a3ff0, - 0x56d82c7d, - 0x22ef9033, - 0x87c74e49, - 0xd9c1d138, - 0x8cfea2ca, - 0x98360bd4, - 0xa6cf81f5, - 0xa528de7a, - 0xda268eb7, - 0x3fa4bfad, - 0x2ce49d3a, - 0x500d9278, - 0x6a9bcc5f, - 0x5462467e, - 0xf6c2138d, - 0x90e8b8d8, - 0x2e5ef739, - 0x82f5afc3, - 0x9fbe805d, - 0x697c93d0, - 0x6fa92dd5, - 0xcfb31225, - 0xc83b99ac, - 0x10a77d18, - 0xe86e639c, - 0xdb7bbb3b, - 0xcd097826, - 0x6ef41859, - 0xec01b79a, - 0x83a89a4f, - 0xe6656e95, - 0xaa7ee6ff, - 0x2108cfbc, - 0xefe6e815, - 0xbad99be7, - 0x4ace366f, - 0xead4099f, - 0x29d67cb0, - 0x31afb2a4, - 0x2a31233f, - 0xc63094a5, - 0x35c066a2, - 0x7437bc4e, - 0xfca6ca82, - 0xe0b0d090, - 0x3315d8a7, - 0xf14a9804, - 0x41f7daec, - 0x7f0e50cd, - 0x172ff691, - 0x768dd64d, - 0x434db0ef, - 0xcc544daa, - 0xe4df0496, - 0x9ee3b5d1, - 0x4c1b886a, - 0xc1b81f2c, - 0x467f5165, - 0x9d04ea5e, - 0x015d358c, - 0xfa737487, - 0xfb2e410b, - 0xb35a1d67, - 0x9252d2db, - 0xe9335610, - 0x6d1347d6, - 0x9a8c61d7, - 0x377a0ca1, - 0x598e14f8, - 0xeb893c13, - 0xceee27a9, - 0xb735c961, - 0xe1ede51c, - 0x7a3cb147, - 0x9c59dfd2, - 0x553f73f2, - 0x1879ce14, - 0x73bf37c7, - 0x53eacdf7, - 0x5f5baafd, - 0xdf146f3d, - 0x7886db44, - 0xca81f3af, - 0xb93ec468, - 0x382c3424, - 0xc25f40a3, - 0x1672c31d, - 0xbc0c25e2, - 0x288b493c, - 0xff41950d, - 0x397101a8, - 0x08deb30c, - 0xd89ce4b4, - 0x6490c156, - 0x7b6184cb, - 0xd570b632, - 0x48745c6c, - 0xd04257b8 -]; diff --git a/pointycastle/lib/block/blowfish.dart b/pointycastle/lib/block/blowfish.dart deleted file mode 100644 index 0f1dc30..0000000 --- a/pointycastle/lib/block/blowfish.dart +++ /dev/null @@ -1,466 +0,0 @@ -// See file LICENSE for more information. - -library impl.block_cipher.blowfish; - -import 'dart:core'; -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_block_cipher.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// A class that provides Blowfish key encryption operations, -/// such as encoding data and generating keys. -/// Author Nguyen Van Nguyen -class BlowfishEngine extends BaseBlockCipher { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - BlockCipher, - 'Blowfish', - () => BlowfishEngine(), - ); - - static const _kp = [ - 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, // 0 - 3 - 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, - 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, - 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, - 0x9216d5d9, 0x8979fb1b - ]; - - static const _sBox0 = [ - 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, // 0 - 3 - 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, - 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, - 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, - 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, - 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, - 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, - 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, - 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, - 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, - 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, - 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, - 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, - 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, - 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, - 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, - 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, - 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, - 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, - 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, - 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, - 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, - 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, - 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, - 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, - 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, - 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, - 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, - 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, - 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, - 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, - 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, - 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, - 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, - 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, - 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, - 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, - 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, - 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, - 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, - 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, - 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, - 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, - 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, - 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, - 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, - 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, - 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, - 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, - 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, - 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, - 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, - 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, - 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, - 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, - 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, - 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, - 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, - 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, - 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, - 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, - 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, - 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, - 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a - ]; - - static const _sBox1 = [ - 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, // 0 - 3 - 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, - 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, - 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, - 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, - 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, - 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, - 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, - 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, - 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, - 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, - 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, - 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, - 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, - 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, - 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, - 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, - 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, - 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, - 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, - 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, - 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, - 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, - 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, - 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, - 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, - 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, - 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, - 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, - 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, - 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, - 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, - 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, - 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, - 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, - 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, - 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, - 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, - 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, - 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, - 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, - 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, - 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, - 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, - 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, - 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, - 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, - 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, - 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, - 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, - 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, - 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, - 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, - 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, - 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, - 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, - 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, - 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, - 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, - 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, - 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, - 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, - 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, - 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 - ]; - - static const _sBox2 = [ - 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, // 0 - 3 - 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, - 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, - 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, - 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, - 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, - 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, - 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, - 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, - 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, - 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, - 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, - 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, - 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, - 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, - 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, - 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, - 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, - 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, - 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, - 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, - 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, - 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, - 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, - 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, - 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, - 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, - 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, - 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, - 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, - 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, - 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, - 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, - 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, - 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, - 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, - 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, - 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, - 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, - 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, - 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, - 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, - 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, - 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, - 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, - 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, - 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, - 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, - 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, - 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, - 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, - 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, - 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, - 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, - 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, - 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, - 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, - 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, - 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, - 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, - 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, - 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, - 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, - 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 - ]; - - static const _sBox3 = [ - 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, // 0 - 3 - 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, - 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, - 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, - 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, - 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, - 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, - 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, - 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, - 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, - 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, - 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, - 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, - 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, - 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, - 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, - 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, - 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, - 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, - 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, - 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, - 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, - 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, - 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, - 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, - 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, - 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, - 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, - 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, - 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, - 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, - 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, - 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, - 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, - 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, - 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, - 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, - 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, - 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, - 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, - 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, - 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, - 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, - 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, - 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, - 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, - 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, - 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, - 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, - 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, - 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, - 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, - 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, - 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, - 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, - 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, - 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, - 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, - 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, - 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, - 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, - 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, - 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, - 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 - ]; - - static const _rounds = 16; - static const _sBoxSK = 256; - static const _pSZ = _rounds + 2; - - static const BLOCK_SIZE = 8; - - bool _forEncryption = false; - - late Uint8List _workingKey; - - /// the s-boxes - final _s0 = List.filled(_sBoxSK, 0); - final _s1 = List.filled(_sBoxSK, 0); - final _s2 = List.filled(_sBoxSK, 0); - final _s3 = List.filled(_sBoxSK, 0); - - /// the p-array - final _p = List.filled(_pSZ, 0); - - @override - String get algorithmName => 'Blowfish'; - - @override - int get blockSize => BLOCK_SIZE; - - @override - void reset() {} - - @override - void init(final bool forEncryption, final CipherParameters? params) { - if (params is KeyParameter) { - _forEncryption = forEncryption; - _workingKey = params.key; - _setKey(_workingKey); - } else { - throw ArgumentError( - 'Invalid parameter passed to $algorithmName init - ${params.runtimeType}', - ); - } - } - - @override - int processBlock( - final Uint8List input, - final int inOff, - final Uint8List output, - final int outOff, - ) { - if (_workingKey.isEmpty) { - throw StateError('$algorithmName not initialised'); - } - if ((inOff + BLOCK_SIZE) > input.lengthInBytes) { - throw ArgumentError('Input buffer too short for $algorithmName engine'); - } - if ((outOff + BLOCK_SIZE) > output.lengthInBytes) { - throw ArgumentError('Output buffer too short for $algorithmName engine'); - } - - if (_forEncryption) { - _encryptBlock(input, inOff, output, outOff); - } else { - _decryptBlock(input, inOff, output, outOff); - } - - return BLOCK_SIZE; - } - - int _f(final int x) { - return ((_s0[(x >> 24) & 0xff] + _s1[(x >> 16) & 0xff]) ^ - _s2[(x >> 8) & 0xff]) + - _s3[x & 0xff]; - } - - /// apply the encryption cycle to each value pair in the table. - void _processTable(int xl, int xr, final List table) { - final size = table.length; - for (var s = 0; s < size; s += 2) { - xl ^= _p[0]; - for (var i = 1; i < _rounds; i += 2) { - xr ^= _f(xl) ^ _p[i]; - xl ^= _f(xr) ^ _p[i + 1]; - } - xr ^= _p[_rounds + 1]; - table[s] = xr; - table[s + 1] = xl; - - /// end of cycle swap - xr = xl; - xl = table[s]; - } - } - - void _setKey(final Uint8List key) { - if (key.length < 4 || key.length > 56) { - throw ArgumentError('Key length must be in range 32 to 448 bits'); - } - _s0.setAll(0, _sBox0.sublist(0, _sBoxSK)); - _s1.setAll(0, _sBox1.sublist(0, _sBoxSK)); - _s2.setAll(0, _sBox2.sublist(0, _sBoxSK)); - _s3.setAll(0, _sBox3.sublist(0, _sBoxSK)); - - _p.setAll(0, _kp.sublist(0, _pSZ)); - - final keyLength = key.length; - var keyIndex = 0; - - for (var i = 0; i < _pSZ; i++) { - var data = 0x0000000; - for (var j = 0; j < 4; j++) { - data = (data << 8) | key[keyIndex++]; - if (keyIndex >= keyLength) { - keyIndex = 0; - } - } - _p[i] ^= data; - } - - _processTable(0, 0, _p); - _processTable(_p[_pSZ - 2], _p[_pSZ - 1], _s0); - _processTable(_s0[_sBoxSK - 2], _s0[_sBoxSK - 1], _s1); - _processTable(_s1[_sBoxSK - 2], _s1[_sBoxSK - 1], _s2); - _processTable(_s2[_sBoxSK - 2], _s2[_sBoxSK - 1], _s3); - } - - void _encryptBlock( - final Uint8List src, - final int srcIndex, - final Uint8List dst, - final int dstIndex, - ) { - var xl = src.sublist(srcIndex).buffer.asByteData().getInt32(0); - var xr = src.sublist(srcIndex + 4).buffer.asByteData().getInt32(0); - - xl ^= _p[0]; - - for (var i = 1; i < _rounds; i += 2) { - xr ^= _f(xl) ^ _p[i]; - xl ^= _f(xr) ^ _p[i + 1]; - } - xr ^= _p[_rounds + 1]; - - dst.setAll(dstIndex, _pack32(xr)); - dst.setAll(dstIndex + 4, _pack32(xl)); - } - - void _decryptBlock( - final Uint8List src, - final int srcIndex, - final Uint8List dst, - final int dstIndex, - ) { - var xl = src.sublist(srcIndex).buffer.asByteData().getInt32(0); - var xr = src.sublist(srcIndex + 4).buffer.asByteData().getInt32(0); - - xl ^= _p[_rounds + 1]; - - for (var i = _rounds; i > 0; i -= 2) { - xr ^= _f(xl) ^ _p[i]; - xl ^= _f(xr) ^ _p[i - 1]; - } - - xr ^= _p[0]; - dst.setAll(dstIndex, _pack32(xr)); - dst.setAll(dstIndex + 4, _pack32(xl)); - } - - static Uint8List _pack32(int x) => - Uint8List(4)..buffer.asByteData().setInt32(0, x); -} diff --git a/pointycastle/lib/block/camellia.dart b/pointycastle/lib/block/camellia.dart deleted file mode 100644 index 08e6a89..0000000 --- a/pointycastle/lib/block/camellia.dart +++ /dev/null @@ -1,698 +0,0 @@ -// See file LICENSE for more information. - -library impl.block_cipher.camellia; - -import 'dart:typed_data'; - -import 'dart:core'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_block_cipher.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// Camellia - based on RFC 3713. -/// Author Nguyen Van Nguyen -class CamelliaEngine extends BaseBlockCipher { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - BlockCipher, - 'Camellia', - () => CamelliaEngine(), - ); - - static const BLOCK_SIZE = 16; - - static const _mask8 = 0xff; - - static const _mask32 = 0xffffffff; - - static const _sigma = [ - 0xa09e667f, 0x3bcc908b, 0xb67ae858, 0x4caa73b2, // 0 - 3 - 0xc6ef372f, 0xe94f82be, 0x54ff53a5, 0xf1d36f1c, - 0x10e527fa, 0xde682d1d, 0xb05688c2, 0xb3e6c1fd - ]; - - //// The first camellia sbox - static const _sbox1_1110 = [ - 0x70707000, 0x82828200, 0x2c2c2c00, 0xececec00, 0xb3b3b300, - 0x27272700, // 0 - 5 - 0xc0c0c000, 0xe5e5e500, 0xe4e4e400, 0x85858500, 0x57575700, 0x35353500, - 0xeaeaea00, 0x0c0c0c00, 0xaeaeae00, 0x41414100, 0x23232300, 0xefefef00, - 0x6b6b6b00, 0x93939300, 0x45454500, 0x19191900, 0xa5a5a500, 0x21212100, - 0xededed00, 0x0e0e0e00, 0x4f4f4f00, 0x4e4e4e00, 0x1d1d1d00, 0x65656500, - 0x92929200, 0xbdbdbd00, 0x86868600, 0xb8b8b800, 0xafafaf00, 0x8f8f8f00, - 0x7c7c7c00, 0xebebeb00, 0x1f1f1f00, 0xcecece00, 0x3e3e3e00, 0x30303000, - 0xdcdcdc00, 0x5f5f5f00, 0x5e5e5e00, 0xc5c5c500, 0x0b0b0b00, 0x1a1a1a00, - 0xa6a6a600, 0xe1e1e100, 0x39393900, 0xcacaca00, 0xd5d5d500, 0x47474700, - 0x5d5d5d00, 0x3d3d3d00, 0xd9d9d900, 0x01010100, 0x5a5a5a00, 0xd6d6d600, - 0x51515100, 0x56565600, 0x6c6c6c00, 0x4d4d4d00, 0x8b8b8b00, 0x0d0d0d00, - 0x9a9a9a00, 0x66666600, 0xfbfbfb00, 0xcccccc00, 0xb0b0b000, 0x2d2d2d00, - 0x74747400, 0x12121200, 0x2b2b2b00, 0x20202000, 0xf0f0f000, 0xb1b1b100, - 0x84848400, 0x99999900, 0xdfdfdf00, 0x4c4c4c00, 0xcbcbcb00, 0xc2c2c200, - 0x34343400, 0x7e7e7e00, 0x76767600, 0x05050500, 0x6d6d6d00, 0xb7b7b700, - 0xa9a9a900, 0x31313100, 0xd1d1d100, 0x17171700, 0x04040400, 0xd7d7d700, - 0x14141400, 0x58585800, 0x3a3a3a00, 0x61616100, 0xdedede00, 0x1b1b1b00, - 0x11111100, 0x1c1c1c00, 0x32323200, 0x0f0f0f00, 0x9c9c9c00, 0x16161600, - 0x53535300, 0x18181800, 0xf2f2f200, 0x22222200, 0xfefefe00, 0x44444400, - 0xcfcfcf00, 0xb2b2b200, 0xc3c3c300, 0xb5b5b500, 0x7a7a7a00, 0x91919100, - 0x24242400, 0x08080800, 0xe8e8e800, 0xa8a8a800, 0x60606000, 0xfcfcfc00, - 0x69696900, 0x50505000, 0xaaaaaa00, 0xd0d0d000, 0xa0a0a000, 0x7d7d7d00, - 0xa1a1a100, 0x89898900, 0x62626200, 0x97979700, 0x54545400, 0x5b5b5b00, - 0x1e1e1e00, 0x95959500, 0xe0e0e000, 0xffffff00, 0x64646400, 0xd2d2d200, - 0x10101000, 0xc4c4c400, 0x00000000, 0x48484800, 0xa3a3a300, 0xf7f7f700, - 0x75757500, 0xdbdbdb00, 0x8a8a8a00, 0x03030300, 0xe6e6e600, 0xdadada00, - 0x09090900, 0x3f3f3f00, 0xdddddd00, 0x94949400, 0x87878700, 0x5c5c5c00, - 0x83838300, 0x02020200, 0xcdcdcd00, 0x4a4a4a00, 0x90909000, 0x33333300, - 0x73737300, 0x67676700, 0xf6f6f600, 0xf3f3f300, 0x9d9d9d00, 0x7f7f7f00, - 0xbfbfbf00, 0xe2e2e200, 0x52525200, 0x9b9b9b00, 0xd8d8d800, 0x26262600, - 0xc8c8c800, 0x37373700, 0xc6c6c600, 0x3b3b3b00, 0x81818100, 0x96969600, - 0x6f6f6f00, 0x4b4b4b00, 0x13131300, 0xbebebe00, 0x63636300, 0x2e2e2e00, - 0xe9e9e900, 0x79797900, 0xa7a7a700, 0x8c8c8c00, 0x9f9f9f00, 0x6e6e6e00, - 0xbcbcbc00, 0x8e8e8e00, 0x29292900, 0xf5f5f500, 0xf9f9f900, 0xb6b6b600, - 0x2f2f2f00, 0xfdfdfd00, 0xb4b4b400, 0x59595900, 0x78787800, 0x98989800, - 0x06060600, 0x6a6a6a00, 0xe7e7e700, 0x46464600, 0x71717100, 0xbababa00, - 0xd4d4d400, 0x25252500, 0xababab00, 0x42424200, 0x88888800, 0xa2a2a200, - 0x8d8d8d00, 0xfafafa00, 0x72727200, 0x07070700, 0xb9b9b900, 0x55555500, - 0xf8f8f800, 0xeeeeee00, 0xacacac00, 0x0a0a0a00, 0x36363600, 0x49494900, - 0x2a2a2a00, 0x68686800, 0x3c3c3c00, 0x38383800, 0xf1f1f100, 0xa4a4a400, - 0x40404000, 0x28282800, 0xd3d3d300, 0x7b7b7b00, 0xbbbbbb00, 0xc9c9c900, - 0x43434300, 0xc1c1c100, 0x15151500, 0xe3e3e300, 0xadadad00, 0xf4f4f400, - 0x77777700, 0xc7c7c700, 0x80808000, 0x9e9e9e00 - ]; - - /// The second camellia sbox - static const _sbox2_0222 = [ - 0x00e0e0e0, 0x00050505, 0x00585858, 0x00d9d9d9, 0x00676767, - 0x004e4e4e, // 0 - 5 - 0x00818181, 0x00cbcbcb, 0x00c9c9c9, 0x000b0b0b, 0x00aeaeae, 0x006a6a6a, - 0x00d5d5d5, 0x00181818, 0x005d5d5d, 0x00828282, 0x00464646, 0x00dfdfdf, - 0x00d6d6d6, 0x00272727, 0x008a8a8a, 0x00323232, 0x004b4b4b, 0x00424242, - 0x00dbdbdb, 0x001c1c1c, 0x009e9e9e, 0x009c9c9c, 0x003a3a3a, 0x00cacaca, - 0x00252525, 0x007b7b7b, 0x000d0d0d, 0x00717171, 0x005f5f5f, 0x001f1f1f, - 0x00f8f8f8, 0x00d7d7d7, 0x003e3e3e, 0x009d9d9d, 0x007c7c7c, 0x00606060, - 0x00b9b9b9, 0x00bebebe, 0x00bcbcbc, 0x008b8b8b, 0x00161616, 0x00343434, - 0x004d4d4d, 0x00c3c3c3, 0x00727272, 0x00959595, 0x00ababab, 0x008e8e8e, - 0x00bababa, 0x007a7a7a, 0x00b3b3b3, 0x00020202, 0x00b4b4b4, 0x00adadad, - 0x00a2a2a2, 0x00acacac, 0x00d8d8d8, 0x009a9a9a, 0x00171717, 0x001a1a1a, - 0x00353535, 0x00cccccc, 0x00f7f7f7, 0x00999999, 0x00616161, 0x005a5a5a, - 0x00e8e8e8, 0x00242424, 0x00565656, 0x00404040, 0x00e1e1e1, 0x00636363, - 0x00090909, 0x00333333, 0x00bfbfbf, 0x00989898, 0x00979797, 0x00858585, - 0x00686868, 0x00fcfcfc, 0x00ececec, 0x000a0a0a, 0x00dadada, 0x006f6f6f, - 0x00535353, 0x00626262, 0x00a3a3a3, 0x002e2e2e, 0x00080808, 0x00afafaf, - 0x00282828, 0x00b0b0b0, 0x00747474, 0x00c2c2c2, 0x00bdbdbd, 0x00363636, - 0x00222222, 0x00383838, 0x00646464, 0x001e1e1e, 0x00393939, 0x002c2c2c, - 0x00a6a6a6, 0x00303030, 0x00e5e5e5, 0x00444444, 0x00fdfdfd, 0x00888888, - 0x009f9f9f, 0x00656565, 0x00878787, 0x006b6b6b, 0x00f4f4f4, 0x00232323, - 0x00484848, 0x00101010, 0x00d1d1d1, 0x00515151, 0x00c0c0c0, 0x00f9f9f9, - 0x00d2d2d2, 0x00a0a0a0, 0x00555555, 0x00a1a1a1, 0x00414141, 0x00fafafa, - 0x00434343, 0x00131313, 0x00c4c4c4, 0x002f2f2f, 0x00a8a8a8, 0x00b6b6b6, - 0x003c3c3c, 0x002b2b2b, 0x00c1c1c1, 0x00ffffff, 0x00c8c8c8, 0x00a5a5a5, - 0x00202020, 0x00898989, 0x00000000, 0x00909090, 0x00474747, 0x00efefef, - 0x00eaeaea, 0x00b7b7b7, 0x00151515, 0x00060606, 0x00cdcdcd, 0x00b5b5b5, - 0x00121212, 0x007e7e7e, 0x00bbbbbb, 0x00292929, 0x000f0f0f, 0x00b8b8b8, - 0x00070707, 0x00040404, 0x009b9b9b, 0x00949494, 0x00212121, 0x00666666, - 0x00e6e6e6, 0x00cecece, 0x00ededed, 0x00e7e7e7, 0x003b3b3b, 0x00fefefe, - 0x007f7f7f, 0x00c5c5c5, 0x00a4a4a4, 0x00373737, 0x00b1b1b1, 0x004c4c4c, - 0x00919191, 0x006e6e6e, 0x008d8d8d, 0x00767676, 0x00030303, 0x002d2d2d, - 0x00dedede, 0x00969696, 0x00262626, 0x007d7d7d, 0x00c6c6c6, 0x005c5c5c, - 0x00d3d3d3, 0x00f2f2f2, 0x004f4f4f, 0x00191919, 0x003f3f3f, 0x00dcdcdc, - 0x00797979, 0x001d1d1d, 0x00525252, 0x00ebebeb, 0x00f3f3f3, 0x006d6d6d, - 0x005e5e5e, 0x00fbfbfb, 0x00696969, 0x00b2b2b2, 0x00f0f0f0, 0x00313131, - 0x000c0c0c, 0x00d4d4d4, 0x00cfcfcf, 0x008c8c8c, 0x00e2e2e2, 0x00757575, - 0x00a9a9a9, 0x004a4a4a, 0x00575757, 0x00848484, 0x00111111, 0x00454545, - 0x001b1b1b, 0x00f5f5f5, 0x00e4e4e4, 0x000e0e0e, 0x00737373, 0x00aaaaaa, - 0x00f1f1f1, 0x00dddddd, 0x00595959, 0x00141414, 0x006c6c6c, 0x00929292, - 0x00545454, 0x00d0d0d0, 0x00787878, 0x00707070, 0x00e3e3e3, 0x00494949, - 0x00808080, 0x00505050, 0x00a7a7a7, 0x00f6f6f6, 0x00777777, 0x00939393, - 0x00868686, 0x00838383, 0x002a2a2a, 0x00c7c7c7, 0x005b5b5b, 0x00e9e9e9, - 0x00eeeeee, 0x008f8f8f, 0x00010101, 0x003d3d3d - ]; - - /// The third camellia sbox - static const _sbox3_3033 = [ - 0x38003838, 0x41004141, 0x16001616, 0x76007676, 0xd900d9d9, - 0x93009393, // 0 - 5 - 0x60006060, 0xf200f2f2, 0x72007272, 0xc200c2c2, 0xab00abab, 0x9a009a9a, - 0x75007575, 0x06000606, 0x57005757, 0xa000a0a0, 0x91009191, 0xf700f7f7, - 0xb500b5b5, 0xc900c9c9, 0xa200a2a2, 0x8c008c8c, 0xd200d2d2, 0x90009090, - 0xf600f6f6, 0x07000707, 0xa700a7a7, 0x27002727, 0x8e008e8e, 0xb200b2b2, - 0x49004949, 0xde00dede, 0x43004343, 0x5c005c5c, 0xd700d7d7, 0xc700c7c7, - 0x3e003e3e, 0xf500f5f5, 0x8f008f8f, 0x67006767, 0x1f001f1f, 0x18001818, - 0x6e006e6e, 0xaf00afaf, 0x2f002f2f, 0xe200e2e2, 0x85008585, 0x0d000d0d, - 0x53005353, 0xf000f0f0, 0x9c009c9c, 0x65006565, 0xea00eaea, 0xa300a3a3, - 0xae00aeae, 0x9e009e9e, 0xec00ecec, 0x80008080, 0x2d002d2d, 0x6b006b6b, - 0xa800a8a8, 0x2b002b2b, 0x36003636, 0xa600a6a6, 0xc500c5c5, 0x86008686, - 0x4d004d4d, 0x33003333, 0xfd00fdfd, 0x66006666, 0x58005858, 0x96009696, - 0x3a003a3a, 0x09000909, 0x95009595, 0x10001010, 0x78007878, 0xd800d8d8, - 0x42004242, 0xcc00cccc, 0xef00efef, 0x26002626, 0xe500e5e5, 0x61006161, - 0x1a001a1a, 0x3f003f3f, 0x3b003b3b, 0x82008282, 0xb600b6b6, 0xdb00dbdb, - 0xd400d4d4, 0x98009898, 0xe800e8e8, 0x8b008b8b, 0x02000202, 0xeb00ebeb, - 0x0a000a0a, 0x2c002c2c, 0x1d001d1d, 0xb000b0b0, 0x6f006f6f, 0x8d008d8d, - 0x88008888, 0x0e000e0e, 0x19001919, 0x87008787, 0x4e004e4e, 0x0b000b0b, - 0xa900a9a9, 0x0c000c0c, 0x79007979, 0x11001111, 0x7f007f7f, 0x22002222, - 0xe700e7e7, 0x59005959, 0xe100e1e1, 0xda00dada, 0x3d003d3d, 0xc800c8c8, - 0x12001212, 0x04000404, 0x74007474, 0x54005454, 0x30003030, 0x7e007e7e, - 0xb400b4b4, 0x28002828, 0x55005555, 0x68006868, 0x50005050, 0xbe00bebe, - 0xd000d0d0, 0xc400c4c4, 0x31003131, 0xcb00cbcb, 0x2a002a2a, 0xad00adad, - 0x0f000f0f, 0xca00caca, 0x70007070, 0xff00ffff, 0x32003232, 0x69006969, - 0x08000808, 0x62006262, 0x00000000, 0x24002424, 0xd100d1d1, 0xfb00fbfb, - 0xba00baba, 0xed00eded, 0x45004545, 0x81008181, 0x73007373, 0x6d006d6d, - 0x84008484, 0x9f009f9f, 0xee00eeee, 0x4a004a4a, 0xc300c3c3, 0x2e002e2e, - 0xc100c1c1, 0x01000101, 0xe600e6e6, 0x25002525, 0x48004848, 0x99009999, - 0xb900b9b9, 0xb300b3b3, 0x7b007b7b, 0xf900f9f9, 0xce00cece, 0xbf00bfbf, - 0xdf00dfdf, 0x71007171, 0x29002929, 0xcd00cdcd, 0x6c006c6c, 0x13001313, - 0x64006464, 0x9b009b9b, 0x63006363, 0x9d009d9d, 0xc000c0c0, 0x4b004b4b, - 0xb700b7b7, 0xa500a5a5, 0x89008989, 0x5f005f5f, 0xb100b1b1, 0x17001717, - 0xf400f4f4, 0xbc00bcbc, 0xd300d3d3, 0x46004646, 0xcf00cfcf, 0x37003737, - 0x5e005e5e, 0x47004747, 0x94009494, 0xfa00fafa, 0xfc00fcfc, 0x5b005b5b, - 0x97009797, 0xfe00fefe, 0x5a005a5a, 0xac00acac, 0x3c003c3c, 0x4c004c4c, - 0x03000303, 0x35003535, 0xf300f3f3, 0x23002323, 0xb800b8b8, 0x5d005d5d, - 0x6a006a6a, 0x92009292, 0xd500d5d5, 0x21002121, 0x44004444, 0x51005151, - 0xc600c6c6, 0x7d007d7d, 0x39003939, 0x83008383, 0xdc00dcdc, 0xaa00aaaa, - 0x7c007c7c, 0x77007777, 0x56005656, 0x05000505, 0x1b001b1b, 0xa400a4a4, - 0x15001515, 0x34003434, 0x1e001e1e, 0x1c001c1c, 0xf800f8f8, 0x52005252, - 0x20002020, 0x14001414, 0xe900e9e9, 0xbd00bdbd, 0xdd00dddd, 0xe400e4e4, - 0xa100a1a1, 0xe000e0e0, 0x8a008a8a, 0xf100f1f1, 0xd600d6d6, 0x7a007a7a, - 0xbb00bbbb, 0xe300e3e3, 0x40004040, 0x4f004f4f - ]; - - /// The fourth camellia sbox - static const _sbox4_4404 = [ - 0x70700070, 0x2c2c002c, 0xb3b300b3, 0xc0c000c0, 0xe4e400e4, - 0x57570057, // 0 - 5 - 0xeaea00ea, 0xaeae00ae, 0x23230023, 0x6b6b006b, 0x45450045, 0xa5a500a5, - 0xeded00ed, 0x4f4f004f, 0x1d1d001d, 0x92920092, 0x86860086, 0xafaf00af, - 0x7c7c007c, 0x1f1f001f, 0x3e3e003e, 0xdcdc00dc, 0x5e5e005e, 0x0b0b000b, - 0xa6a600a6, 0x39390039, 0xd5d500d5, 0x5d5d005d, 0xd9d900d9, 0x5a5a005a, - 0x51510051, 0x6c6c006c, 0x8b8b008b, 0x9a9a009a, 0xfbfb00fb, 0xb0b000b0, - 0x74740074, 0x2b2b002b, 0xf0f000f0, 0x84840084, 0xdfdf00df, 0xcbcb00cb, - 0x34340034, 0x76760076, 0x6d6d006d, 0xa9a900a9, 0xd1d100d1, 0x04040004, - 0x14140014, 0x3a3a003a, 0xdede00de, 0x11110011, 0x32320032, 0x9c9c009c, - 0x53530053, 0xf2f200f2, 0xfefe00fe, 0xcfcf00cf, 0xc3c300c3, 0x7a7a007a, - 0x24240024, 0xe8e800e8, 0x60600060, 0x69690069, 0xaaaa00aa, 0xa0a000a0, - 0xa1a100a1, 0x62620062, 0x54540054, 0x1e1e001e, 0xe0e000e0, 0x64640064, - 0x10100010, 0x00000000, 0xa3a300a3, 0x75750075, 0x8a8a008a, 0xe6e600e6, - 0x09090009, 0xdddd00dd, 0x87870087, 0x83830083, 0xcdcd00cd, 0x90900090, - 0x73730073, 0xf6f600f6, 0x9d9d009d, 0xbfbf00bf, 0x52520052, 0xd8d800d8, - 0xc8c800c8, 0xc6c600c6, 0x81810081, 0x6f6f006f, 0x13130013, 0x63630063, - 0xe9e900e9, 0xa7a700a7, 0x9f9f009f, 0xbcbc00bc, 0x29290029, 0xf9f900f9, - 0x2f2f002f, 0xb4b400b4, 0x78780078, 0x06060006, 0xe7e700e7, 0x71710071, - 0xd4d400d4, 0xabab00ab, 0x88880088, 0x8d8d008d, 0x72720072, 0xb9b900b9, - 0xf8f800f8, 0xacac00ac, 0x36360036, 0x2a2a002a, 0x3c3c003c, 0xf1f100f1, - 0x40400040, 0xd3d300d3, 0xbbbb00bb, 0x43430043, 0x15150015, 0xadad00ad, - 0x77770077, 0x80800080, 0x82820082, 0xecec00ec, 0x27270027, 0xe5e500e5, - 0x85850085, 0x35350035, 0x0c0c000c, 0x41410041, 0xefef00ef, 0x93930093, - 0x19190019, 0x21210021, 0x0e0e000e, 0x4e4e004e, 0x65650065, 0xbdbd00bd, - 0xb8b800b8, 0x8f8f008f, 0xebeb00eb, 0xcece00ce, 0x30300030, 0x5f5f005f, - 0xc5c500c5, 0x1a1a001a, 0xe1e100e1, 0xcaca00ca, 0x47470047, 0x3d3d003d, - 0x01010001, 0xd6d600d6, 0x56560056, 0x4d4d004d, 0x0d0d000d, 0x66660066, - 0xcccc00cc, 0x2d2d002d, 0x12120012, 0x20200020, 0xb1b100b1, 0x99990099, - 0x4c4c004c, 0xc2c200c2, 0x7e7e007e, 0x05050005, 0xb7b700b7, 0x31310031, - 0x17170017, 0xd7d700d7, 0x58580058, 0x61610061, 0x1b1b001b, 0x1c1c001c, - 0x0f0f000f, 0x16160016, 0x18180018, 0x22220022, 0x44440044, 0xb2b200b2, - 0xb5b500b5, 0x91910091, 0x08080008, 0xa8a800a8, 0xfcfc00fc, 0x50500050, - 0xd0d000d0, 0x7d7d007d, 0x89890089, 0x97970097, 0x5b5b005b, 0x95950095, - 0xffff00ff, 0xd2d200d2, 0xc4c400c4, 0x48480048, 0xf7f700f7, 0xdbdb00db, - 0x03030003, 0xdada00da, 0x3f3f003f, 0x94940094, 0x5c5c005c, 0x02020002, - 0x4a4a004a, 0x33330033, 0x67670067, 0xf3f300f3, 0x7f7f007f, 0xe2e200e2, - 0x9b9b009b, 0x26260026, 0x37370037, 0x3b3b003b, 0x96960096, 0x4b4b004b, - 0xbebe00be, 0x2e2e002e, 0x79790079, 0x8c8c008c, 0x6e6e006e, 0x8e8e008e, - 0xf5f500f5, 0xb6b600b6, 0xfdfd00fd, 0x59590059, 0x98980098, 0x6a6a006a, - 0x46460046, 0xbaba00ba, 0x25250025, 0x42420042, 0xa2a200a2, 0xfafa00fa, - 0x07070007, 0x55550055, 0xeeee00ee, 0x0a0a000a, 0x49490049, 0x68680068, - 0x38380038, 0xa4a400a4, 0x28280028, 0x7b7b007b, 0xc9c900c9, 0xc1c100c1, - 0xe3e300e3, 0xf4f400f4, 0xc7c700c7, 0x9e9e009e - ]; - - bool initialised = false; - - late bool _keyIs128; - - final _subkey = List.filled(24 * 4, 0); - - /// for whitening - final _kw = List.filled(4 * 2, 0); - - /// for FL and FL^(-1) - final _ke = List.filled(6 * 2, 0); - - /// for encryption and decryption - final _state = List.filled(4, 0); - - @override - String get algorithmName => 'Camellia'; - - @override - int get blockSize => BLOCK_SIZE; - - @override - void init(bool forEncryption, CipherParameters? params) { - if (params is! KeyParameter) { - throw Exception('Only simple KeyParameter expected.'); - } - - _setKey(forEncryption, params.key); - - initialised = true; - } - - @override - int processBlock( - Uint8List input, - int inOff, - Uint8List output, - int outOff, - ) { - if (!initialised) { - throw Exception('$algorithmName engine not initialised'); - } - - if ((inOff + BLOCK_SIZE) > input.length) { - throw Exception('Input buffer too short'); - } - if ((outOff + BLOCK_SIZE) > output.length) { - throw Exception('Output buffer too short'); - } - if (_keyIs128) { - return _processBlock128(input, inOff, output, outOff); - } else { - return _processBlock256(input, inOff, output, outOff); - } - } - - @override - void reset() {} - - static void _roldq( - int rot, - List ki, - int inOff, - List ko, - int outOff, - ) { - ko[outOff] = - _shiftLeft32(ki[inOff], rot) | _shiftRight32(ki[1 + inOff], 32 - rot); - ko[1 + outOff] = _shiftLeft32(ki[1 + inOff], rot) | - _shiftRight32(ki[2 + inOff], 32 - rot); - ko[2 + outOff] = _shiftLeft32(ki[2 + inOff], rot) | - _shiftRight32(ki[3 + inOff], 32 - rot); - ko[3 + outOff] = - _shiftLeft32(ki[3 + inOff], rot) | _shiftRight32(ki[inOff], 32 - rot); - ki[inOff] = ko[outOff]; - ki[1 + inOff] = ko[1 + outOff]; - ki[2 + inOff] = ko[2 + outOff]; - ki[3 + inOff] = ko[3 + outOff]; - } - - static void _decroldq( - int rot, - List ki, - int inOff, - List ko, - int outOff, - ) { - ko[2 + outOff] = - _shiftLeft32(ki[inOff], rot) | _shiftRight32(ki[1 + inOff], 32 - rot); - ko[3 + outOff] = _shiftLeft32(ki[1 + inOff], rot) | - _shiftRight32(ki[2 + inOff], 32 - rot); - ko[outOff] = _shiftLeft32(ki[2 + inOff], rot) | - _shiftRight32(ki[3 + inOff], 32 - rot); - ko[1 + outOff] = - _shiftLeft32(ki[3 + inOff], rot) | _shiftRight32(ki[inOff], 32 - rot); - ki[inOff] = ko[2 + outOff]; - ki[1 + inOff] = ko[3 + outOff]; - ki[2 + inOff] = ko[outOff]; - ki[3 + inOff] = ko[1 + outOff]; - } - - static void _roldqo32( - int rot, - List ki, - int inOff, - List ko, - int outOff, - ) { - ko[outOff] = _shiftLeft32(ki[1 + inOff], rot - 32) | - _shiftRight32(ki[2 + inOff], 64 - rot); - ko[1 + outOff] = _shiftLeft32(ki[2 + inOff], rot - 32) | - _shiftRight32(ki[3 + inOff], 64 - rot); - ko[2 + outOff] = _shiftLeft32(ki[3 + inOff], rot - 32) | - _shiftRight32(ki[inOff], 64 - rot); - ko[3 + outOff] = _shiftLeft32(ki[inOff], rot - 32) | - _shiftRight32(ki[1 + inOff], 64 - rot); - ki[inOff] = ko[outOff]; - ki[1 + inOff] = ko[1 + outOff]; - ki[2 + inOff] = ko[2 + outOff]; - ki[3 + inOff] = ko[3 + outOff]; - } - - static void _decroldqo32( - int rot, - List ki, - int inOff, - List ko, - int outOff, - ) { - ko[2 + outOff] = _shiftLeft32(ki[1 + inOff], rot - 32) | - _shiftRight32(ki[2 + inOff], 64 - rot); - ko[3 + outOff] = _shiftLeft32(ki[2 + inOff], rot - 32) | - _shiftRight32(ki[3 + inOff], 64 - rot); - ko[outOff] = _shiftLeft32(ki[3 + inOff], rot - 32) | - _shiftRight32(ki[inOff], 64 - rot); - ko[1 + outOff] = _shiftLeft32(ki[inOff], rot - 32) | - _shiftRight32(ki[1 + inOff], 64 - rot); - ki[inOff] = ko[2 + outOff]; - ki[1 + inOff] = ko[3 + outOff]; - ki[2 + inOff] = ko[outOff]; - ki[3 + inOff] = ko[1 + outOff]; - } - - static int _bytes2uint(Uint8List src, int offset) { - return _unpack32(src.sublist(offset, offset + 4)); - } - - static void _uint2bytes(int word, Uint8List dst, int offset) { - dst.setRange(offset, offset + 4, _pack32(word.toUnsigned(32))); - } - - static void _camelliaF2(List s, List skey, int keyoff) { - var t1 = s[0] ^ skey[keyoff]; - var u = _sbox4_4404[t1 & _mask8]; - u ^= _sbox3_3033[(t1 >> 8) & _mask8]; - u ^= _sbox2_0222[(t1 >> 16) & _mask8]; - u ^= _sbox1_1110[(t1 >> 24) & _mask8]; - - var t2 = s[1] ^ skey[1 + keyoff]; - var v = _sbox1_1110[t2 & _mask8]; - v ^= _sbox4_4404[(t2 >> 8) & _mask8]; - v ^= _sbox3_3033[(t2 >> 16) & _mask8]; - v ^= _sbox2_0222[(t2 >> 24) & _mask8]; - - s[2] ^= u ^ v; - s[3] ^= u ^ v ^ _rotateRight32(u, 8); - - t1 = s[2] ^ skey[2 + keyoff]; - u = _sbox4_4404[t1 & _mask8]; - u ^= _sbox3_3033[(t1 >> 8) & _mask8]; - u ^= _sbox2_0222[(t1 >> 16) & _mask8]; - u ^= _sbox1_1110[(t1 >> 24) & _mask8]; - t2 = s[3] ^ skey[3 + keyoff]; - v = _sbox1_1110[t2 & _mask8]; - v ^= _sbox4_4404[(t2 >> 8) & _mask8]; - v ^= _sbox3_3033[(t2 >> 16) & _mask8]; - v ^= _sbox2_0222[(t2 >> 24) & _mask8]; - - s[0] ^= u ^ v; - s[1] ^= u ^ v ^ _rotateRight32(u, 8); - } - - static void _camelliaFLs(List s, List fkey, int keyoff) { - s[1] ^= _rotateLeft32(s[0] & fkey[keyoff], 1); - s[0] ^= fkey[1 + keyoff] | s[1]; - - s[2] ^= fkey[3 + keyoff] | s[3]; - s[3] ^= _rotateLeft32(fkey[2 + keyoff] & s[2], 1); - } - - void _setKey(bool forEncryption, Uint8List key) { - final k = List.filled(8, 0); - final ka = List.filled(4, 0); - final kb = List.filled(4, 0); - final t = List.filled(4, 0); - - switch (key.length) { - case 16: - _keyIs128 = true; - k[0] = _bytes2uint(key, 0); - k[1] = _bytes2uint(key, 4); - k[2] = _bytes2uint(key, 8); - k[3] = _bytes2uint(key, 12); - break; - case 24: - k[0] = _bytes2uint(key, 0); - k[1] = _bytes2uint(key, 4); - k[2] = _bytes2uint(key, 8); - k[3] = _bytes2uint(key, 12); - k[4] = _bytes2uint(key, 16); - k[5] = _bytes2uint(key, 20); - k[6] = ~k[4]; - k[7] = ~k[5]; - _keyIs128 = false; - break; - case 32: - k[0] = _bytes2uint(key, 0); - k[1] = _bytes2uint(key, 4); - k[2] = _bytes2uint(key, 8); - k[3] = _bytes2uint(key, 12); - k[4] = _bytes2uint(key, 16); - k[5] = _bytes2uint(key, 20); - k[6] = _bytes2uint(key, 24); - k[7] = _bytes2uint(key, 28); - _keyIs128 = false; - break; - default: - throw Exception('Key size are only 16/24/32 bytes.'); - } - - for (var i = 0; i < 4; i++) { - ka[i] = k[i] ^ k[i + 4]; - } - /* compute KA */ - _camelliaF2(ka, _sigma, 0); - for (var i = 0; i < 4; i++) { - ka[i] ^= k[i]; - } - _camelliaF2(ka, _sigma, 4); - - if (_keyIs128) { - if (forEncryption) { - /* KL dependant keys */ - _kw[0] = k[0]; - _kw[1] = k[1]; - _kw[2] = k[2]; - _kw[3] = k[3]; - _roldq(15, k, 0, _subkey, 4); - _roldq(30, k, 0, _subkey, 12); - _roldq(15, k, 0, t, 0); - _subkey[18] = t[2]; - _subkey[19] = t[3]; - _roldq(17, k, 0, _ke, 4); - _roldq(17, k, 0, _subkey, 24); - _roldq(17, k, 0, _subkey, 32); - /* KA dependant keys */ - _subkey[0] = ka[0]; - _subkey[1] = ka[1]; - _subkey[2] = ka[2]; - _subkey[3] = ka[3]; - _roldq(15, ka, 0, _subkey, 8); - _roldq(15, ka, 0, _ke, 0); - _roldq(15, ka, 0, t, 0); - _subkey[16] = t[0]; - _subkey[17] = t[1]; - _roldq(15, ka, 0, _subkey, 20); - _roldqo32(34, ka, 0, _subkey, 28); - _roldq(17, ka, 0, _kw, 4); - } else { - // decryption - /* KL dependant keys */ - _kw[4] = k[0]; - _kw[5] = k[1]; - _kw[6] = k[2]; - _kw[7] = k[3]; - _decroldq(15, k, 0, _subkey, 28); - _decroldq(30, k, 0, _subkey, 20); - _decroldq(15, k, 0, t, 0); - _subkey[16] = t[0]; - _subkey[17] = t[1]; - _decroldq(17, k, 0, _ke, 0); - _decroldq(17, k, 0, _subkey, 8); - _decroldq(17, k, 0, _subkey, 0); - /* KA dependant keys */ - _subkey[34] = ka[0]; - _subkey[35] = ka[1]; - _subkey[32] = ka[2]; - _subkey[33] = ka[3]; - _decroldq(15, ka, 0, _subkey, 24); - _decroldq(15, ka, 0, _ke, 4); - _decroldq(15, ka, 0, t, 0); - _subkey[18] = t[2]; - _subkey[19] = t[3]; - _decroldq(15, ka, 0, _subkey, 12); - _decroldqo32(34, ka, 0, _subkey, 4); - _roldq(17, ka, 0, _kw, 0); - } - } else { - // 192bit or 256bit - /* compute KB */ - for (var i = 0; i < 4; i++) { - kb[i] = ka[i] ^ k[i + 4]; - } - _camelliaF2(kb, _sigma, 8); - - if (forEncryption) { - /* KL dependant keys */ - _kw[0] = k[0]; - _kw[1] = k[1]; - _kw[2] = k[2]; - _kw[3] = k[3]; - _roldqo32(45, k, 0, _subkey, 16); - _roldq(15, k, 0, _ke, 4); - _roldq(17, k, 0, _subkey, 32); - _roldqo32(34, k, 0, _subkey, 44); - /* KR dependant keys */ - _roldq(15, k, 4, _subkey, 4); - _roldq(15, k, 4, _ke, 0); - _roldq(30, k, 4, _subkey, 24); - _roldqo32(34, k, 4, _subkey, 36); - /* KA dependant keys */ - _roldq(15, ka, 0, _subkey, 8); - _roldq(30, ka, 0, _subkey, 20); - /* 32bit rotation */ - _ke[8] = ka[1]; - _ke[9] = ka[2]; - _ke[10] = ka[3]; - _ke[11] = ka[0]; - _roldqo32(49, ka, 0, _subkey, 40); - - /* KB dependant keys */ - _subkey[0] = kb[0]; - _subkey[1] = kb[1]; - _subkey[2] = kb[2]; - _subkey[3] = kb[3]; - _roldq(30, kb, 0, _subkey, 12); - _roldq(30, kb, 0, _subkey, 28); - _roldqo32(51, kb, 0, _kw, 4); - } else { - // decryption - /* KL dependant keys */ - _kw[4] = k[0]; - _kw[5] = k[1]; - _kw[6] = k[2]; - _kw[7] = k[3]; - _decroldqo32(45, k, 0, _subkey, 28); - _decroldq(15, k, 0, _ke, 4); - _decroldq(17, k, 0, _subkey, 12); - _decroldqo32(34, k, 0, _subkey, 0); - /* KR dependant keys */ - _decroldq(15, k, 4, _subkey, 40); - _decroldq(15, k, 4, _ke, 8); - _decroldq(30, k, 4, _subkey, 20); - _decroldqo32(34, k, 4, _subkey, 8); - /* KA dependant keys */ - _decroldq(15, ka, 0, _subkey, 36); - _decroldq(30, ka, 0, _subkey, 24); - /* 32bit rotation */ - _ke[2] = ka[1]; - _ke[3] = ka[2]; - _ke[0] = ka[3]; - _ke[1] = ka[0]; - _decroldqo32(49, ka, 0, _subkey, 4); - - /* KB dependant keys */ - _subkey[46] = kb[0]; - _subkey[47] = kb[1]; - _subkey[44] = kb[2]; - _subkey[45] = kb[3]; - _decroldq(30, kb, 0, _subkey, 32); - _decroldq(30, kb, 0, _subkey, 16); - _roldqo32(51, kb, 0, _kw, 0); - } - } - } - - int _processBlock128( - Uint8List input, - int inOff, - Uint8List output, - int outOff, - ) { - for (var i = 0; i < 4; i++) { - _state[i] = _bytes2uint(input, inOff + (i * 4)); - _state[i] ^= _kw[i]; - } - - _camelliaF2(_state, _subkey, 0); - _camelliaF2(_state, _subkey, 4); - _camelliaF2(_state, _subkey, 8); - _camelliaFLs(_state, _ke, 0); - _camelliaF2(_state, _subkey, 12); - _camelliaF2(_state, _subkey, 16); - _camelliaF2(_state, _subkey, 20); - _camelliaFLs(_state, _ke, 4); - _camelliaF2(_state, _subkey, 24); - _camelliaF2(_state, _subkey, 28); - _camelliaF2(_state, _subkey, 32); - - _state[2] ^= _kw[4]; - _state[3] ^= _kw[5]; - _state[0] ^= _kw[6]; - _state[1] ^= _kw[7]; - - _uint2bytes(_state[2], output, outOff); - _uint2bytes(_state[3], output, outOff + 4); - _uint2bytes(_state[0], output, outOff + 8); - _uint2bytes(_state[1], output, outOff + 12); - - return BLOCK_SIZE; - } - - int _processBlock256( - Uint8List input, - int inOff, - Uint8List output, - int outOff, - ) { - for (var i = 0; i < 4; i++) { - _state[i] = _bytes2uint(input, inOff + (i * 4)); - _state[i] ^= _kw[i]; - } - - _camelliaF2(_state, _subkey, 0); - _camelliaF2(_state, _subkey, 4); - _camelliaF2(_state, _subkey, 8); - _camelliaFLs(_state, _ke, 0); - _camelliaF2(_state, _subkey, 12); - _camelliaF2(_state, _subkey, 16); - _camelliaF2(_state, _subkey, 20); - _camelliaFLs(_state, _ke, 4); - _camelliaF2(_state, _subkey, 24); - _camelliaF2(_state, _subkey, 28); - _camelliaF2(_state, _subkey, 32); - _camelliaFLs(_state, _ke, 8); - _camelliaF2(_state, _subkey, 36); - _camelliaF2(_state, _subkey, 40); - _camelliaF2(_state, _subkey, 44); - - _state[2] ^= _kw[4]; - _state[3] ^= _kw[5]; - _state[0] ^= _kw[6]; - _state[1] ^= _kw[7]; - - _uint2bytes(_state[2], output, outOff); - _uint2bytes(_state[3], output, outOff + 4); - _uint2bytes(_state[0], output, outOff + 8); - _uint2bytes(_state[1], output, outOff + 12); - return BLOCK_SIZE; - } - - static int _unpack32(Uint8List x) => x.buffer.asByteData().getUint32(0); - static Uint8List _pack32(int x) => - Uint8List(4)..buffer.asByteData().setUint32(0, x); - - static int _shiftLeft32(int x, int n) { - return (x & _mask32) << n; - } - - static int _shiftRight32(int x, int n) { - return (x & _mask32) >> n; - } - - static int _rotateLeft32(int x, int n) { - x = x & _mask32; - return (x << n) | (x >> 32 - n); - } - - static int _rotateRight32(int x, int n) { - x = x & _mask32; - return (x >> n) | (x << 32 - n); - } -} diff --git a/pointycastle/lib/block/des_base.dart b/pointycastle/lib/block/des_base.dart deleted file mode 100644 index 9104aac..0000000 --- a/pointycastle/lib/block/des_base.dart +++ /dev/null @@ -1,860 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/src/ufixnum.dart'; - -class DesBase { - static final BLOCK_SIZE = 8; - - //static final List bytebit = [128, 64, 32, 16, 8, 4, 2, 1]; - static final List bytebit = [0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1]; - - static final List bigbyte = [ - 0x800000, - 0x400000, - 0x200000, - 0x100000, - 0x80000, - 0x40000, - 0x20000, - 0x10000, - 0x8000, - 0x4000, - 0x2000, - 0x1000, - 0x800, - 0x400, - 0x200, - 0x100, - 0x80, - 0x40, - 0x20, - 0x10, - 0x8, - 0x4, - 0x2, - 0x1 - ]; - - /* - * Use the key schedule specified in the Standard (ANSI X3.92-1981). - */ - - static final Uint8List pc1 = Uint8List.fromList([ - 56, - 48, - 40, - 32, - 24, - 16, - 8, - 0, - 57, - 49, - 41, - 33, - 25, - 17, - 9, - 1, - 58, - 50, - 42, - 34, - 26, - 18, - 10, - 2, - 59, - 51, - 43, - 35, - 62, - 54, - 46, - 38, - 30, - 22, - 14, - 6, - 61, - 53, - 45, - 37, - 29, - 21, - 13, - 5, - 60, - 52, - 44, - 36, - 28, - 20, - 12, - 4, - 27, - 19, - 11, - 3 - ]); - - static final Uint8List totrot = Uint8List.fromList( - [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]); - - static final Uint8List pc2 = Uint8List.fromList([ - 13, - 16, - 10, - 23, - 0, - 4, - 2, - 27, - 14, - 5, - 20, - 9, - 22, - 18, - 11, - 3, - 25, - 7, - 15, - 6, - 26, - 19, - 12, - 1, - 40, - 51, - 30, - 36, - 46, - 54, - 29, - 39, - 50, - 44, - 32, - 47, - 43, - 48, - 38, - 55, - 33, - 52, - 45, - 41, - 49, - 35, - 28, - 31 - ]); - - static final List SP1 = [ - 0x01010400, - 0x00000000, - 0x00010000, - 0x01010404, - 0x01010004, - 0x00010404, - 0x00000004, - 0x00010000, - 0x00000400, - 0x01010400, - 0x01010404, - 0x00000400, - 0x01000404, - 0x01010004, - 0x01000000, - 0x00000004, - 0x00000404, - 0x01000400, - 0x01000400, - 0x00010400, - 0x00010400, - 0x01010000, - 0x01010000, - 0x01000404, - 0x00010004, - 0x01000004, - 0x01000004, - 0x00010004, - 0x00000000, - 0x00000404, - 0x00010404, - 0x01000000, - 0x00010000, - 0x01010404, - 0x00000004, - 0x01010000, - 0x01010400, - 0x01000000, - 0x01000000, - 0x00000400, - 0x01010004, - 0x00010000, - 0x00010400, - 0x01000004, - 0x00000400, - 0x00000004, - 0x01000404, - 0x00010404, - 0x01010404, - 0x00010004, - 0x01010000, - 0x01000404, - 0x01000004, - 0x00000404, - 0x00010404, - 0x01010400, - 0x00000404, - 0x01000400, - 0x01000400, - 0x00000000, - 0x00010004, - 0x00010400, - 0x00000000, - 0x01010004 - ]; - - static final List SP2 = [ - 0x80108020, - 0x80008000, - 0x00008000, - 0x00108020, - 0x00100000, - 0x00000020, - 0x80100020, - 0x80008020, - 0x80000020, - 0x80108020, - 0x80108000, - 0x80000000, - 0x80008000, - 0x00100000, - 0x00000020, - 0x80100020, - 0x00108000, - 0x00100020, - 0x80008020, - 0x00000000, - 0x80000000, - 0x00008000, - 0x00108020, - 0x80100000, - 0x00100020, - 0x80000020, - 0x00000000, - 0x00108000, - 0x00008020, - 0x80108000, - 0x80100000, - 0x00008020, - 0x00000000, - 0x00108020, - 0x80100020, - 0x00100000, - 0x80008020, - 0x80100000, - 0x80108000, - 0x00008000, - 0x80100000, - 0x80008000, - 0x00000020, - 0x80108020, - 0x00108020, - 0x00000020, - 0x00008000, - 0x80000000, - 0x00008020, - 0x80108000, - 0x00100000, - 0x80000020, - 0x00100020, - 0x80008020, - 0x80000020, - 0x00100020, - 0x00108000, - 0x00000000, - 0x80008000, - 0x00008020, - 0x80000000, - 0x80100020, - 0x80108020, - 0x00108000 - ]; - - static final List SP3 = [ - 0x00000208, - 0x08020200, - 0x00000000, - 0x08020008, - 0x08000200, - 0x00000000, - 0x00020208, - 0x08000200, - 0x00020008, - 0x08000008, - 0x08000008, - 0x00020000, - 0x08020208, - 0x00020008, - 0x08020000, - 0x00000208, - 0x08000000, - 0x00000008, - 0x08020200, - 0x00000200, - 0x00020200, - 0x08020000, - 0x08020008, - 0x00020208, - 0x08000208, - 0x00020200, - 0x00020000, - 0x08000208, - 0x00000008, - 0x08020208, - 0x00000200, - 0x08000000, - 0x08020200, - 0x08000000, - 0x00020008, - 0x00000208, - 0x00020000, - 0x08020200, - 0x08000200, - 0x00000000, - 0x00000200, - 0x00020008, - 0x08020208, - 0x08000200, - 0x08000008, - 0x00000200, - 0x00000000, - 0x08020008, - 0x08000208, - 0x00020000, - 0x08000000, - 0x08020208, - 0x00000008, - 0x00020208, - 0x00020200, - 0x08000008, - 0x08020000, - 0x08000208, - 0x00000208, - 0x08020000, - 0x00020208, - 0x00000008, - 0x08020008, - 0x00020200 - ]; - - static final List SP4 = [ - 0x00802001, - 0x00002081, - 0x00002081, - 0x00000080, - 0x00802080, - 0x00800081, - 0x00800001, - 0x00002001, - 0x00000000, - 0x00802000, - 0x00802000, - 0x00802081, - 0x00000081, - 0x00000000, - 0x00800080, - 0x00800001, - 0x00000001, - 0x00002000, - 0x00800000, - 0x00802001, - 0x00000080, - 0x00800000, - 0x00002001, - 0x00002080, - 0x00800081, - 0x00000001, - 0x00002080, - 0x00800080, - 0x00002000, - 0x00802080, - 0x00802081, - 0x00000081, - 0x00800080, - 0x00800001, - 0x00802000, - 0x00802081, - 0x00000081, - 0x00000000, - 0x00000000, - 0x00802000, - 0x00002080, - 0x00800080, - 0x00800081, - 0x00000001, - 0x00802001, - 0x00002081, - 0x00002081, - 0x00000080, - 0x00802081, - 0x00000081, - 0x00000001, - 0x00002000, - 0x00800001, - 0x00002001, - 0x00802080, - 0x00800081, - 0x00002001, - 0x00002080, - 0x00800000, - 0x00802001, - 0x00000080, - 0x00800000, - 0x00002000, - 0x00802080 - ]; - - static final List SP5 = [ - 0x00000100, - 0x02080100, - 0x02080000, - 0x42000100, - 0x00080000, - 0x00000100, - 0x40000000, - 0x02080000, - 0x40080100, - 0x00080000, - 0x02000100, - 0x40080100, - 0x42000100, - 0x42080000, - 0x00080100, - 0x40000000, - 0x02000000, - 0x40080000, - 0x40080000, - 0x00000000, - 0x40000100, - 0x42080100, - 0x42080100, - 0x02000100, - 0x42080000, - 0x40000100, - 0x00000000, - 0x42000000, - 0x02080100, - 0x02000000, - 0x42000000, - 0x00080100, - 0x00080000, - 0x42000100, - 0x00000100, - 0x02000000, - 0x40000000, - 0x02080000, - 0x42000100, - 0x40080100, - 0x02000100, - 0x40000000, - 0x42080000, - 0x02080100, - 0x40080100, - 0x00000100, - 0x02000000, - 0x42080000, - 0x42080100, - 0x00080100, - 0x42000000, - 0x42080100, - 0x02080000, - 0x00000000, - 0x40080000, - 0x42000000, - 0x00080100, - 0x02000100, - 0x40000100, - 0x00080000, - 0x00000000, - 0x40080000, - 0x02080100, - 0x40000100 - ]; - - static final List SP6 = [ - 0x20000010, - 0x20400000, - 0x00004000, - 0x20404010, - 0x20400000, - 0x00000010, - 0x20404010, - 0x00400000, - 0x20004000, - 0x00404010, - 0x00400000, - 0x20000010, - 0x00400010, - 0x20004000, - 0x20000000, - 0x00004010, - 0x00000000, - 0x00400010, - 0x20004010, - 0x00004000, - 0x00404000, - 0x20004010, - 0x00000010, - 0x20400010, - 0x20400010, - 0x00000000, - 0x00404010, - 0x20404000, - 0x00004010, - 0x00404000, - 0x20404000, - 0x20000000, - 0x20004000, - 0x00000010, - 0x20400010, - 0x00404000, - 0x20404010, - 0x00400000, - 0x00004010, - 0x20000010, - 0x00400000, - 0x20004000, - 0x20000000, - 0x00004010, - 0x20000010, - 0x20404010, - 0x00404000, - 0x20400000, - 0x00404010, - 0x20404000, - 0x00000000, - 0x20400010, - 0x00000010, - 0x00004000, - 0x20400000, - 0x00404010, - 0x00004000, - 0x00400010, - 0x20004010, - 0x00000000, - 0x20404000, - 0x20000000, - 0x00400010, - 0x20004010 - ]; - - static final List SP7 = [ - 0x00200000, - 0x04200002, - 0x04000802, - 0x00000000, - 0x00000800, - 0x04000802, - 0x00200802, - 0x04200800, - 0x04200802, - 0x00200000, - 0x00000000, - 0x04000002, - 0x00000002, - 0x04000000, - 0x04200002, - 0x00000802, - 0x04000800, - 0x00200802, - 0x00200002, - 0x04000800, - 0x04000002, - 0x04200000, - 0x04200800, - 0x00200002, - 0x04200000, - 0x00000800, - 0x00000802, - 0x04200802, - 0x00200800, - 0x00000002, - 0x04000000, - 0x00200800, - 0x04000000, - 0x00200800, - 0x00200000, - 0x04000802, - 0x04000802, - 0x04200002, - 0x04200002, - 0x00000002, - 0x00200002, - 0x04000000, - 0x04000800, - 0x00200000, - 0x04200800, - 0x00000802, - 0x00200802, - 0x04200800, - 0x00000802, - 0x04000002, - 0x04200802, - 0x04200000, - 0x00200800, - 0x00000000, - 0x00000002, - 0x04200802, - 0x00000000, - 0x00200802, - 0x04200000, - 0x00000800, - 0x04000002, - 0x04000800, - 0x00000800, - 0x00200002 - ]; - - static final List SP8 = [ - 0x10001040, - 0x00001000, - 0x00040000, - 0x10041040, - 0x10000000, - 0x10001040, - 0x00000040, - 0x10000000, - 0x00040040, - 0x10040000, - 0x10041040, - 0x00041000, - 0x10041000, - 0x00041040, - 0x00001000, - 0x00000040, - 0x10040000, - 0x10000040, - 0x10001000, - 0x00001040, - 0x00041000, - 0x00040040, - 0x10040040, - 0x10041000, - 0x00001040, - 0x00000000, - 0x00000000, - 0x10040040, - 0x10000040, - 0x10001000, - 0x00041040, - 0x00040000, - 0x00041040, - 0x00040000, - 0x10041000, - 0x00001000, - 0x00000040, - 0x10040040, - 0x00001000, - 0x00041040, - 0x10001000, - 0x00000040, - 0x10000040, - 0x10040000, - 0x10040040, - 0x10000000, - 0x00040000, - 0x10001040, - 0x00000000, - 0x10041040, - 0x00040040, - 0x10000040, - 0x10040000, - 0x10001000, - 0x10001040, - 0x00000000, - 0x10041040, - 0x00041000, - 0x00041000, - 0x00001040, - 0x00001040, - 0x00040040, - 0x10000000, - 0x10041000 - ]; - - List generateWorkingKey(bool encrypting, Uint8List key) { - var newKey = List.generate(32, (index) => 0); - var pc1m = List.generate(56, (index) => false); - var pcr = List.generate(56, (index) => false); - - for (var j = 0; j < 56; j++) { - var l = pc1[j]; - - pc1m[j] = ((key[shiftr32(l, 3)] & bytebit[l & 07]) != 0); - } - - for (var i = 0; i < 16; i++) { - int l, m, n; - - if (encrypting) { - m = shiftl32(i, 1); - } else { - m = shiftl32(15 - i, 1); - } - - n = m + 1; - newKey[m] = newKey[n] = 0; - - for (var j = 0; j < 28; j++) { - l = j + totrot[i]; - if (l < 28) { - pcr[j] = pc1m[l]; - } else { - pcr[j] = pc1m[l - 28]; - } - } - - for (var j = 28; j < 56; j++) { - l = j + totrot[i]; - if (l < 56) { - pcr[j] = pc1m[l]; - } else { - pcr[j] = pc1m[l - 28]; - } - } - - for (var j = 0; j < 24; j++) { - if (pcr[pc2[j]]) { - newKey[m] |= bigbyte[j]; - } - - if (pcr[pc2[j + 24]]) { - newKey[n] |= bigbyte[j]; - } - } - } - - // - // store the processed key - // - for (var i = 0; i != 32; i += 2) { - int i1, i2; - - i1 = newKey[i]; - i2 = newKey[i + 1]; - - newKey[i] = (shiftl32(i1 & 0x00fc0000, 6)) | - (shiftl32(i1 & 0x00000fc0, 10)) | - (shiftr32(i2 & 0x00fc0000, 10)) | - (shiftr32(i2 & 0x00000fc0, 6)); - - newKey[i + 1] = (shiftl32(i1 & 0x0003f000, 12)) | - (shiftl32(i1 & 0x0000003f, 16)) | - (shiftr32(i2 & 0x0003f000, 4)) | - (i2 & 0x0000003f); - } - - return newKey; - } - - void desFunc( - List wKey, - Uint8List inp, - int inOff, - Uint8List out, - int outOff, - ) { - int work, right, left; - - left = _bigEndianToInt(inp, inOff); - right = _bigEndianToInt(inp, inOff + 4); - - work = ((shiftr32(left, 4)) ^ right) & 0x0f0f0f0f; - right ^= work; - left ^= shiftl32(work, 4); - work = ((shiftr32(left, 16)) ^ right) & 0x0000ffff; - right ^= work; - left ^= shiftl32(work, 16); - work = ((shiftr32(right, 2)) ^ left) & 0x33333333; - left ^= work; - right ^= shiftl32(work, 2); - work = ((shiftr32(right, 8)) ^ left) & 0x00ff00ff; - left ^= work; - right ^= shiftl32(work, 8); - right = (shiftl32(right, 1)) | (shiftr32(right, 31)); - work = (left ^ right) & 0xaaaaaaaa; - left ^= work; - right ^= work; - left = (shiftl32(left, 1)) | (shiftr32(left, 31)); - - for (var round = 0; round < 8; round++) { - int fval; - - work = (shiftl32(right, 28)) | (shiftr32(right, 4)); - work ^= wKey[round * 4 + 0]; - fval = SP7[work & 0x3f]; - fval |= SP5[(shiftr32(work, 8)) & 0x3f]; - fval |= SP3[(shiftr32(work, 16)) & 0x3f]; - fval |= SP1[(shiftr32(work, 24)) & 0x3f]; - work = right ^ wKey[round * 4 + 1]; - fval |= SP8[work & 0x3f]; - fval |= SP6[(shiftr32(work, 8)) & 0x3f]; - fval |= SP4[(shiftr32(work, 16)) & 0x3f]; - fval |= SP2[(shiftr32(work, 24)) & 0x3f]; - left ^= fval; - work = (shiftl32(left, 28)) | (shiftr32(left, 4)); - work ^= wKey[round * 4 + 2]; - fval = SP7[work & 0x3f]; - fval |= SP5[(shiftr32(work, 8)) & 0x3f]; - fval |= SP3[(shiftr32(work, 16)) & 0x3f]; - fval |= SP1[(shiftr32(work, 24)) & 0x3f]; - work = left ^ wKey[round * 4 + 3]; - fval |= SP8[work & 0x3f]; - fval |= SP6[(shiftr32(work, 8)) & 0x3f]; - fval |= SP4[(shiftr32(work, 16)) & 0x3f]; - fval |= SP2[(shiftr32(work, 24)) & 0x3f]; - right ^= fval; - } - right = (shiftl32(right, 31)) | (shiftr32(right, 1)); - work = (left ^ right) & 0xaaaaaaaa; - left ^= work; - right ^= work; - left = (shiftl32(left, 31)) | (shiftr32(left, 1)); - work = ((shiftr32(left, 8)) ^ right) & 0x00ff00ff; - right ^= work; - left ^= shiftl32(work, 8); - work = ((shiftr32(left, 2)) ^ right) & 0x33333333; - right ^= work; - left ^= shiftl32(work, 2); - work = ((shiftr32(right, 16)) ^ left) & 0x0000ffff; - left ^= work; - right ^= shiftl32(work, 16); - work = ((shiftr32(right, 4)) ^ left) & 0x0f0f0f0f; - left ^= work; - right ^= shiftl32(work, 4); - - _intToBigEndian(right, out, outOff); - _intToBigEndian(left, out, outOff + 4); - } - - void _intToBigEndian(int n, Uint8List bs, int off) { - bs[off] = shiftr32(n, 24); - bs[++off] = shiftr32(n, 16); - bs[++off] = shiftr32(n, 8); - bs[++off] = n; - } - - int _bigEndianToInt(Uint8List bs, int off) { - var n = shiftl32(bs[off], 24); - n |= shiftl32(bs[++off] & 0xff, 16); - n |= shiftl32(bs[++off] & 0xff, 8); - n |= bs[++off] & 0xff; - return n; - } -} diff --git a/pointycastle/lib/block/desede_engine.dart b/pointycastle/lib/block/desede_engine.dart deleted file mode 100644 index ee85c40..0000000 --- a/pointycastle/lib/block/desede_engine.dart +++ /dev/null @@ -1,108 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/block/des_base.dart'; -import 'package:pointycastle/src/impl/base_block_cipher.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -class DESedeEngine extends DesBase implements BaseBlockCipher { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(BlockCipher, 'DESede', () => DESedeEngine()); - - static final BLOCK_SIZE = 8; - - List? workingKey1; - List? workingKey2; - List? workingKey3; - - bool forEncryption = false; - - @override - String get algorithmName => 'DESede'; - - @override - int get blockSize => BLOCK_SIZE; - - @override - void init(bool forEncryption, CipherParameters? params) { - if (params is KeyParameter) { - var keyMaster = params.key; - - if (keyMaster.length != 24 && keyMaster.length != 16) { - throw ArgumentError('key size must be 16 or 24 bytes.'); - } - - this.forEncryption = forEncryption; - - var key1 = Uint8List(8); - - _arrayCopy(keyMaster, 0, key1, 0, key1.length); - workingKey1 = generateWorkingKey(forEncryption, key1); - - var key2 = Uint8List(8); - _arrayCopy(keyMaster, 8, key2, 0, key2.length); - workingKey2 = generateWorkingKey(!forEncryption, key2); - - if (keyMaster.length == 24) { - var key3 = Uint8List(8); - _arrayCopy(keyMaster, 16, key3, 0, key3.length); - workingKey3 = generateWorkingKey(forEncryption, key3); - } else { - workingKey3 = workingKey1; - } - } - } - - @override - Uint8List process(Uint8List data) { - var out = Uint8List(blockSize); - var len = processBlock(data, 0, out, 0); - return out.sublist(0, len); - } - - @override - int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { - if (workingKey1 == null || workingKey2 == null || workingKey3 == null) { - throw ArgumentError('DESede engine not initialised'); - } - - if ((inpOff + BLOCK_SIZE) > inp.length) { - throw ArgumentError('input buffer too short'); - } - - if ((outOff + BLOCK_SIZE) > out.length) { - throw ArgumentError('output buffer too short'); - } - - var temp = Uint8List(BLOCK_SIZE); - - if (forEncryption) { - desFunc(workingKey1!, inp, inpOff, temp, 0); - desFunc(workingKey2!, temp, 0, temp, 0); - desFunc(workingKey3!, temp, 0, out, outOff); - } else { - desFunc(workingKey3!, inp, inpOff, temp, 0); - desFunc(workingKey2!, temp, 0, temp, 0); - desFunc(workingKey1!, temp, 0, out, outOff); - } - - return BLOCK_SIZE; - } - - @override - void reset() {} - - void _arrayCopy(Uint8List? sourceArr, int sourcePos, Uint8List? outArr, - int outPos, int len) { - for (var i = 0; i < len; i++) { - outArr![outPos + i] = sourceArr![sourcePos + i]; - } - } - - int bitsOfSecurity() { - if (workingKey1 != null && workingKey1 == workingKey3) { - return 80; - } - return 112; - } -} diff --git a/pointycastle/lib/block/modes/cbc.dart b/pointycastle/lib/block/modes/cbc.dart deleted file mode 100644 index 57b65d3..0000000 --- a/pointycastle/lib/block/modes/cbc.dart +++ /dev/null @@ -1,113 +0,0 @@ -// See file LICENSE for more information. - -library impl.block_cipher.modes.cbc; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/impl/base_block_cipher.dart'; - -/// Implementation of Cipher-Block-Chaining (CBC) mode on top of a [BlockCipher]. -class CBCBlockCipher extends BaseBlockCipher { - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - BlockCipher, - '/CBC', - (_, final Match match) => () { - var underlying = BlockCipher(match.group(1)!); - return CBCBlockCipher(underlying); - }); - - final BlockCipher _underlyingCipher; - - late Uint8List _iv; - Uint8List? _cbcV; - Uint8List? _cbcNextV; - - late bool _encrypting; - - CBCBlockCipher(this._underlyingCipher) { - _iv = Uint8List(blockSize); - _cbcV = Uint8List(blockSize); - _cbcNextV = Uint8List(blockSize); - } - - @override - String get algorithmName => '${_underlyingCipher.algorithmName}/CBC'; - @override - int get blockSize => _underlyingCipher.blockSize; - - @override - void reset() { - _cbcV!.setAll(0, _iv); - _cbcNextV!.fillRange(0, _cbcNextV!.length, 0); - - _underlyingCipher.reset(); - } - - @override - void init(bool forEncryption, covariant ParametersWithIV params) { - if (params.iv.length != blockSize) { - throw ArgumentError( - 'Initialization vector must be the same length as block size'); - } - - _encrypting = forEncryption; - _iv.setAll(0, params.iv); - - reset(); - - _underlyingCipher.init(forEncryption, params.parameters); - } - - @override - int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) => - _encrypting - ? _encryptBlock(inp, inpOff, out, outOff) - : _decryptBlock(inp, inpOff, out, outOff); - - int _encryptBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { - if ((inpOff + blockSize) > inp.length) { - throw ArgumentError('Input buffer too short'); - } - - // XOR the cbcV and the input, then encrypt the cbcV - for (var i = 0; i < blockSize; i++) { - _cbcV![i] ^= inp[inpOff + i]; - } - - var length = _underlyingCipher.processBlock(_cbcV!, 0, out, outOff); - - // copy ciphertext to cbcV - _cbcV!.setRange(0, blockSize, - Uint8List.view(out.buffer, out.offsetInBytes + outOff, blockSize)); - - return length; - } - - int _decryptBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { - if ((inpOff + blockSize) > inp.length) { - throw ArgumentError('Input buffer too short'); - } - - _cbcNextV!.setRange(0, blockSize, - Uint8List.view(inp.buffer, inp.offsetInBytes + inpOff, blockSize)); - - var length = _underlyingCipher.processBlock(inp, inpOff, out, outOff); - - // XOR the cbcV and the output - for (var i = 0; i < blockSize; i++) { - out[outOff + i] ^= _cbcV![i]; - } - - // swap the back up buffer into next position - Uint8List? tmp; - - tmp = _cbcV; - _cbcV = _cbcNextV; - _cbcNextV = tmp; - - return length; - } -} diff --git a/pointycastle/lib/block/modes/ccm.dart b/pointycastle/lib/block/modes/ccm.dart deleted file mode 100644 index bcd74c1..0000000 --- a/pointycastle/lib/block/modes/ccm.dart +++ /dev/null @@ -1,344 +0,0 @@ -library impl.block_cipher.modes.ccm; - -import 'dart:typed_data'; - -import 'package:pointycastle/export.dart'; -import 'package:pointycastle/src/ufixnum.dart'; -import 'package:pointycastle/src/utils.dart'; - -import '../../src/impl/base_aead_block_cipher.dart'; -import '../../src/registry/registry.dart'; - -/// Implementation of the CCM block cipher mode. CCM is authenticated, meaning -/// that you can pass AEAD data (and that appending a MAC of the ciphertext is -/// unnecessary). -class CCMBlockCipher extends BaseAEADBlockCipher { - late Uint8List _macBlock; - @override - late Uint8List nonce; - - @override - Uint8List? aad; - - @override - late int macSize; - - late KeyParameter _keyParam; - - BytesBuilder associatedText = BytesBuilder(); - BytesBuilder data = BytesBuilder(); - - late bool _forEncryption; - - // ignore: non_constant_identifier_names - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - BlockCipher, - '/CCM', - (_, final Match match) => () { - var underlying = BlockCipher(match.group(1)!); - return CCMBlockCipher(underlying); - }); - - CCMBlockCipher(super.underlyingCipher) { - _macBlock = Uint8List(blockSize); - if (blockSize != 16) { - throw ArgumentError('CCM requires a block size of 16'); - } - } - - @override - void reset() { - underlyingCipher.reset(); - associatedText.clear(); - data.clear(); - } - - @override - void init(bool forEncryption, covariant CipherParameters params) { - _forEncryption = forEncryption; - KeyParameter key; - - if (params is AEADParameters) { - nonce = params.nonce; - aad = params.associatedData; - macSize = _getMacSize(forEncryption, params.macSize); - key = params.parameters as KeyParameter; - } else if (params is ParametersWithIV) { - nonce = params.iv; - aad = null; - macSize = _getMacSize(forEncryption, 64); - key = params.parameters!; - } else { - throw ArgumentError('Invalid parameter class'); - } - - if (nonce.length < 7 || nonce.length > 13) { - throw ArgumentError('nonce must have length from 7 to 13 octets'); - } - - _keyParam = key; - - reset(); - } - - @override - String get algorithmName => '${underlyingCipher.algorithmName}/CCM'; - - @override - int processBytes( - Uint8List inp, int inpOff, int len, Uint8List out, int outOff) { - data.write(inp, inpOff, len); - return 0; - } - - @override - int doFinal(Uint8List out, int outOff) { - var len = _processPacket(data.toBytes(), 0, data.length, out, outOff); - - reset(); - - return len; - } - - @override - void processAADBytes(Uint8List inp, int inpOff, int len) { - associatedText.write(inp, inpOff, len); - } - - @override - int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) => - processBytes(inp, inpOff, inp.length, out, outOff); - - int _processPacket( - Uint8List inp, int inpOff, int len, Uint8List out, int outOff) { - var n = nonce.length; - var q = 15 - n; - if (q < 4) { - var limitLen = 1 << (8 * q); - if (len >= limitLen) { - throw StateError('CCM packet too large for choice of q.'); - } - } - - var iv = Uint8List(blockSize); - iv[0] = (q - 1) & 0x7; - arrayCopy(nonce, 0, iv, 1, nonce.length); - - BlockCipher ctrCipher = - SICBlockCipher(blockSize, SICStreamCipher(underlyingCipher)); - ctrCipher.init( - forEncryption, ParametersWithIV(_keyParam, iv)); - - int outputLen; - var inIndex = inpOff; - var outIndex = outOff; - - if (forEncryption) { - outputLen = len + macSize; - if (out.length < (outputLen + outOff)) { - throw ArgumentError('Output buffer too short.'); - } - - _calculateMac(inp, inpOff, len, _macBlock); - - var encMac = Uint8List(blockSize); - - ctrCipher.processBlock(_macBlock, 0, encMac, 0); // S0 - - while (inIndex < (inpOff + len - blockSize)) // S1... - { - ctrCipher.processBlock(inp, inIndex, out, outIndex); - outIndex += blockSize; - inIndex += blockSize; - } - - var block = Uint8List(blockSize); - - arrayCopy(inp, inIndex, block, 0, len + inpOff - inIndex); - - ctrCipher.processBlock(block, 0, block, 0); - - arrayCopy(block, 0, out, outIndex, len + inpOff - inIndex); - - arrayCopy(encMac, 0, out, outOff + len, macSize); - } else { - if (len < macSize) { - throw InvalidCipherTextException('data too short'); - } - outputLen = len - macSize; - if (out.length < (outputLen + outOff)) { - throw ArgumentError('Output buffer too short.'); - } - - arrayCopy(inp, inpOff + outputLen, _macBlock, 0, macSize); - - ctrCipher.processBlock(_macBlock, 0, _macBlock, 0); - - for (var i = macSize; i != _macBlock.length; i++) { - _macBlock[i] = 0; - } - - while (inIndex < (inpOff + outputLen - blockSize)) { - ctrCipher.processBlock(inp, inIndex, out, outIndex); - outIndex += blockSize; - inIndex += blockSize; - } - - var block = Uint8List(blockSize); - - arrayCopy(inp, inIndex, block, 0, outputLen - (inIndex - inpOff)); - - ctrCipher.processBlock(block, 0, block, 0); - - arrayCopy(block, 0, out, outIndex, outputLen - (inIndex - inpOff)); - - var calculatedMacBlock = Uint8List(blockSize); - - _calculateMac(out, outOff, outputLen, calculatedMacBlock); - - if (!(_macBlock.length == calculatedMacBlock.length)) { - throw StateError('mac check in CCM failed'); - } else { - for (var i = 0; i < _macBlock.length; i++) { - if (_macBlock[i] != calculatedMacBlock[i]) { - throw StateError('mac check in CCM failed'); - } - } - } - } - - return outputLen; - } - - int _calculateMac( - Uint8List data, int dataOff, int dataLen, Uint8List macBlock) { - Mac cMac = CBCBlockCipherMac(underlyingCipher, macSize * 8, null); - - cMac.init(ParametersWithIV(_keyParam, Uint8List(blockSize))); - - // - // build b0 - // - var b0 = Uint8List(16); - - if (_hasAssociatedText()) { - b0[0] |= 0x40; - } - - b0[0] |= (((cMac.macSize - 2) ~/ 2) & 0x7) << 3; - - b0[0] |= ((15 - nonce.length) - 1) & 0x7; - - arrayCopy(nonce, 0, b0, 1, nonce.length); - - var q = dataLen; - var count = 1; - while (q > 0) { - b0[b0.length - count] = q & 0xff; - q = cshiftr32(q, 8); - count++; - } - - cMac.update(b0, 0, b0.length); - - // - // process associated text - // - if (_hasAssociatedText()) { - int extra; - - var textLength = _getAssociatedTextLength(); - if (textLength < ((1 << 16) - (1 << 8))) { - cMac.updateByte(textLength >> 8); - cMac.updateByte(textLength); - - extra = 2; - } else { - cMac.updateByte(0xff); - cMac.updateByte(0xfe); - cMac.updateByte(textLength >> 24); - cMac.updateByte(textLength >> 16); - cMac.updateByte(textLength >> 8); - cMac.updateByte(textLength); - - extra = 6; - } - - if (aad != null) { - cMac.update(aad!, 0, aad!.length); - } - if (associatedText.length > 0) { - cMac.update(associatedText.toBytes(), 0, associatedText.length); - } - - extra = (extra + textLength) % 16; - if (extra != 0) { - for (var i = extra; i != 16; i++) { - cMac.updateByte(0x00); - } - } - } - - // - // add the text - // - cMac.update(data, dataOff, dataLen); - - return cMac.doFinal(macBlock, 0); - } - - int _getMacSize(bool forEncryption, int requestedMacBits) { - if (forEncryption && - (requestedMacBits < 32 || - requestedMacBits > 128 || - 0 != (requestedMacBits & 15))) { - throw ArgumentError( - 'tag length in octets must be one of {4,6,8,10,12,14,16}'); - } - - return cshiftr32(requestedMacBits, 3); - } - - @override - Uint8List get mac { - var out = Uint8List(macSize); - arrayCopy(_macBlock, 0, out, 0, out.length); - return out; - } - - @override - bool get forEncryption => _forEncryption; - - @override - void prepare(KeyParameter keyParam) { - // Unused artifact of class hierarchy. - } - - @override - int getOutputSize(int length) { - var totalData = length + data.length; - - if (forEncryption) { - return totalData + macSize; - } - - return totalData < macSize ? 0 : totalData - macSize; - } - - int _getAssociatedTextLength() { - return associatedText.length + ((aad == null) ? 0 : aad!.length); - } - - bool _hasAssociatedText() { - return _getAssociatedTextLength() > 0; - } - - @override - Uint8List get remainingInput => data.toBytes(); -} - -extension WriteLen on BytesBuilder { - void write(Uint8List b, int off, int len) { - add(b.sublist(off, off + len)); - } -} diff --git a/pointycastle/lib/block/modes/cfb.dart b/pointycastle/lib/block/modes/cfb.dart deleted file mode 100644 index f4bfc55..0000000 --- a/pointycastle/lib/block/modes/cfb.dart +++ /dev/null @@ -1,175 +0,0 @@ -// See file LICENSE for more information. - -library impl.block_cipher.modes.cfb; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/impl/base_block_cipher.dart'; - -/// Implementation of Cipher Feedback Mode (CFB) on top of a [BlockCipher]. -class CFBBlockCipher extends BaseBlockCipher { - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig.regex( - BlockCipher, - r'^(.+)/CFB-([0-9]+)$', - (_, final Match match) => () { - var underlying = BlockCipher(match.group(1)!); - var blockSizeInBits = int.parse(match.group(2)!); - if ((blockSizeInBits % 8) != 0) { - throw RegistryFactoryException.invalid( - 'Bad CFB block size: $blockSizeInBits (must be a multiple of 8)'); - } - return CFBBlockCipher(underlying, blockSizeInBits ~/ 8); - }); - - @override - final int blockSize; - - final BlockCipher _underlyingCipher; - - late Uint8List _iv; - Uint8List? _cfbV; - Uint8List? _cfbOutV; - late bool _encrypting; - - CFBBlockCipher(this._underlyingCipher, this.blockSize) { - _iv = Uint8List(_underlyingCipher.blockSize); - _cfbV = Uint8List(_underlyingCipher.blockSize); - _cfbOutV = Uint8List(_underlyingCipher.blockSize); - } - - @override - String get algorithmName => - '${_underlyingCipher.algorithmName}/CFB-${blockSize * 8}'; - - @override - void reset() { - _cfbV!.setRange(0, _iv.length, _iv); - _underlyingCipher.reset(); - } - - /// Initialise the cipher and, possibly, the initialisation vector (IV). - /// If an IV isn't passed as part of the parameter, the IV will be all zeros. - /// An IV which is too short is handled in FIPS compliant fashion. - /// - /// @param encrypting if true the cipher is initialised for - /// encryption, if false for decryption. - /// @param params the key and other data required by the cipher. - /// @exception IllegalArgumentException if the params argument is - /// inappropriate. - @override - void init(bool encrypting, CipherParameters? params) { - _encrypting = encrypting; - - if (params is ParametersWithIV) { - var ivParam = params; - var iv = ivParam.iv; - - if (iv.length < _iv.length) { - // prepend the supplied IV with zeros (per FIPS PUB 81) - var offset = _iv.length - iv.length; - _iv.fillRange(0, offset, 0); - _iv.setRange(offset, _iv.length, iv); - } else { - _iv.setRange(0, _iv.length, iv); - } - - reset(); - - // if null it's an IV changed only. - if (ivParam.parameters != null) { - _underlyingCipher.init(true, ivParam.parameters); - } - } else { - reset(); - _underlyingCipher.init(true, params); - } - } - - /// Process one block of input from the array in and write it to - /// the out array. - /// - /// @param in the array containing the input data. - /// @param inOff offset into the in array the data starts at. - /// @param out the array the output data will be copied into. - /// @param outOff the offset into the out array the output will start at. - /// @exception DataLengthException if there isn't enough data in in, or - /// space in out. - /// @exception IllegalStateException if the cipher isn't initialised. - /// @return the number of bytes processed and produced. - @override - int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) => - _encrypting - ? _encryptBlock(inp, inpOff, out, outOff) - : _decryptBlock(inp, inpOff, out, outOff); - - /// Do the appropriate processing for CFB mode encryption. - /// - /// @param in the array containing the data to be encrypted. - /// @param inOff offset into the in array the data starts at. - /// @param out the array the encrypted data will be copied into. - /// @param outOff the offset into the out array the output will start at. - /// @exception DataLengthException if there isn't enough data in in, or - /// space in out. - /// @exception IllegalStateException if the cipher isn't initialised. - /// @return the number of bytes processed and produced. - int _encryptBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { - if ((inpOff + blockSize) > inp.length) { - throw ArgumentError('Input buffer too short'); - } - - if ((outOff + blockSize) > out.length) { - throw ArgumentError('Output buffer too short'); - } - - _underlyingCipher.processBlock(_cfbV!, 0, _cfbOutV!, 0); - - // XOR the cfbV with the plaintext producing the ciphertext - for (var i = 0; i < blockSize; i++) { - out[outOff + i] = _cfbOutV![i] ^ inp[inpOff + i]; - } - - // change over the input block. - var offset = _cfbV!.length - blockSize; - _cfbV!.setRange(0, offset, _cfbV!.sublist(blockSize)); - _cfbV!.setRange(offset, _cfbV!.length, out.sublist(outOff)); - - return blockSize; - } - - /// Do the appropriate processing for CFB mode decryption. - /// - /// @param in the array containing the data to be decrypted. - /// @param inOff offset into the in array the data starts at. - /// @param out the array the encrypted data will be copied into. - /// @param outOff the offset into the out array the output will start at. - /// @exception DataLengthException if there isn't enough data in in, or - /// space in out. - /// @exception IllegalStateException if the cipher isn't initialised. - /// @return the number of bytes processed and produced. - int _decryptBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { - if ((inpOff + blockSize) > inp.length) { - throw ArgumentError('Input buffer too short'); - } - - if ((outOff + blockSize) > out.length) { - throw ArgumentError('Output buffer too short'); - } - - _underlyingCipher.processBlock(_cfbV!, 0, _cfbOutV!, 0); - - // change over the input block. - var offset = _cfbV!.length - blockSize; - _cfbV!.setRange(0, offset, _cfbV!.sublist(blockSize)); - _cfbV!.setRange(offset, _cfbV!.length, inp.sublist(inpOff)); - - // XOR the cfbV with the ciphertext producing the plaintext - for (var i = 0; i < blockSize; i++) { - out[outOff + i] = _cfbOutV![i] ^ inp[inpOff + i]; - } - - return blockSize; - } -} diff --git a/pointycastle/lib/block/modes/ctr.dart b/pointycastle/lib/block/modes/ctr.dart deleted file mode 100644 index 769146a..0000000 --- a/pointycastle/lib/block/modes/ctr.dart +++ /dev/null @@ -1,22 +0,0 @@ -// See file LICENSE for more information. - -library impl.block_cipher.modes.ctr; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/adapters/stream_cipher_as_block_cipher.dart'; -import 'package:pointycastle/stream/ctr.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -class CTRBlockCipher extends StreamCipherAsBlockCipher { - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - BlockCipher, - '/CTR', - (_, final Match match) => () { - var underlying = BlockCipher(match.group(1)!); - return CTRBlockCipher( - underlying.blockSize, CTRStreamCipher(underlying)); - }); - - CTRBlockCipher(super.blockSize, super.underlyingCipher); -} diff --git a/pointycastle/lib/block/modes/ecb.dart b/pointycastle/lib/block/modes/ecb.dart deleted file mode 100644 index 039585f..0000000 --- a/pointycastle/lib/block/modes/ecb.dart +++ /dev/null @@ -1,43 +0,0 @@ -// See file LICENSE for more information. - -library impl.block_cipher.modes.ecb; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/impl/base_block_cipher.dart'; - -/// Implementation of Electronic Code Book (ECB) mode on top of a [BlockCipher]. -class ECBBlockCipher extends BaseBlockCipher { - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - BlockCipher, - '/ECB', - (_, final Match match) => () { - var underlying = BlockCipher(match.group(1)!); - return ECBBlockCipher(underlying); - }); - - final BlockCipher _underlyingCipher; - - ECBBlockCipher(this._underlyingCipher); - - @override - String get algorithmName => '${_underlyingCipher.algorithmName}/ECB'; - @override - int get blockSize => _underlyingCipher.blockSize; - @override - void reset() { - _underlyingCipher.reset(); - } - - @override - void init(bool forEncryption, CipherParameters? params) { - _underlyingCipher.init(forEncryption, params); - } - - @override - int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) => - _underlyingCipher.processBlock(inp, inpOff, out, outOff); -} diff --git a/pointycastle/lib/block/modes/gcm.dart b/pointycastle/lib/block/modes/gcm.dart deleted file mode 100644 index b46b33a..0000000 --- a/pointycastle/lib/block/modes/gcm.dart +++ /dev/null @@ -1,226 +0,0 @@ -library impl.block_cipher.modes.gcm; - -import 'dart:math' show min; -import 'dart:typed_data'; - -import 'package:pointycastle/src/ct.dart'; - -import '../../api.dart'; -import '../../src/impl/base_aead_block_cipher.dart'; -import '../../src/registry/registry.dart'; - -class GCMBlockCipher extends BaseAEADBlockCipher { - /// Intended for internal use. - // ignore: non_constant_identifier_names - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - BlockCipher, - '/GCM', - (_, final Match match) => () { - var underlying = BlockCipher(match.group(1)!); - return GCMBlockCipher(underlying); - }); - - late Uint8List _h; - late Uint8List _counter; - late Uint8List _e; - late Uint8List _e0; - late Uint8List _x; - late int _processedBytes; - int _blocksRemaining = 0; - - GCMBlockCipher(super.cipher); - - @override - String get algorithmName => '${underlyingCipher.algorithmName}/GCM'; - - @override - void init(bool forEncryption, CipherParameters? params) { - var bs = underlyingCipher.blockSize; - _blocksRemaining = (2 ^ 36 - 64) ~/ bs; - super.init(forEncryption, params); - } - - @override - void reset() { - var bs = underlyingCipher.blockSize; - _blocksRemaining = (2 ^ 36 - 64) ~/ bs; - super.reset(); - } - - @override - void prepare(KeyParameter keyParam) { - if (macSize != 16) { - throw ArgumentError('macSize should be equal to 16 for GCM'); - } - - underlyingCipher.init(true, keyParam); - - _h = Uint8List(blockSize); - underlyingCipher.processBlock(_h, 0, _h, 0); - - _counter = _computeInitialCounter(nonce); - - _e0 = Uint8List(16); - _computeE(_counter, _e0); - - _e = Uint8List(16); - - _x = Uint8List(16); - - _processedBytes = 0; - } - - Uint8List _computeInitialCounter(Uint8List iv) { - var counter = Uint8List(16); - - if (iv.length == 12) { - counter.setAll(0, iv); - counter[15] = 1; - } else { - _gHASH(counter, iv); - var length = Uint8List.view((Uint32List(4)..[0] = iv.length * 8).buffer); - length = Uint8List.fromList(length.reversed.toList()); - - _gHASHBlock(counter, length); - } - return counter; - } - - @override - int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { - var length = - blockSize < inp.length - inpOff ? blockSize : inp.length - inpOff; - - var i = Uint8List(blockSize); - i.setAll(0, inp.skip(inpOff).take(length)); - - _processedBytes += length; - - _getNextCTRBlock(_e); - - var o = Uint8List.fromList(i); - _xor(o, _e); - if (length < blockSize) o.fillRange(length, blockSize, 0); - - out.setRange(outOff, outOff + length, o); - - var c = forEncryption ? o : i; - - _gHASHBlock(_x, c); - - return length; - } - - void _gHASH(Uint8List x, Uint8List y) { - var block = Uint8List(16); - for (var i = 0; i < y.length; i += 16) { - block.setAll(0, y.sublist(i, min(i + 16, y.length))); - block.fillRange(min(i + 16, y.length) - i, 16, 0); - _gHASHBlock(x, block); - } - } - - void _gHASHBlock(Uint8List x, Uint8List y) { - _xor(x, y); - _mult(x, _h); - } - - void _getNextCTRBlock(Uint8List out) { - // - // This is tested manually by forcing _blocksRemaining to 1 and trying to run - // the unit tests. Otherwise it takes 64GB of data to exhaust. - // - if (_blocksRemaining == 0) { - throw StateError('Attempt to process too many blocks'); - } - _blocksRemaining--; - - _counter[15]++; - for (var i = 15; i >= 12 && _counter[i] == 0; i--) { - _counter[i] = 0; - if (i > 12) _counter[i - 1]++; - } - _computeE(_counter, out); - } - - void _computeE(Uint8List inp, Uint8List out) { - underlyingCipher.processBlock(inp, 0, out, 0); - } - - final Uint8List r = Uint8List(16)..[0] = 0xe1; - - void _mult(Uint8List x, Uint8List y) { - var v = x; - var z = Uint8List(x.length); - - for (var i = 0; i < 128; i++) { - CT_xor(z, v, _bit(y, i)); - CT_xor(v, r, _shiftRight(v)); - } - - x.setAll(0, z); - } - - void _xor(Uint8List x, Uint8List? y) { - for (var i = 0; i < x.length; i++) { - x[i] ^= y![i]; - } - } - - bool _bit(Uint8List x, int n) { - var byte = n ~/ 8; - var mask = 1 << (7 - n % 8); - return x[byte] & mask == mask; - } - - bool _shiftRight(Uint8List x) { - var overflow = false; - for (var i = 0; i < x.length; i++) { - var nextOverflow = x[i] & 0x1 == 0x1; - x[i] >>= 1; - if (overflow) x[i] |= 0x80; - overflow = nextOverflow; - } - return overflow; - } - - @override - int doFinal(Uint8List out, int outOff) { - var result = remainingInput.isNotEmpty - ? processBlock(remainingInput, 0, out, outOff) - : 0; - - var len = Uint8List.view((Uint32List(4) - ..[2] = aad!.length * 8 - ..[0] = _processedBytes * 8) - .buffer); - len = Uint8List.fromList(len.reversed.toList()); - - _gHASHBlock(_x, len); - - _xor(_x, _e0); - - if (forEncryption) { - out.setAll(outOff + result, _x); - result += _x.length; - } - - validateMac(); - - return result; - } - - @override - Uint8List get mac => _x; - - @override - void processAADBytes(Uint8List inp, int inpOff, int len) { - var block = Uint8List(16); - for (var i = 0; i < len; i += 16) { - block.fillRange(0, 16, 0); - block.setAll( - 0, inp.sublist(inpOff + i, inpOff + min(i + 16, len) as int)); - _gHASHBlock(_x, block); - } - } -} diff --git a/pointycastle/lib/block/modes/gctr.dart b/pointycastle/lib/block/modes/gctr.dart deleted file mode 100644 index 8ebba7e..0000000 --- a/pointycastle/lib/block/modes/gctr.dart +++ /dev/null @@ -1,144 +0,0 @@ -// See file LICENSE for more information. - -library impl.block_cipher.modes.gctr; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_block_cipher.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of GOST 28147 OFB counter mode (GCTR) on top of a [BlockCipher]. -class GCTRBlockCipher extends BaseBlockCipher { - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - BlockCipher, - '/GCTR', - (_, final Match match) => () { - var underlying = BlockCipher(match.group(1)!); - return GCTRBlockCipher(underlying); - }); - - static const C1 = 16843012; //00000001000000010000000100000100 - static const C2 = 16843009; //00000001000000010000000100000001 - - final BlockCipher _underlyingCipher; - - late Uint8List _iv; - Uint8List? _ofbV; - Uint8List? _ofbOutV; - - bool _firstStep = true; - late int _n3; - late int _n4; - - GCTRBlockCipher(this._underlyingCipher) { - if (blockSize != 8) { - throw ArgumentError('GCTR can only be used with 64 bit block ciphers'); - } - - _iv = Uint8List(_underlyingCipher.blockSize); - _ofbV = Uint8List(_underlyingCipher.blockSize); - _ofbOutV = Uint8List(_underlyingCipher.blockSize); - } - - @override - int get blockSize => _underlyingCipher.blockSize; - @override - String get algorithmName => '${_underlyingCipher.algorithmName}/GCTR'; - @override - void reset() { - _ofbV!.setRange(0, _iv.length, _iv); - _underlyingCipher.reset(); - } - - /// Initialise the cipher and, possibly, the initialisation vector (IV). - /// If an IV isn't passed as part of the parameter, the IV will be all zeros. - /// An IV which is too short is handled in FIPS compliant fashion. - /// - /// @param encrypting if true the cipher is initialised for - /// encryption, if false for decryption. //ignored by this CTR mode - /// @param params the key and other data required by the cipher. - /// @exception IllegalArgumentException if the params argument is - /// inappropriate. - @override - void init(bool encrypting, CipherParameters? params) { - _firstStep = true; - _n3 = 0; - _n4 = 0; - - if (params is ParametersWithIV) { - var ivParam = params; - var iv = ivParam.iv; - - if (iv.length < _iv.length) { - // prepend the supplied IV with zeros (per FIPS PUB 81) - var offset = _iv.length - iv.length; - _iv.fillRange(0, offset, 0); - _iv.setRange(offset, _iv.length, iv); - } else { - _iv.setRange(0, _iv.length, iv); - } - - reset(); - - // if params is null we reuse the current working key. - if (ivParam.parameters != null) { - _underlyingCipher.init(true, ivParam.parameters); - } - } else { - // TODO: make this behave in a standard way (as the other modes of operation) - reset(); - - // if params is null we reuse the current working key. - if (params != null) { - _underlyingCipher.init(true, params); - } - } - } - - @override - int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { - if ((inpOff + blockSize) > inp.length) { - throw ArgumentError('Input buffer too short'); - } - - if ((outOff + blockSize) > out.length) { - throw ArgumentError('Output buffer too short'); - } - - if (_firstStep) { - _firstStep = false; - _underlyingCipher.processBlock(_ofbV!, 0, _ofbOutV!, 0); - _n3 = _bytesToint(_ofbOutV, 0); - _n4 = _bytesToint(_ofbOutV, 4); - } - _n3 += C2; - _n4 += C1; - _intTobytes(_n3, _ofbV, 0); - _intTobytes(_n4, _ofbV, 4); - - _underlyingCipher.processBlock(_ofbV!, 0, _ofbOutV!, 0); - - // XOR the ofbV with the plaintext producing the cipher text (and the next input block). - for (var i = 0; i < blockSize; i++) { - out[outOff + i] = _ofbOutV![i] ^ inp[inpOff + i]; - } - - // change over the input block. - var offset = _ofbV!.length - blockSize; - _ofbV!.setRange(0, offset, _ofbV!.sublist(blockSize)); - _ofbV!.setRange(offset, _ofbV!.length, _ofbOutV!); - - return blockSize; - } - - int _bytesToint(Uint8List? inp, int inpOff) { - return unpack32(inp, inpOff, Endian.little); - } - - void _intTobytes(int num, Uint8List? out, int outOff) { - pack32(num, out, outOff, Endian.little); - } -} diff --git a/pointycastle/lib/block/modes/ige.dart b/pointycastle/lib/block/modes/ige.dart deleted file mode 100644 index 84c3003..0000000 --- a/pointycastle/lib/block/modes/ige.dart +++ /dev/null @@ -1,117 +0,0 @@ -// See file LICENSE for more information. - -library impl.block_cipher.modes.ige; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/impl/base_block_cipher.dart'; -import 'package:pointycastle/src/utils.dart'; - -/// Implementation of IGE mode on top of a [BlockCipher]. -/// -/// This mode is not commonly used aside from as a critical building block in -/// the Telegram protocol. -class IGEBlockCipher extends BaseBlockCipher { - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - BlockCipher, - '/IGE', - (_, final Match match) => () { - var underlying = BlockCipher(match.group(1)!); - return IGEBlockCipher(underlying); - }); - - final BlockCipher _underlyingCipher; - - late Uint8List _x0, _y0, _xPrev, _yPrev; - - late bool _encrypting; - - /// Instantiates an IGEBlockCipher, using [_underlyingCipher] as the basis - /// for chaining encryption/decryption. - IGEBlockCipher(this._underlyingCipher) { - _x0 = Uint8List(blockSize); - _y0 = Uint8List(blockSize); - _xPrev = Uint8List(blockSize); - _yPrev = Uint8List(blockSize); - } - - @override - String get algorithmName => '${_underlyingCipher.algorithmName}/IGE'; - - @override - int get blockSize => _underlyingCipher.blockSize; - - @override - void reset() { - arrayCopy(_x0, 0, _xPrev, 0, blockSize); - arrayCopy(_y0, 0, _yPrev, 0, blockSize); - - _underlyingCipher.reset(); - } - - @override - void init(bool forEncryption, covariant ParametersWithIV params) { - if (params.iv.length != blockSize * 2) { - throw ArgumentError( - 'Initialization vector must be the same length as block size'); - } - - _encrypting = forEncryption; - arrayCopy(params.iv, 0, _x0, 0, blockSize); - arrayCopy(params.iv, blockSize, _y0, 0, blockSize); - - reset(); - - _underlyingCipher.init(forEncryption, params.parameters); - } - - @override - int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) => - _encrypting - ? _encryptBlock(inp, inpOff, out, outOff) - : _decryptBlock(inp, inpOff, out, outOff); - - int _encryptBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { - if ((inpOff + blockSize) > inp.length) { - throw ArgumentError('Input buffer too short'); - } - - for (var i = 0; i < blockSize; i++) { - _xPrev[i] ^= inp[inpOff + i]; - } - - var length = _underlyingCipher.processBlock(_xPrev, 0, out, outOff); - - for (var i = 0; i < blockSize; i++) { - out[outOff + i] ^= _yPrev[i]; - } - - arrayCopy(inp, inpOff, _yPrev, 0, blockSize); - arrayCopy(out, outOff, _xPrev, 0, blockSize); - - return length; - } - - int _decryptBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { - if ((inpOff + blockSize) > inp.length) { - throw ArgumentError('Input buffer too short'); - } - - for (var i = 0; i < blockSize; i++) { - _yPrev[i] ^= inp[inpOff + i]; - } - - var length = _underlyingCipher.processBlock(_yPrev, 0, out, outOff); - - for (var i = 0; i < blockSize; i++) { - out[outOff + i] ^= _xPrev[i]; - } - - arrayCopy(out, outOff, _yPrev, 0, blockSize); - arrayCopy(inp, inpOff, _xPrev, 0, blockSize); - - return length; - } -} diff --git a/pointycastle/lib/block/modes/ofb.dart b/pointycastle/lib/block/modes/ofb.dart deleted file mode 100644 index 44018f9..0000000 --- a/pointycastle/lib/block/modes/ofb.dart +++ /dev/null @@ -1,104 +0,0 @@ -// See file LICENSE for more information. - -library impl.block_cipher.modes.ofb; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/impl/base_block_cipher.dart'; - -/// Implementation of Output FeedBack mode (OFB) on top of a [BlockCipher]. -class OFBBlockCipher extends BaseBlockCipher { - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig.regex( - BlockCipher, - r'^(.+)/OFB-([0-9]+)$', - (_, final Match match) => () { - var underlying = BlockCipher(match.group(1)!); - var blockSizeInBits = int.parse(match.group(2)!); - if ((blockSizeInBits % 8) != 0) { - throw RegistryFactoryException.invalid( - 'Bad OFB block size: $blockSizeInBits (must be a multiple of 8)'); - } - return OFBBlockCipher(underlying, blockSizeInBits ~/ 8); - }); - - @override - final int blockSize; - - final BlockCipher _underlyingCipher; - - late Uint8List _iv; - Uint8List? _ofbV; - Uint8List? _ofbOutV; - - OFBBlockCipher(this._underlyingCipher, this.blockSize) { - _iv = Uint8List(_underlyingCipher.blockSize); - _ofbV = Uint8List(_underlyingCipher.blockSize); - _ofbOutV = Uint8List(_underlyingCipher.blockSize); - } - - @override - String get algorithmName => - '${_underlyingCipher.algorithmName}/OFB-${blockSize * 8}'; - - @override - void reset() { - _ofbV!.setRange(0, _iv.length, _iv); - _underlyingCipher.reset(); - } - - /// Initialise the cipher and, possibly, the initialisation vector (IV). If an IV isn't passed as part of the parameter, the - /// IV will be all zeros. An IV which is too short is handled in FIPS compliant fashion. - @override - void init(bool forEncryption, CipherParameters? params) { - if (params is ParametersWithIV) { - var ivParam = params; - var iv = ivParam.iv; - - if (iv.length < _iv.length) { - // prepend the supplied IV with zeros (per FIPS PUB 81) - var offset = _iv.length - iv.length; - _iv.fillRange(0, offset, 0); - _iv.setAll(offset, iv); - } else { - _iv.setRange(0, _iv.length, iv); - } - - reset(); - - // if null it's an IV changed only. - if (ivParam.parameters != null) { - _underlyingCipher.init(true, ivParam.parameters); - } - } else { - _underlyingCipher.init(true, params); - } - } - - @override - int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { - if ((inpOff + blockSize) > inp.length) { - throw ArgumentError('Input buffer too short'); - } - - if ((outOff + blockSize) > out.length) { - throw ArgumentError('Output buffer too short'); - } - - _underlyingCipher.processBlock(_ofbV!, 0, _ofbOutV!, 0); - - // XOR the ofbV with the plaintext producing the cipher text (and the next input block). - for (var i = 0; i < blockSize; i++) { - out[outOff + i] = _ofbOutV![i] ^ inp[inpOff + i]; - } - - // change over the input block. - var offset = _ofbV!.length - blockSize; - _ofbV!.setRange(0, offset, _ofbV!.sublist(blockSize)); - _ofbV!.setRange(offset, _ofbV!.length, _ofbOutV!); - - return blockSize; - } -} diff --git a/pointycastle/lib/block/modes/sic.dart b/pointycastle/lib/block/modes/sic.dart deleted file mode 100644 index 035ae67..0000000 --- a/pointycastle/lib/block/modes/sic.dart +++ /dev/null @@ -1,23 +0,0 @@ -// See file LICENSE for more information. - -library impl.block_cipher.modes.sic; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/adapters/stream_cipher_as_block_cipher.dart'; -import 'package:pointycastle/stream/sic.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// See [SICStreamCipher]. -class SICBlockCipher extends StreamCipherAsBlockCipher { - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - BlockCipher, - '/SIC', - (_, final Match match) => () { - var underlying = BlockCipher(match.group(1)!); - return SICBlockCipher( - underlying.blockSize, SICStreamCipher(underlying)); - }); - - SICBlockCipher(super.blockSize, super.underlyingCipher); -} diff --git a/pointycastle/lib/block/rc2_engine.dart b/pointycastle/lib/block/rc2_engine.dart deleted file mode 100644 index 4e7a919..0000000 --- a/pointycastle/lib/block/rc2_engine.dart +++ /dev/null @@ -1,498 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_block_cipher.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -class RC2Engine extends BaseBlockCipher { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(BlockCipher, 'RC2', () => RC2Engine()); - - static Uint8List piTable = Uint8List.fromList([ - 0xd9, - 0x78, - 0xf9, - 0xc4, - 0x19, - 0xdd, - 0xb5, - 0xed, - 0x28, - 0xe9, - 0xfd, - 0x79, - 0x4a, - 0xa0, - 0xd8, - 0x9d, - 0xc6, - 0x7e, - 0x37, - 0x83, - 0x2b, - 0x76, - 0x53, - 0x8e, - 0x62, - 0x4c, - 0x64, - 0x88, - 0x44, - 0x8b, - 0xfb, - 0xa2, - 0x17, - 0x9a, - 0x59, - 0xf5, - 0x87, - 0xb3, - 0x4f, - 0x13, - 0x61, - 0x45, - 0x6d, - 0x8d, - 0x09, - 0x81, - 0x7d, - 0x32, - 0xbd, - 0x8f, - 0x40, - 0xeb, - 0x86, - 0xb7, - 0x7b, - 0x0b, - 0xf0, - 0x95, - 0x21, - 0x22, - 0x5c, - 0x6b, - 0x4e, - 0x82, - 0x54, - 0xd6, - 0x65, - 0x93, - 0xce, - 0x60, - 0xb2, - 0x1c, - 0x73, - 0x56, - 0xc0, - 0x14, - 0xa7, - 0x8c, - 0xf1, - 0xdc, - 0x12, - 0x75, - 0xca, - 0x1f, - 0x3b, - 0xbe, - 0xe4, - 0xd1, - 0x42, - 0x3d, - 0xd4, - 0x30, - 0xa3, - 0x3c, - 0xb6, - 0x26, - 0x6f, - 0xbf, - 0x0e, - 0xda, - 0x46, - 0x69, - 0x07, - 0x57, - 0x27, - 0xf2, - 0x1d, - 0x9b, - 0xbc, - 0x94, - 0x43, - 0x03, - 0xf8, - 0x11, - 0xc7, - 0xf6, - 0x90, - 0xef, - 0x3e, - 0xe7, - 0x06, - 0xc3, - 0xd5, - 0x2f, - 0xc8, - 0x66, - 0x1e, - 0xd7, - 0x08, - 0xe8, - 0xea, - 0xde, - 0x80, - 0x52, - 0xee, - 0xf7, - 0x84, - 0xaa, - 0x72, - 0xac, - 0x35, - 0x4d, - 0x6a, - 0x2a, - 0x96, - 0x1a, - 0xd2, - 0x71, - 0x5a, - 0x15, - 0x49, - 0x74, - 0x4b, - 0x9f, - 0xd0, - 0x5e, - 0x04, - 0x18, - 0xa4, - 0xec, - 0xc2, - 0xe0, - 0x41, - 0x6e, - 0x0f, - 0x51, - 0xcb, - 0xcc, - 0x24, - 0x91, - 0xaf, - 0x50, - 0xa1, - 0xf4, - 0x70, - 0x39, - 0x99, - 0x7c, - 0x3a, - 0x85, - 0x23, - 0xb8, - 0xb4, - 0x7a, - 0xfc, - 0x02, - 0x36, - 0x5b, - 0x25, - 0x55, - 0x97, - 0x31, - 0x2d, - 0x5d, - 0xfa, - 0x98, - 0xe3, - 0x8a, - 0x92, - 0xae, - 0x05, - 0xdf, - 0x29, - 0x10, - 0x67, - 0x6c, - 0xba, - 0xc9, - 0xd3, - 0x00, - 0xe6, - 0xcf, - 0xe1, - 0x9e, - 0xa8, - 0x2c, - 0x63, - 0x16, - 0x01, - 0x3f, - 0x58, - 0xe2, - 0x89, - 0xa9, - 0x0d, - 0x38, - 0x34, - 0x1b, - 0xab, - 0x33, - 0xff, - 0xb0, - 0xbb, - 0x48, - 0x0c, - 0x5f, - 0xb9, - 0xb1, - 0xcd, - 0x2e, - 0xc5, - 0xf3, - 0xdb, - 0x47, - 0xe5, - 0xa5, - 0x9c, - 0x77, - 0x0a, - 0xa6, - 0x20, - 0x68, - 0xfe, - 0x7f, - 0xc1, - 0xad - ]); - - static const BLOCK_SIZE = 8; - - @override - String get algorithmName => 'RC2'; - - @override - int get blockSize => BLOCK_SIZE; - - bool forEncryption = false; - List? workingKey; - - List generateWorkingKey(Uint8List key, int bits) { - int x; - var xKey = List.generate(128, (index) => 0); - - for (var i = 0; i != key.length; i++) { - xKey[i] = key[i] & 0xff; - } - - // Phase 1: Expand input key to 128 bytes - var len = key.length; - - if (len < 128) { - var index = 0; - - x = xKey[len - 1]; - - do { - x = piTable[(x + xKey[index++]) & 255] & 0xff; - xKey[len++] = x; - } while (len < 128); - } - - // Phase 2 - reduce effective key size to "bits" - len = (bits + 7) >> 3; - x = piTable[xKey[128 - len] & (255 >> (7 & -bits))] & 0xff; - xKey[128 - len] = x; - - for (var i = 128 - len - 1; i >= 0; i--) { - x = piTable[x ^ xKey[i + len]] & 0xff; - xKey[i] = x; - } - - // Phase 3 - copy to newKey in little-endian order - var newKey = List.generate(64, (index) => 0); - - for (var i = 0; i != newKey.length; i++) { - newKey[i] = xKey[2 * i] + (xKey[2 * i + 1] << 8); - } - - return newKey; - } - - @override - void init(bool forEncryption, CipherParameters? params) { - this.forEncryption = forEncryption; - - Uint8List key; - if (params != null) { - if (params is RC2Parameters) { - workingKey = generateWorkingKey(params.key, params.effectiveKeyBits); - key = params.key; - } else if (params is KeyParameter) { - key = params.key; - workingKey = generateWorkingKey(key, key.length * 8); - } - } - } - - @override - Uint8List process(Uint8List data) { - var out = Uint8List(blockSize); - var len = processBlock(data, 0, out, 0); - return out.sublist(0, len); - } - - @override - int processBlock(Uint8List input, int inputOff, Uint8List out, int outOff) { - if (workingKey == null) { - throw ArgumentError('RC2 engine not initialised'); - } - - if ((inputOff + BLOCK_SIZE) > input.length) { - throw ArgumentError('input buffer too short'); - } - - if ((outOff + BLOCK_SIZE) > out.length) { - throw ArgumentError('output buffer too short'); - } - - if (forEncryption) { - encryptBlock(input, inputOff, out, outOff); - } else { - decryptBlock(input, inputOff, out, outOff); - } - - return BLOCK_SIZE; - } - - @override - void reset() {} - - int rotateWordLeft(int x, int y) { - x &= 0xffff; - return (x << y) | (x >> (16 - y)); - } - - void encryptBlock(Uint8List input, int inOff, Uint8List out, int outOff) { - int x76, x54, x32, x10; - - x76 = ((input[inOff + 7] & 0xff) << 8) + (input[inOff + 6] & 0xff); - x54 = ((input[inOff + 5] & 0xff) << 8) + (input[inOff + 4] & 0xff); - x32 = ((input[inOff + 3] & 0xff) << 8) + (input[inOff + 2] & 0xff); - x10 = ((input[inOff + 1] & 0xff) << 8) + (input[inOff + 0] & 0xff); - - for (var i = 0; i <= 16; i += 4) { - x10 = - rotateWordLeft(x10 + (x32 & ~x76) + (x54 & x76) + workingKey![i], 1); - x32 = rotateWordLeft( - x32 + (x54 & ~x10) + (x76 & x10) + workingKey![i + 1], 2); - x54 = rotateWordLeft( - x54 + (x76 & ~x32) + (x10 & x32) + workingKey![i + 2], 3); - x76 = rotateWordLeft( - x76 + (x10 & ~x54) + (x32 & x54) + workingKey![i + 3], 5); - } - - x10 += workingKey![x76 & 63]; - x32 += workingKey![x10 & 63]; - x54 += workingKey![x32 & 63]; - x76 += workingKey![x54 & 63]; - - for (var i = 20; i <= 40; i += 4) { - x10 = - rotateWordLeft(x10 + (x32 & ~x76) + (x54 & x76) + workingKey![i], 1); - x32 = rotateWordLeft( - x32 + (x54 & ~x10) + (x76 & x10) + workingKey![i + 1], 2); - x54 = rotateWordLeft( - x54 + (x76 & ~x32) + (x10 & x32) + workingKey![i + 2], 3); - x76 = rotateWordLeft( - x76 + (x10 & ~x54) + (x32 & x54) + workingKey![i + 3], 5); - } - - x10 += workingKey![x76 & 63]; - x32 += workingKey![x10 & 63]; - x54 += workingKey![x32 & 63]; - x76 += workingKey![x54 & 63]; - - for (var i = 44; i < 64; i += 4) { - x10 = - rotateWordLeft(x10 + (x32 & ~x76) + (x54 & x76) + workingKey![i], 1); - x32 = rotateWordLeft( - x32 + (x54 & ~x10) + (x76 & x10) + workingKey![i + 1], 2); - x54 = rotateWordLeft( - x54 + (x76 & ~x32) + (x10 & x32) + workingKey![i + 2], 3); - x76 = rotateWordLeft( - x76 + (x10 & ~x54) + (x32 & x54) + workingKey![i + 3], 5); - } - - out[outOff + 0] = x10; - out[outOff + 1] = x10 >> 8; - out[outOff + 2] = x32; - out[outOff + 3] = x32 >> 8; - out[outOff + 4] = x54; - out[outOff + 5] = x54 >> 8; - out[outOff + 6] = x76; - out[outOff + 7] = x76 >> 8; - } - - void decryptBlock(Uint8List input, int inOff, Uint8List out, int outOff) { - int x76, x54, x32, x10; - - x76 = ((input[inOff + 7] & 0xff) << 8) + (input[inOff + 6] & 0xff); - x54 = ((input[inOff + 5] & 0xff) << 8) + (input[inOff + 4] & 0xff); - x32 = ((input[inOff + 3] & 0xff) << 8) + (input[inOff + 2] & 0xff); - x10 = ((input[inOff + 1] & 0xff) << 8) + (input[inOff + 0] & 0xff); - - for (var i = 60; i >= 44; i -= 4) { - x76 = rotateWordLeft(x76, 11) - - ((x10 & ~x54) + (x32 & x54) + workingKey![i + 3]); - x54 = rotateWordLeft(x54, 13) - - ((x76 & ~x32) + (x10 & x32) + workingKey![i + 2]); - x32 = rotateWordLeft(x32, 14) - - ((x54 & ~x10) + (x76 & x10) + workingKey![i + 1]); - x10 = rotateWordLeft(x10, 15) - - ((x32 & ~x76) + (x54 & x76) + workingKey![i]); - } - - x76 -= workingKey![x54 & 63]; - x54 -= workingKey![x32 & 63]; - x32 -= workingKey![x10 & 63]; - x10 -= workingKey![x76 & 63]; - - for (var i = 40; i >= 20; i -= 4) { - x76 = rotateWordLeft(x76, 11) - - ((x10 & ~x54) + (x32 & x54) + workingKey![i + 3]); - x54 = rotateWordLeft(x54, 13) - - ((x76 & ~x32) + (x10 & x32) + workingKey![i + 2]); - x32 = rotateWordLeft(x32, 14) - - ((x54 & ~x10) + (x76 & x10) + workingKey![i + 1]); - x10 = rotateWordLeft(x10, 15) - - ((x32 & ~x76) + (x54 & x76) + workingKey![i]); - } - - x76 -= workingKey![x54 & 63]; - x54 -= workingKey![x32 & 63]; - x32 -= workingKey![x10 & 63]; - x10 -= workingKey![x76 & 63]; - - for (var i = 16; i >= 0; i -= 4) { - x76 = rotateWordLeft(x76, 11) - - ((x10 & ~x54) + (x32 & x54) + workingKey![i + 3]); - x54 = rotateWordLeft(x54, 13) - - ((x76 & ~x32) + (x10 & x32) + workingKey![i + 2]); - x32 = rotateWordLeft(x32, 14) - - ((x54 & ~x10) + (x76 & x10) + workingKey![i + 1]); - x10 = rotateWordLeft(x10, 15) - - ((x32 & ~x76) + (x54 & x76) + workingKey![i]); - } - - out[outOff + 0] = x10; - out[outOff + 1] = x10 >> 8; - out[outOff + 2] = x32; - out[outOff + 3] = x32 >> 8; - out[outOff + 4] = x54; - out[outOff + 5] = x54 >> 8; - out[outOff + 6] = x76; - out[outOff + 7] = x76 >> 8; - } -} diff --git a/pointycastle/lib/block/twofish.dart b/pointycastle/lib/block/twofish.dart deleted file mode 100644 index f78eb17..0000000 --- a/pointycastle/lib/block/twofish.dart +++ /dev/null @@ -1,694 +0,0 @@ -// See file LICENSE for more information. - -library impl.block_cipher.twofish; - -import 'dart:core'; -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_block_cipher.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// A class that provides Twofish encryption operations. -/// Author Nguyen Van Nguyen -class TwofishEngine extends BaseBlockCipher { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - BlockCipher, - 'Twofish', - () => TwofishEngine(), - ); - - /// Q-Table 0 - static const _q0 = [ - 0xa9, 0x67, 0xb3, 0xe8, 0x04, 0xfd, 0xa3, 0x76, // 0 - 7 - 0x9a, 0x92, 0x80, 0x78, 0xe4, 0xdd, 0xd1, 0x38, - 0x0d, 0xc6, 0x35, 0x98, 0x18, 0xf7, 0xec, 0x6c, - 0x43, 0x75, 0x37, 0x26, 0xfa, 0x13, 0x94, 0x48, - 0xf2, 0xd0, 0x8b, 0x30, 0x84, 0x54, 0xdf, 0x23, - 0x19, 0x5b, 0x3d, 0x59, 0xf3, 0xae, 0xa2, 0x82, - 0x63, 0x01, 0x83, 0x2e, 0xd9, 0x51, 0x9b, 0x7c, - 0xa6, 0xeb, 0xa5, 0xbe, 0x16, 0x0c, 0xe3, 0x61, - 0xc0, 0x8c, 0x3a, 0xf5, 0x73, 0x2c, 0x25, 0x0b, - 0xbb, 0x4e, 0x89, 0x6b, 0x53, 0x6a, 0xb4, 0xf1, - 0xe1, 0xe6, 0xbd, 0x45, 0xe2, 0xf4, 0xb6, 0x66, - 0xcc, 0x95, 0x03, 0x56, 0xd4, 0x1c, 0x1e, 0xd7, - 0xfb, 0xc3, 0x8e, 0xb5, 0xe9, 0xcf, 0xbf, 0xba, - 0xea, 0x77, 0x39, 0xaf, 0x33, 0xc9, 0x62, 0x71, - 0x81, 0x79, 0x09, 0xad, 0x24, 0xcd, 0xf9, 0xd8, - 0xe5, 0xc5, 0xb9, 0x4d, 0x44, 0x08, 0x86, 0xe7, - 0xa1, 0x1d, 0xaa, 0xed, 0x06, 0x70, 0xb2, 0xd2, - 0x41, 0x7b, 0xa0, 0x11, 0x31, 0xc2, 0x27, 0x90, - 0x20, 0xf6, 0x60, 0xff, 0x96, 0x5c, 0xb1, 0xab, - 0x9e, 0x9c, 0x52, 0x1b, 0x5f, 0x93, 0x0a, 0xef, - 0x91, 0x85, 0x49, 0xee, 0x2d, 0x4f, 0x8f, 0x3b, - 0x47, 0x87, 0x6d, 0x46, 0xd6, 0x3e, 0x69, 0x64, - 0x2a, 0xce, 0xcb, 0x2f, 0xfc, 0x97, 0x05, 0x7a, - 0xac, 0x7f, 0xd5, 0x1a, 0x4b, 0x0e, 0xa7, 0x5a, - 0x28, 0x14, 0x3f, 0x29, 0x88, 0x3c, 0x4c, 0x02, - 0xb8, 0xda, 0xb0, 0x17, 0x55, 0x1f, 0x8a, 0x7d, - 0x57, 0xc7, 0x8d, 0x74, 0xb7, 0xc4, 0x9f, 0x72, - 0x7e, 0x15, 0x22, 0x12, 0x58, 0x07, 0x99, 0x34, - 0x6e, 0x50, 0xde, 0x68, 0x65, 0xbc, 0xdb, 0xf8, - 0xc8, 0xa8, 0x2b, 0x40, 0xdc, 0xfe, 0x32, 0xa4, - 0xca, 0x10, 0x21, 0xf0, 0xd3, 0x5d, 0x0f, 0x00, - 0x6f, 0x9d, 0x36, 0x42, 0x4a, 0x5e, 0xc1, 0xe0 - ]; - - /// Q-Table 1 - static const _q1 = [ - 0x75, 0xf3, 0xc6, 0xf4, 0xdb, 0x7b, 0xfb, 0xc8, // 0 - 7 - 0x4a, 0xd3, 0xe6, 0x6b, 0x45, 0x7d, 0xe8, 0x4b, - 0xd6, 0x32, 0xd8, 0xfd, 0x37, 0x71, 0xf1, 0xe1, - 0x30, 0x0f, 0xf8, 0x1b, 0x87, 0xfa, 0x06, 0x3f, - 0x5e, 0xba, 0xae, 0x5b, 0x8a, 0x00, 0xbc, 0x9d, - 0x6d, 0xc1, 0xb1, 0x0e, 0x80, 0x5d, 0xd2, 0xd5, - 0xa0, 0x84, 0x07, 0x14, 0xb5, 0x90, 0x2c, 0xa3, - 0xb2, 0x73, 0x4c, 0x54, 0x92, 0x74, 0x36, 0x51, - 0x38, 0xb0, 0xbd, 0x5a, 0xfc, 0x60, 0x62, 0x96, - 0x6c, 0x42, 0xf7, 0x10, 0x7c, 0x28, 0x27, 0x8c, - 0x13, 0x95, 0x9c, 0xc7, 0x24, 0x46, 0x3b, 0x70, - 0xca, 0xe3, 0x85, 0xcb, 0x11, 0xd0, 0x93, 0xb8, - 0xa6, 0x83, 0x20, 0xff, 0x9f, 0x77, 0xc3, 0xcc, - 0x03, 0x6f, 0x08, 0xbf, 0x40, 0xe7, 0x2b, 0xe2, - 0x79, 0x0c, 0xaa, 0x82, 0x41, 0x3a, 0xea, 0xb9, - 0xe4, 0x9a, 0xa4, 0x97, 0x7e, 0xda, 0x7a, 0x17, - 0x66, 0x94, 0xa1, 0x1d, 0x3d, 0xf0, 0xde, 0xb3, - 0x0b, 0x72, 0xa7, 0x1c, 0xef, 0xd1, 0x53, 0x3e, - 0x8f, 0x33, 0x26, 0x5f, 0xec, 0x76, 0x2a, 0x49, - 0x81, 0x88, 0xee, 0x21, 0xc4, 0x1a, 0xeb, 0xd9, - 0xc5, 0x39, 0x99, 0xcd, 0xad, 0x31, 0x8b, 0x01, - 0x18, 0x23, 0xdd, 0x1f, 0x4e, 0x2d, 0xf9, 0x48, - 0x4f, 0xf2, 0x65, 0x8e, 0x78, 0x5c, 0x58, 0x19, - 0x8d, 0xe5, 0x98, 0x57, 0x67, 0x7f, 0x05, 0x64, - 0xaf, 0x63, 0xb6, 0xfe, 0xf5, 0xb7, 0x3c, 0xa5, - 0xce, 0xe9, 0x68, 0x44, 0xe0, 0x4d, 0x43, 0x69, - 0x29, 0x2e, 0xac, 0x15, 0x59, 0xa8, 0x0a, 0x9e, - 0x6e, 0x47, 0xdf, 0x34, 0x35, 0x6a, 0xcf, 0xdc, - 0x22, 0xc9, 0xc0, 0x9b, 0x89, 0xd4, 0xed, 0xab, - 0x12, 0xa2, 0x0d, 0x52, 0xbb, 0x02, 0x2f, 0xa9, - 0xd7, 0x61, 0x1e, 0xb4, 0x50, 0x04, 0xf6, 0xc2, - 0x16, 0x25, 0x86, 0x56, 0x55, 0x09, 0xbe, 0x91 - ]; - - /// M-Table 0 - static const _m0 = [ - 0xbcbc3275, 0xecec21f3, 0x202043c6, 0xb3b3c9f4, 0xdada03db, 0x02028b7b, - 0xe2e22bfb, 0x9e9efac8, // 0 - 7 - 0xc9c9ec4a, 0xd4d409d3, 0x18186be6, 0x1e1e9f6b, 0x98980e45, 0xb2b2387d, - 0xa6a6d2e8, 0x2626b74b, - 0x3c3c57d6, 0x93938a32, 0x8282eed8, 0x525298fd, 0x7b7bd437, 0xbbbb3771, - 0x5b5b97f1, 0x474783e1, - 0x24243c30, 0x5151e20f, 0xbabac6f8, 0x4a4af31b, 0xbfbf4887, 0x0d0d70fa, - 0xb0b0b306, 0x7575de3f, - 0xd2d2fd5e, 0x7d7d20ba, 0x666631ae, 0x3a3aa35b, 0x59591c8a, 0x00000000, - 0xcdcd93bc, 0x1a1ae09d, - 0xaeae2c6d, 0x7f7fabc1, 0x2b2bc7b1, 0xbebeb90e, 0xe0e0a080, 0x8a8a105d, - 0x3b3b52d2, 0x6464bad5, - 0xd8d888a0, 0xe7e7a584, 0x5f5fe807, 0x1b1b1114, 0x2c2cc2b5, 0xfcfcb490, - 0x3131272c, 0x808065a3, - 0x73732ab2, 0x0c0c8173, 0x79795f4c, 0x6b6b4154, 0x4b4b0292, 0x53536974, - 0x94948f36, 0x83831f51, - 0x2a2a3638, 0xc4c49cb0, 0x2222c8bd, 0xd5d5f85a, 0xbdbdc3fc, 0x48487860, - 0xffffce62, 0x4c4c0796, - 0x4141776c, 0xc7c7e642, 0xebeb24f7, 0x1c1c1410, 0x5d5d637c, 0x36362228, - 0x6767c027, 0xe9e9af8c, - 0x4444f913, 0x1414ea95, 0xf5f5bb9c, 0xcfcf18c7, 0x3f3f2d24, 0xc0c0e346, - 0x7272db3b, 0x54546c70, - 0x29294cca, 0xf0f035e3, 0x0808fe85, 0xc6c617cb, 0xf3f34f11, 0x8c8ce4d0, - 0xa4a45993, 0xcaca96b8, - 0x68683ba6, 0xb8b84d83, 0x38382820, 0xe5e52eff, 0xadad569f, 0x0b0b8477, - 0xc8c81dc3, 0x9999ffcc, - 0x5858ed03, 0x19199a6f, 0x0e0e0a08, 0x95957ebf, 0x70705040, 0xf7f730e7, - 0x6e6ecf2b, 0x1f1f6ee2, - 0xb5b53d79, 0x09090f0c, 0x616134aa, 0x57571682, 0x9f9f0b41, 0x9d9d803a, - 0x111164ea, 0x2525cdb9, - 0xafafdde4, 0x4545089a, 0xdfdf8da4, 0xa3a35c97, 0xeaead57e, 0x353558da, - 0xededd07a, 0x4343fc17, - 0xf8f8cb66, 0xfbfbb194, 0x3737d3a1, 0xfafa401d, 0xc2c2683d, 0xb4b4ccf0, - 0x32325dde, 0x9c9c71b3, - 0x5656e70b, 0xe3e3da72, 0x878760a7, 0x15151b1c, 0xf9f93aef, 0x6363bfd1, - 0x3434a953, 0x9a9a853e, - 0xb1b1428f, 0x7c7cd133, 0x88889b26, 0x3d3da65f, 0xa1a1d7ec, 0xe4e4df76, - 0x8181942a, 0x91910149, - 0x0f0ffb81, 0xeeeeaa88, 0x161661ee, 0xd7d77321, 0x9797f5c4, 0xa5a5a81a, - 0xfefe3feb, 0x6d6db5d9, - 0x7878aec5, 0xc5c56d39, 0x1d1de599, 0x7676a4cd, 0x3e3edcad, 0xcbcb6731, - 0xb6b6478b, 0xefef5b01, - 0x12121e18, 0x6060c523, 0x6a6ab0dd, 0x4d4df61f, 0xcecee94e, 0xdede7c2d, - 0x55559df9, 0x7e7e5a48, - 0x2121b24f, 0x03037af2, 0xa0a02665, 0x5e5e198e, 0x5a5a6678, 0x65654b5c, - 0x62624e58, 0xfdfd4519, - 0x0606f48d, 0x404086e5, 0xf2f2be98, 0x3333ac57, 0x17179067, 0x05058e7f, - 0xe8e85e05, 0x4f4f7d64, - 0x89896aaf, 0x10109563, 0x74742fb6, 0x0a0a75fe, 0x5c5c92f5, 0x9b9b74b7, - 0x2d2d333c, 0x3030d6a5, - 0x2e2e49ce, 0x494989e9, 0x46467268, 0x77775544, 0xa8a8d8e0, 0x9696044d, - 0x2828bd43, 0xa9a92969, - 0xd9d97929, 0x8686912e, 0xd1d187ac, 0xf4f44a15, 0x8d8d1559, 0xd6d682a8, - 0xb9b9bc0a, 0x42420d9e, - 0xf6f6c16e, 0x2f2fb847, 0xdddd06df, 0x23233934, 0xcccc6235, 0xf1f1c46a, - 0xc1c112cf, 0x8585ebdc, - 0x8f8f9e22, 0x7171a1c9, 0x9090f0c0, 0xaaaa539b, 0x0101f189, 0x8b8be1d4, - 0x4e4e8ced, 0x8e8e6fab, - 0xababa212, 0x6f6f3ea2, 0xe6e6540d, 0xdbdbf252, 0x92927bbb, 0xb7b7b602, - 0x6969ca2f, 0x3939d9a9, - 0xd3d30cd7, 0xa7a72361, 0xa2a2ad1e, 0xc3c399b4, 0x6c6c4450, 0x07070504, - 0x04047ff6, 0x272746c2, - 0xacaca716, 0xd0d07625, 0x50501386, 0xdcdcf756, 0x84841a55, 0xe1e15109, - 0x7a7a25be, 0x1313ef91 - ]; - - /// M-Table 1 - static const _m1 = [ - 0xa9d93939, 0x67901717, 0xb3719c9c, 0xe8d2a6a6, 0x04050707, 0xfd985252, - 0xa3658080, 0x76dfe4e4, // 0 - 7 - 0x9a084545, 0x92024b4b, 0x80a0e0e0, 0x78665a5a, 0xe4ddafaf, 0xddb06a6a, - 0xd1bf6363, 0x38362a2a, - 0x0d54e6e6, 0xc6432020, 0x3562cccc, 0x98bef2f2, 0x181e1212, 0xf724ebeb, - 0xecd7a1a1, 0x6c774141, - 0x43bd2828, 0x7532bcbc, 0x37d47b7b, 0x269b8888, 0xfa700d0d, 0x13f94444, - 0x94b1fbfb, 0x485a7e7e, - 0xf27a0303, 0xd0e48c8c, 0x8b47b6b6, 0x303c2424, 0x84a5e7e7, 0x54416b6b, - 0xdf06dddd, 0x23c56060, - 0x1945fdfd, 0x5ba33a3a, 0x3d68c2c2, 0x59158d8d, 0xf321ecec, 0xae316666, - 0xa23e6f6f, 0x82165757, - 0x63951010, 0x015befef, 0x834db8b8, 0x2e918686, 0xd9b56d6d, 0x511f8383, - 0x9b53aaaa, 0x7c635d5d, - 0xa63b6868, 0xeb3ffefe, 0xa5d63030, 0xbe257a7a, 0x16a7acac, 0x0c0f0909, - 0xe335f0f0, 0x6123a7a7, - 0xc0f09090, 0x8cafe9e9, 0x3a809d9d, 0xf5925c5c, 0x73810c0c, 0x2c273131, - 0x2576d0d0, 0x0be75656, - 0xbb7b9292, 0x4ee9cece, 0x89f10101, 0x6b9f1e1e, 0x53a93434, 0x6ac4f1f1, - 0xb499c3c3, 0xf1975b5b, - 0xe1834747, 0xe66b1818, 0xbdc82222, 0x450e9898, 0xe26e1f1f, 0xf4c9b3b3, - 0xb62f7474, 0x66cbf8f8, - 0xccff9999, 0x95ea1414, 0x03ed5858, 0x56f7dcdc, 0xd4e18b8b, 0x1c1b1515, - 0x1eada2a2, 0xd70cd3d3, - 0xfb2be2e2, 0xc31dc8c8, 0x8e195e5e, 0xb5c22c2c, 0xe9894949, 0xcf12c1c1, - 0xbf7e9595, 0xba207d7d, - 0xea641111, 0x77840b0b, 0x396dc5c5, 0xaf6a8989, 0x33d17c7c, 0xc9a17171, - 0x62ceffff, 0x7137bbbb, - 0x81fb0f0f, 0x793db5b5, 0x0951e1e1, 0xaddc3e3e, 0x242d3f3f, 0xcda47676, - 0xf99d5555, 0xd8ee8282, - 0xe5864040, 0xc5ae7878, 0xb9cd2525, 0x4d049696, 0x44557777, 0x080a0e0e, - 0x86135050, 0xe730f7f7, - 0xa1d33737, 0x1d40fafa, 0xaa346161, 0xed8c4e4e, 0x06b3b0b0, 0x706c5454, - 0xb22a7373, 0xd2523b3b, - 0x410b9f9f, 0x7b8b0202, 0xa088d8d8, 0x114ff3f3, 0x3167cbcb, 0xc2462727, - 0x27c06767, 0x90b4fcfc, - 0x20283838, 0xf67f0404, 0x60784848, 0xff2ee5e5, 0x96074c4c, 0x5c4b6565, - 0xb1c72b2b, 0xab6f8e8e, - 0x9e0d4242, 0x9cbbf5f5, 0x52f2dbdb, 0x1bf34a4a, 0x5fa63d3d, 0x9359a4a4, - 0x0abcb9b9, 0xef3af9f9, - 0x91ef1313, 0x85fe0808, 0x49019191, 0xee611616, 0x2d7cdede, 0x4fb22121, - 0x8f42b1b1, 0x3bdb7272, - 0x47b82f2f, 0x8748bfbf, 0x6d2caeae, 0x46e3c0c0, 0xd6573c3c, 0x3e859a9a, - 0x6929a9a9, 0x647d4f4f, - 0x2a948181, 0xce492e2e, 0xcb17c6c6, 0x2fca6969, 0xfcc3bdbd, 0x975ca3a3, - 0x055ee8e8, 0x7ad0eded, - 0xac87d1d1, 0x7f8e0505, 0xd5ba6464, 0x1aa8a5a5, 0x4bb72626, 0x0eb9bebe, - 0xa7608787, 0x5af8d5d5, - 0x28223636, 0x14111b1b, 0x3fde7575, 0x2979d9d9, 0x88aaeeee, 0x3c332d2d, - 0x4c5f7979, 0x02b6b7b7, - 0xb896caca, 0xda583535, 0xb09cc4c4, 0x17fc4343, 0x551a8484, 0x1ff64d4d, - 0x8a1c5959, 0x7d38b2b2, - 0x57ac3333, 0xc718cfcf, 0x8df40606, 0x74695353, 0xb7749b9b, 0xc4f59797, - 0x9f56adad, 0x72dae3e3, - 0x7ed5eaea, 0x154af4f4, 0x229e8f8f, 0x12a2abab, 0x584e6262, 0x07e85f5f, - 0x99e51d1d, 0x34392323, - 0x6ec1f6f6, 0x50446c6c, 0xde5d3232, 0x68724646, 0x6526a0a0, 0xbc93cdcd, - 0xdb03dada, 0xf8c6baba, - 0xc8fa9e9e, 0xa882d6d6, 0x2bcf6e6e, 0x40507070, 0xdceb8585, 0xfe750a0a, - 0x328a9393, 0xa48ddfdf, - 0xca4c2929, 0x10141c1c, 0x2173d7d7, 0xf0ccb4b4, 0xd309d4d4, 0x5d108a8a, - 0x0fe25151, 0x00000000, - 0x6f9a1919, 0x9de01a1a, 0x368f9494, 0x42e6c7c7, 0x4aecc9c9, 0x5efdd2d2, - 0xc1ab7f7f, 0xe0d8a8a8 - ]; - - /// M-Table 2 - static const _m2 = [ - 0xbc75bc32, 0xecf3ec21, 0x20c62043, 0xb3f4b3c9, 0xdadbda03, 0x027b028b, - 0xe2fbe22b, 0x9ec89efa, // 0 - 7 - 0xc94ac9ec, 0xd4d3d409, 0x18e6186b, 0x1e6b1e9f, 0x9845980e, 0xb27db238, - 0xa6e8a6d2, 0x264b26b7, - 0x3cd63c57, 0x9332938a, 0x82d882ee, 0x52fd5298, 0x7b377bd4, 0xbb71bb37, - 0x5bf15b97, 0x47e14783, - 0x2430243c, 0x510f51e2, 0xbaf8bac6, 0x4a1b4af3, 0xbf87bf48, 0x0dfa0d70, - 0xb006b0b3, 0x753f75de, - 0xd25ed2fd, 0x7dba7d20, 0x66ae6631, 0x3a5b3aa3, 0x598a591c, 0x00000000, - 0xcdbccd93, 0x1a9d1ae0, - 0xae6dae2c, 0x7fc17fab, 0x2bb12bc7, 0xbe0ebeb9, 0xe080e0a0, 0x8a5d8a10, - 0x3bd23b52, 0x64d564ba, - 0xd8a0d888, 0xe784e7a5, 0x5f075fe8, 0x1b141b11, 0x2cb52cc2, 0xfc90fcb4, - 0x312c3127, 0x80a38065, - 0x73b2732a, 0x0c730c81, 0x794c795f, 0x6b546b41, 0x4b924b02, 0x53745369, - 0x9436948f, 0x8351831f, - 0x2a382a36, 0xc4b0c49c, 0x22bd22c8, 0xd55ad5f8, 0xbdfcbdc3, 0x48604878, - 0xff62ffce, 0x4c964c07, - 0x416c4177, 0xc742c7e6, 0xebf7eb24, 0x1c101c14, 0x5d7c5d63, 0x36283622, - 0x672767c0, 0xe98ce9af, - 0x441344f9, 0x149514ea, 0xf59cf5bb, 0xcfc7cf18, 0x3f243f2d, 0xc046c0e3, - 0x723b72db, 0x5470546c, - 0x29ca294c, 0xf0e3f035, 0x088508fe, 0xc6cbc617, 0xf311f34f, 0x8cd08ce4, - 0xa493a459, 0xcab8ca96, - 0x68a6683b, 0xb883b84d, 0x38203828, 0xe5ffe52e, 0xad9fad56, 0x0b770b84, - 0xc8c3c81d, 0x99cc99ff, - 0x580358ed, 0x196f199a, 0x0e080e0a, 0x95bf957e, 0x70407050, 0xf7e7f730, - 0x6e2b6ecf, 0x1fe21f6e, - 0xb579b53d, 0x090c090f, 0x61aa6134, 0x57825716, 0x9f419f0b, 0x9d3a9d80, - 0x11ea1164, 0x25b925cd, - 0xafe4afdd, 0x459a4508, 0xdfa4df8d, 0xa397a35c, 0xea7eead5, 0x35da3558, - 0xed7aedd0, 0x431743fc, - 0xf866f8cb, 0xfb94fbb1, 0x37a137d3, 0xfa1dfa40, 0xc23dc268, 0xb4f0b4cc, - 0x32de325d, 0x9cb39c71, - 0x560b56e7, 0xe372e3da, 0x87a78760, 0x151c151b, 0xf9eff93a, 0x63d163bf, - 0x345334a9, 0x9a3e9a85, - 0xb18fb142, 0x7c337cd1, 0x8826889b, 0x3d5f3da6, 0xa1eca1d7, 0xe476e4df, - 0x812a8194, 0x91499101, - 0x0f810ffb, 0xee88eeaa, 0x16ee1661, 0xd721d773, 0x97c497f5, 0xa51aa5a8, - 0xfeebfe3f, 0x6dd96db5, - 0x78c578ae, 0xc539c56d, 0x1d991de5, 0x76cd76a4, 0x3ead3edc, 0xcb31cb67, - 0xb68bb647, 0xef01ef5b, - 0x1218121e, 0x602360c5, 0x6add6ab0, 0x4d1f4df6, 0xce4ecee9, 0xde2dde7c, - 0x55f9559d, 0x7e487e5a, - 0x214f21b2, 0x03f2037a, 0xa065a026, 0x5e8e5e19, 0x5a785a66, 0x655c654b, - 0x6258624e, 0xfd19fd45, - 0x068d06f4, 0x40e54086, 0xf298f2be, 0x335733ac, 0x17671790, 0x057f058e, - 0xe805e85e, 0x4f644f7d, - 0x89af896a, 0x10631095, 0x74b6742f, 0x0afe0a75, 0x5cf55c92, 0x9bb79b74, - 0x2d3c2d33, 0x30a530d6, - 0x2ece2e49, 0x49e94989, 0x46684672, 0x77447755, 0xa8e0a8d8, 0x964d9604, - 0x284328bd, 0xa969a929, - 0xd929d979, 0x862e8691, 0xd1acd187, 0xf415f44a, 0x8d598d15, 0xd6a8d682, - 0xb90ab9bc, 0x429e420d, - 0xf66ef6c1, 0x2f472fb8, 0xdddfdd06, 0x23342339, 0xcc35cc62, 0xf16af1c4, - 0xc1cfc112, 0x85dc85eb, - 0x8f228f9e, 0x71c971a1, 0x90c090f0, 0xaa9baa53, 0x018901f1, 0x8bd48be1, - 0x4eed4e8c, 0x8eab8e6f, - 0xab12aba2, 0x6fa26f3e, 0xe60de654, 0xdb52dbf2, 0x92bb927b, 0xb702b7b6, - 0x692f69ca, 0x39a939d9, - 0xd3d7d30c, 0xa761a723, 0xa21ea2ad, 0xc3b4c399, 0x6c506c44, 0x07040705, - 0x04f6047f, 0x27c22746, - 0xac16aca7, 0xd025d076, 0x50865013, 0xdc56dcf7, 0x8455841a, 0xe109e151, - 0x7abe7a25, 0x139113ef - ]; - - /// M-Table 3 - static const _m3 = [ - 0xd939a9d9, 0x90176790, 0x719cb371, 0xd2a6e8d2, 0x05070405, 0x9852fd98, - 0x6580a365, 0xdfe476df, // 0 - 7 - 0x08459a08, 0x024b9202, 0xa0e080a0, 0x665a7866, 0xddafe4dd, 0xb06addb0, - 0xbf63d1bf, 0x362a3836, - 0x54e60d54, 0x4320c643, 0x62cc3562, 0xbef298be, 0x1e12181e, 0x24ebf724, - 0xd7a1ecd7, 0x77416c77, - 0xbd2843bd, 0x32bc7532, 0xd47b37d4, 0x9b88269b, 0x700dfa70, 0xf94413f9, - 0xb1fb94b1, 0x5a7e485a, - 0x7a03f27a, 0xe48cd0e4, 0x47b68b47, 0x3c24303c, 0xa5e784a5, 0x416b5441, - 0x06dddf06, 0xc56023c5, - 0x45fd1945, 0xa33a5ba3, 0x68c23d68, 0x158d5915, 0x21ecf321, 0x3166ae31, - 0x3e6fa23e, 0x16578216, - 0x95106395, 0x5bef015b, 0x4db8834d, 0x91862e91, 0xb56dd9b5, 0x1f83511f, - 0x53aa9b53, 0x635d7c63, - 0x3b68a63b, 0x3ffeeb3f, 0xd630a5d6, 0x257abe25, 0xa7ac16a7, 0x0f090c0f, - 0x35f0e335, 0x23a76123, - 0xf090c0f0, 0xafe98caf, 0x809d3a80, 0x925cf592, 0x810c7381, 0x27312c27, - 0x76d02576, 0xe7560be7, - 0x7b92bb7b, 0xe9ce4ee9, 0xf10189f1, 0x9f1e6b9f, 0xa93453a9, 0xc4f16ac4, - 0x99c3b499, 0x975bf197, - 0x8347e183, 0x6b18e66b, 0xc822bdc8, 0x0e98450e, 0x6e1fe26e, 0xc9b3f4c9, - 0x2f74b62f, 0xcbf866cb, - 0xff99ccff, 0xea1495ea, 0xed5803ed, 0xf7dc56f7, 0xe18bd4e1, 0x1b151c1b, - 0xada21ead, 0x0cd3d70c, - 0x2be2fb2b, 0x1dc8c31d, 0x195e8e19, 0xc22cb5c2, 0x8949e989, 0x12c1cf12, - 0x7e95bf7e, 0x207dba20, - 0x6411ea64, 0x840b7784, 0x6dc5396d, 0x6a89af6a, 0xd17c33d1, 0xa171c9a1, - 0xceff62ce, 0x37bb7137, - 0xfb0f81fb, 0x3db5793d, 0x51e10951, 0xdc3eaddc, 0x2d3f242d, 0xa476cda4, - 0x9d55f99d, 0xee82d8ee, - 0x8640e586, 0xae78c5ae, 0xcd25b9cd, 0x04964d04, 0x55774455, 0x0a0e080a, - 0x13508613, 0x30f7e730, - 0xd337a1d3, 0x40fa1d40, 0x3461aa34, 0x8c4eed8c, 0xb3b006b3, 0x6c54706c, - 0x2a73b22a, 0x523bd252, - 0x0b9f410b, 0x8b027b8b, 0x88d8a088, 0x4ff3114f, 0x67cb3167, 0x4627c246, - 0xc06727c0, 0xb4fc90b4, - 0x28382028, 0x7f04f67f, 0x78486078, 0x2ee5ff2e, 0x074c9607, 0x4b655c4b, - 0xc72bb1c7, 0x6f8eab6f, - 0x0d429e0d, 0xbbf59cbb, 0xf2db52f2, 0xf34a1bf3, 0xa63d5fa6, 0x59a49359, - 0xbcb90abc, 0x3af9ef3a, - 0xef1391ef, 0xfe0885fe, 0x01914901, 0x6116ee61, 0x7cde2d7c, 0xb2214fb2, - 0x42b18f42, 0xdb723bdb, - 0xb82f47b8, 0x48bf8748, 0x2cae6d2c, 0xe3c046e3, 0x573cd657, 0x859a3e85, - 0x29a96929, 0x7d4f647d, - 0x94812a94, 0x492ece49, 0x17c6cb17, 0xca692fca, 0xc3bdfcc3, 0x5ca3975c, - 0x5ee8055e, 0xd0ed7ad0, - 0x87d1ac87, 0x8e057f8e, 0xba64d5ba, 0xa8a51aa8, 0xb7264bb7, 0xb9be0eb9, - 0x6087a760, 0xf8d55af8, - 0x22362822, 0x111b1411, 0xde753fde, 0x79d92979, 0xaaee88aa, 0x332d3c33, - 0x5f794c5f, 0xb6b702b6, - 0x96cab896, 0x5835da58, 0x9cc4b09c, 0xfc4317fc, 0x1a84551a, 0xf64d1ff6, - 0x1c598a1c, 0x38b27d38, - 0xac3357ac, 0x18cfc718, 0xf4068df4, 0x69537469, 0x749bb774, 0xf597c4f5, - 0x56ad9f56, 0xdae372da, - 0xd5ea7ed5, 0x4af4154a, 0x9e8f229e, 0xa2ab12a2, 0x4e62584e, 0xe85f07e8, - 0xe51d99e5, 0x39233439, - 0xc1f66ec1, 0x446c5044, 0x5d32de5d, 0x72466872, 0x26a06526, 0x93cdbc93, - 0x03dadb03, 0xc6baf8c6, - 0xfa9ec8fa, 0x82d6a882, 0xcf6e2bcf, 0x50704050, 0xeb85dceb, 0x750afe75, - 0x8a93328a, 0x8ddfa48d, - 0x4c29ca4c, 0x141c1014, 0x73d72173, 0xccb4f0cc, 0x09d4d309, 0x108a5d10, - 0xe2510fe2, 0x00000000, - 0x9a196f9a, 0xe01a9de0, 0x8f94368f, 0xe6c742e6, 0xecc94aec, 0xfdd25efd, - 0xab7fc1ab, 0xd8a8e0d8 - ]; - - /// The Key Schedule List - final List _subKey = []; - - /// The Key depended S-Table 0 - final _sTable0 = List.filled(256, 0); - - /// The Key depended S-Table 1 - final _sTable1 = List.filled(256, 0); - - /// The Key depended S-Table 2 - final _sTable2 = List.filled(256, 0); - - /// The Key depended S-Table 3 - final _sTable3 = List.filled(256, 0); - - static const BLOCK_SIZE = 16; - - bool _forEncryption = false; - - Uint8List _workingKey = Uint8List(0); - - @override - String get algorithmName => 'Twofish'; - - @override - int get blockSize => BLOCK_SIZE; - - @override - void init(bool forEncryption, CipherParameters? params) { - if (params is KeyParameter) { - _forEncryption = forEncryption; - _workingKey = params.key; - final keyBits = _workingKey.length * 8; - if (!(keyBits == 128 || keyBits == 192 || keyBits == 256)) { - throw ArgumentError('Key length not 128/192/256 bits.'); - } - _setupKey(_workingKey); - } else { - throw ArgumentError( - 'Invalid parameter passed to $algorithmName init - ${params.runtimeType}', - ); - } - } - - @override - int processBlock( - Uint8List input, - int inOff, - Uint8List output, - int outOff, - ) { - if (_workingKey.isEmpty) { - throw StateError('$algorithmName not initialised'); - } - if ((inOff + BLOCK_SIZE) > input.lengthInBytes) { - throw ArgumentError('Input buffer too short for $algorithmName engine'); - } - if ((outOff + BLOCK_SIZE) > output.lengthInBytes) { - throw ArgumentError('Output buffer too short for $algorithmName engine'); - } - - if (_forEncryption) { - _encryptBlock(input, inOff, output, outOff); - } else { - _decryptBlock(input, inOff, output, outOff); - } - - return BLOCK_SIZE; - } - - @override - void reset() { - if (_workingKey.isNotEmpty) { - _setupKey(_workingKey); - } - } - - void _setupKey(final Uint8List key) { - switch (key.length) { - case 16: - final list1 = - _mdsrem(_unpack32Le(key.sublist(0)), _unpack32Le(key.sublist(4))); - final list2 = - _mdsrem(_unpack32Le(key.sublist(8)), _unpack32Le(key.sublist(12))); - - for (var i = 0, j = 1; i < 40; i += 2, j += 2) { - var a = _m0[_q0[_q0[i] ^ key[8]] ^ key[0]] ^ - _m1[_q0[_q1[i] ^ key[9]] ^ key[1]] ^ - _m2[_q1[_q0[i] ^ key[10]] ^ key[2]] ^ - _m3[_q1[_q1[i] ^ key[11]] ^ key[3]]; - var b = _m0[_q0[_q0[j] ^ key[12]] ^ key[4]] ^ - _m1[_q0[_q1[j] ^ key[13]] ^ key[5]] ^ - _m2[_q1[_q0[j] ^ key[14]] ^ key[6]] ^ - _m3[_q1[_q1[j] ^ key[15]] ^ key[7]]; - b = (b << 8) | (b >> 24 & 0xff); - a += b; - _subKey.add(a); - a += b; - _subKey.add(a << 9 | a >> 23 & 0x1ff); - } - - for (var i = 0; i < 256; ++i) { - _sTable0[i] = _m0[_q0[_q0[i] ^ list1[3]] ^ list2[3]]; - _sTable1[i] = _m1[_q0[_q1[i] ^ list1[2]] ^ list2[2]]; - _sTable2[i] = _m2[_q1[_q0[i] ^ list1[1]] ^ list2[1]]; - _sTable3[i] = _m3[_q1[_q1[i] ^ list1[0]] ^ list2[0]]; - } - break; - case 24: - final list1 = - _mdsrem(_unpack32Le(key.sublist(0)), _unpack32Le(key.sublist(4))); - final list2 = - _mdsrem(_unpack32Le(key.sublist(8)), _unpack32Le(key.sublist(12))); - final list3 = - _mdsrem(_unpack32Le(key.sublist(16)), _unpack32Le(key.sublist(20))); - - for (var i = 0, j = 1; i < 40; i += 2, j += 2) { - var a = _m0[_q0[_q0[_q1[i] ^ key[16]] ^ key[8]] ^ key[0]] ^ - _m1[_q0[_q1[_q1[i] ^ key[17]] ^ key[9]] ^ key[1]] ^ - _m2[_q1[_q0[_q0[i] ^ key[18]] ^ key[10]] ^ key[2]] ^ - _m3[_q1[_q1[_q0[i] ^ key[19]] ^ key[11]] ^ key[3]]; - var b = _m0[_q0[_q0[_q1[j] ^ key[20]] ^ key[12]] ^ key[4]] ^ - _m1[_q0[_q1[_q1[j] ^ key[21]] ^ key[13]] ^ key[5]] ^ - _m2[_q1[_q0[_q0[j] ^ key[22]] ^ key[14]] ^ key[6]] ^ - _m3[_q1[_q1[_q0[j] ^ key[23]] ^ key[15]] ^ key[7]]; - - b = (b << 8) | (b >> 24 & 0xff); - a += b; - _subKey.add(a); - a += b; - _subKey.add(a << 9 | a >> 23 & 0x1ff); - } - - for (var i = 0; i < 256; ++i) { - _sTable0[i] = _m0[_q0[_q0[_q1[i] ^ list1[3]] ^ list2[3]] ^ list3[3]]; - _sTable1[i] = _m1[_q0[_q1[_q1[i] ^ list1[2]] ^ list2[2]] ^ list3[2]]; - _sTable2[i] = _m2[_q1[_q0[_q0[i] ^ list1[1]] ^ list2[1]] ^ list3[1]]; - _sTable3[i] = _m3[_q1[_q1[_q0[i] ^ list1[0]] ^ list2[0]] ^ list3[0]]; - } - break; - case 32: - final list1 = - _mdsrem(_unpack32Le(key.sublist(0)), _unpack32Le(key.sublist(4))); - final list2 = - _mdsrem(_unpack32Le(key.sublist(8)), _unpack32Le(key.sublist(12))); - final list3 = - _mdsrem(_unpack32Le(key.sublist(16)), _unpack32Le(key.sublist(20))); - final list4 = - _mdsrem(_unpack32Le(key.sublist(24)), _unpack32Le(key.sublist(28))); - - for (var i = 0, j = 1; i < 40; i += 2, j += 2) { - var a = _m0[ - _q0[_q0[_q1[_q1[i] ^ key[24]] ^ key[16]] ^ key[8]] ^ key[0]] ^ - _m1[_q0[_q1[_q1[_q0[i] ^ key[25]] ^ key[17]] ^ key[9]] ^ key[1]] ^ - _m2[_q1[_q0[_q0[_q0[i] ^ key[26]] ^ key[18]] ^ key[10]] ^ - key[2]] ^ - _m3[_q1[_q1[_q0[_q1[i] ^ key[27]] ^ key[19]] ^ key[11]] ^ key[3]]; - var b = _m0[_q0[_q0[_q1[_q1[j] ^ key[28]] ^ key[20]] ^ key[12]] ^ - key[4]] ^ - _m1[_q0[_q1[_q1[_q0[j] ^ key[29]] ^ key[21]] ^ key[13]] ^ - key[5]] ^ - _m2[_q1[_q0[_q0[_q0[j] ^ key[30]] ^ key[22]] ^ key[14]] ^ - key[6]] ^ - _m3[_q1[_q1[_q0[_q1[j] ^ key[31]] ^ key[23]] ^ key[15]] ^ key[7]]; - b = (b << 8) | (b >> 24 & 0xff); - a = a + b; - _subKey.add(a); - a = a + b; - _subKey.add(a << 9 | a >> 23 & 0x1ff); - } - - for (var i = 0; i < 256; ++i) { - _sTable0[i] = _m0[ - _q0[_q0[_q1[_q1[i] ^ list1[3]] ^ list2[3]] ^ list3[3]] ^ - list4[3]]; - _sTable1[i] = _m1[ - _q0[_q1[_q1[_q0[i] ^ list1[2]] ^ list2[2]] ^ list3[2]] ^ - list4[2]]; - _sTable2[i] = _m2[ - _q1[_q0[_q0[_q0[i] ^ list1[1]] ^ list2[1]] ^ list3[1]] ^ - list4[1]]; - _sTable3[i] = _m3[ - _q1[_q1[_q0[_q1[i] ^ list1[0]] ^ list2[0]] ^ list3[0]] ^ - list4[0]]; - } - break; - default: - } - } - - /// Encrypt the given input starting at the given offset and place - /// the result in the provided buffer starting at the given offset. - /// The input will be an exact multiple of our blocksize. - void _encryptBlock( - final Uint8List input, - final int inOff, - final Uint8List output, - final int outOff, - ) { - var r0 = _unpack32Le(input.sublist(inOff)) ^ _subKey[0]; - var r1 = _unpack32Le(input.sublist(inOff + 4)) ^ _subKey[1]; - var r2 = _unpack32Le(input.sublist(inOff + 8)) ^ _subKey[2]; - var r3 = _unpack32Le(input.sublist(inOff + 12)) ^ _subKey[3]; - - var ki = 7; - while (ki < 39) { - var t0 = _sTable0[r0 & 0xff] ^ - _sTable1[(r0 >> 8) & 0xff] ^ - _sTable2[(r0 >> 16) & 0xff] ^ - _sTable3[(r0 >> 24) & 0xff]; - var t1 = _sTable0[(r1 >> 24) & 0xff] ^ - _sTable1[r1 & 0xff] ^ - _sTable2[(r1 >> 8) & 0xff] ^ - _sTable3[(r1 >> 16) & 0xff]; - - r2 ^= t0 + t1 + _subKey[++ki]; - r2 = (r2 >> 1 & 0x7fffffff) | (r2 << 31); - r3 = (((r3 >> 31) & 1) | (r3 << 1)) ^ (t0 + (t1 << 1) + _subKey[++ki]); - - t0 = _sTable0[r2 & 0xff] ^ - _sTable1[(r2 >> 8) & 0xff] ^ - _sTable2[(r2 >> 16) & 0xff] ^ - _sTable3[(r2 >> 24) & 0xff]; - t1 = _sTable0[(r3 >> 24) & 0xff] ^ - _sTable1[r3 & 0xff] ^ - _sTable2[(r3 >> 8) & 0xff] ^ - _sTable3[(r3 >> 16) & 0xff]; - - r0 ^= t0 + t1 + _subKey[++ki]; - r0 = (r0 >> 1 & 0x7fffffff) | (r0 << 31); - r1 = (((r1 >> 31) & 1) | (r1 << 1)) ^ (t0 + (t1 << 1) + _subKey[++ki]); - } - - output.setAll(outOff, _pack32Le(r2 ^ _subKey[4])); - output.setAll(outOff + 4, _pack32Le(r3 ^ _subKey[5])); - output.setAll(outOff + 8, _pack32Le(r0 ^ _subKey[6])); - output.setAll(outOff + 12, _pack32Le(r1 ^ _subKey[7])); - } - - /// Decrypt the given input starting at the given offset and place - /// the result in the provided buffer starting at the given offset. - /// The input will be an exact multiple of our blocksize. - void _decryptBlock( - final Uint8List input, - final int inOff, - final Uint8List output, - final int outOff, - ) { - var r0 = _subKey[4] ^ _unpack32Le(input.sublist(inOff)); - var r1 = _subKey[5] ^ _unpack32Le(input.sublist(inOff + 4)); - var r2 = _subKey[6] ^ _unpack32Le(input.sublist(inOff + 8)); - var r3 = _subKey[7] ^ _unpack32Le(input.sublist(inOff + 12)); - - var ki = 40; - while (ki > 8) { - var t0 = _sTable0[r0 & 0xff] ^ - _sTable1[r0 >> 8 & 0xff] ^ - _sTable2[r0 >> 16 & 0xff] ^ - _sTable3[r0 >> 24 & 0xff]; - var t1 = _sTable0[r1 >> 24 & 0xff] ^ - _sTable1[r1 & 0xff] ^ - _sTable2[r1 >> 8 & 0xff] ^ - _sTable3[r1 >> 16 & 0xff]; - - r3 ^= t0 + (t1 << 1) + _subKey[--ki]; - r3 = r3 >> 1 & 0x7fffffff | r3 << 31; - r2 = (r2 >> 31 & 0x1 | r2 << 1) ^ (t0 + t1 + _subKey[--ki]); - - t0 = _sTable0[r2 & 0xff] ^ - _sTable1[r2 >> 8 & 0xff] ^ - _sTable2[r2 >> 16 & 0xff] ^ - _sTable3[r2 >> 24 & 0xff]; - t1 = _sTable0[r3 >> 24 & 0xff] ^ - _sTable1[r3 & 0xff] ^ - _sTable2[r3 >> 8 & 0xff] ^ - _sTable3[r3 >> 16 & 0xff]; - - r1 ^= t0 + (t1 << 1) + _subKey[--ki]; - r1 = r1 >> 1 & 0x7fffffff | r1 << 31; - r0 = (r0 >> 31 & 0x1 | r0 << 1) ^ (t0 + t1 + _subKey[--ki]); - } - - output.setAll(outOff, _pack32Le(r2 ^ _subKey[0])); - output.setAll(outOff + 4, _pack32Le(r3 ^ _subKey[1])); - output.setAll(outOff + 8, _pack32Le(r0 ^ _subKey[2])); - output.setAll(outOff + 12, _pack32Le(r1 ^ _subKey[3])); - } - - List _mdsrem(final int x, final int y) { - var a = x; - var b = y; - - /// No gain by unrolling this loop. - for (var i = 0; i < 8; ++i) { - /// Get most significant coefficient. - final t = 0xff & (b >> 24); - - /// Shift the others up. - b = (b << 8) | (0xff & (a >> 24)); - a <<= 8; - - var u = t << 1; - - /// Subtract the modular polynomial on overflow. - if ((t & 0x80) > 0) { - u ^= 0x14d; - } - - /// Remove t * (a * x^2 + 1). - b ^= t ^ (u << 16); - - /// Form u = a*t + t/a = t*(a + 1/a). - u ^= 0x7fffffff & (t >> 1); - - /// Add the modular polynomial on underflow. - if ((t & 0x01) > 0) { - u ^= 0xa6; - } - - /// Remove t * (a + 1/a) * (x^3 + x). - b ^= (u << 24) | (u << 8); - } - return [0xff & b >> 24, 0xff & b >> 16, 0xff & b >> 8, 0xff & b]; - } - - static int _unpack32Le(Uint8List x) => - x.buffer.asByteData().getUint32(0, Endian.little); - static Uint8List _pack32Le(int x) => - Uint8List(4)..buffer.asByteData().setUint32(0, x, Endian.little); -} diff --git a/pointycastle/lib/digests/blake2b.dart b/pointycastle/lib/digests/blake2b.dart deleted file mode 100644 index 842bfd4..0000000 --- a/pointycastle/lib/digests/blake2b.dart +++ /dev/null @@ -1,306 +0,0 @@ -// This file has been migrated. - -library impl.digest.blake2b; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -class Blake2bDigest extends BaseDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'Blake2b', () => Blake2bDigest()); - - static const _rounds = 12; - static const _blockSize = 128; - - int _digestLength = 64; - int _keyLength = 0; - Uint8List? _salt; - Uint8List? _personalization; - - Uint8List? _key; - - Uint8List? _buffer; - // Position of last inserted byte: - int _bufferPos = 0; // a value from 0 up to 128 - final _internalState = - Register64List(16); // In the Blake2b paper it is called: v - Register64List? - _chainValue; // state vector, in the Blake2b paper it is called: h - - final _t0 = - Register64(); // holds last significant bits, counter (counts bytes) - final _t1 = Register64(); // counter: Length up to 2^128 are supported - final _f0 = Register64(); // finalization flag, for last block: ~0L - - Blake2bDigest( - {int digestSize = 64, - Uint8List? key, - Uint8List? salt, - Uint8List? personalization}) { - _buffer = Uint8List(_blockSize); - - if (digestSize < 1 || digestSize > 64) { - throw ArgumentError('Invalid digest length (required: 1 - 64)'); - } - _digestLength = digestSize; - if (salt != null) { - if (salt.length != 16) { - throw ArgumentError('salt length must be exactly 16 bytes'); - } - _salt = Uint8List.fromList(salt); - } - if (personalization != null) { - if (personalization.length != 16) { - throw ArgumentError('personalization length must be exactly 16 bytes'); - } - _personalization = Uint8List.fromList(personalization); - } - if (key != null) { - if (key.length > 64) throw ArgumentError('Keys > 64 are not supported'); - _key = Uint8List.fromList(key); - - _keyLength = key.length; - _buffer!.setAll(0, key); - _bufferPos = _blockSize; - } - init(); - } - - @override - String get algorithmName => 'Blake2b'; - @override - int get digestSize => _digestLength; - - void init() { - if (_chainValue == null) { - _chainValue = Register64List(8); - _chainValue![0] - ..set(_blake2bIV[0]) - ..xor(Register64(digestSize | (_keyLength << 8) | 0x1010000)); - _chainValue![1].set(_blake2bIV[1]); - _chainValue![2].set(_blake2bIV[2]); - - _chainValue![3].set(_blake2bIV[3]); - - _chainValue![4].set(_blake2bIV[4]); - _chainValue![5].set(_blake2bIV[5]); - if (_salt != null) { - _chainValue![4].xor(Register64()..unpack(_salt, 0, Endian.little)); - _chainValue![5].xor(Register64()..unpack(_salt, 8, Endian.little)); - } - - _chainValue![6].set(_blake2bIV[6]); - _chainValue![7].set(_blake2bIV[7]); - if (_personalization != null) { - _chainValue![6] - .xor(Register64()..unpack(_personalization, 0, Endian.little)); - _chainValue![7] - .xor(Register64()..unpack(_personalization, 8, Endian.little)); - } - } - } - - void _initializeInternalState() { - _internalState.setRange(0, _chainValue!.length, _chainValue!); - _internalState.setRange( - _chainValue!.length, _chainValue!.length + 4, _blake2bIV); - _internalState[12] - ..set(_t0) - ..xor(_blake2bIV[4]); - _internalState[13] - ..set(_t1) - ..xor(_blake2bIV[5]); - _internalState[14] - ..set(_f0) - ..xor(_blake2bIV[6]); - _internalState[15].set(_blake2bIV[7]); // ^ f1 with f1 = 0 - } - - @override - void updateByte(int inp) { - if (_bufferPos == _blockSize) { - // full buffer - _t0.sum(_blockSize); - // This requires hashing > 2^64 bytes which is impossible for the forseeable future. - // So _t1 is untested dead code, but I've left it in because it is in the source library. - if (_t0.lo32 == 0 && _t0.hi32 == 0) _t1.sum(1); - _compress(_buffer, 0); - _buffer!.fillRange(0, _buffer!.length, 0); // clear buffer - _buffer![0] = inp; - _bufferPos = 1; - } else { - _buffer![_bufferPos] = inp; - ++_bufferPos; - } - } - - @override - void update(Uint8List inp, int inpOff, int len) { - if (len == 0) return; - var remainingLength = 0; - if (_bufferPos != 0) { - remainingLength = _blockSize - _bufferPos; - if (remainingLength < len) { - _buffer! - .setRange(_bufferPos, _bufferPos + remainingLength, inp, inpOff); - _t0.sum(_blockSize); - if (_t0.lo32 == 0 && _t0.hi32 == 0) _t1.sum(1); - _compress(_buffer, 0); - _bufferPos = 0; - _buffer!.fillRange(0, _buffer!.length, 0); // clear buffer - } else { - _buffer!.setRange(_bufferPos, _bufferPos + len, inp, inpOff); - _bufferPos += len; - return; - } - } - - int msgPos; - var blockWiseLastPos = inpOff + len - _blockSize; - for (msgPos = inpOff + remainingLength; - msgPos < blockWiseLastPos; - msgPos += _blockSize) { - _t0.sum(_blockSize); - if (_t0.lo32 == 0 && _t0.hi32 == 0) _t1.sum(1); - _compress(inp, msgPos); - } - - _buffer!.setRange(0, inpOff + len - msgPos, inp, msgPos); - _bufferPos += inpOff + len - msgPos; - } - - @override - int doFinal(Uint8List out, int outOff) { - _f0.set(0xFFFFFFFF, 0xFFFFFFFF); - _t0.sum(_bufferPos); - if (_bufferPos > 0 && _t0.lo32 == 0 && _t0.hi32 == 0) _t1.sum(1); - _compress(_buffer, 0); - _buffer!.fillRange(0, _buffer!.length, 0); // clear buffer - _internalState.fillRange(0, _internalState.length, 0); - - final packedValue = Uint8List(8); - final packedValueData = packedValue.buffer.asByteData(); - for (var i = 0; i < _chainValue!.length && (i * 8 < _digestLength); ++i) { - _chainValue![i].pack(packedValueData, 0, Endian.little); - - final start = outOff + i * 8; - if (i * 8 < _digestLength - 8) { - out.setRange(start, start + 8, packedValue); - } else { - out.setRange(start, start + _digestLength - (i * 8), packedValue); - } - } - - _chainValue!.fillRange(0, _chainValue!.length, 0); - - reset(); - - return _digestLength; - } - - @override - void reset() { - _bufferPos = 0; - _f0.set(0); - _t0.set(0); - _t1.set(0); - _chainValue = null; - _buffer!.fillRange(0, _buffer!.length, 0); - if (_key != null) { - _buffer!.setAll(0, _key!); - _bufferPos = _blockSize; - } - init(); - } - - // This variable is faster as a class member. - final _m = Register64List(16); - void _compress(Uint8List? message, int messagePos) { - _initializeInternalState(); - - for (var j = 0; j < 16; ++j) { - _m[j].unpack(message, messagePos + j * 8, Endian.little); - } - - for (var round = 0; round < _rounds; ++round) { - G(_m[_blake2bSigma[round][0]], _m[_blake2bSigma[round][1]], 0, 4, 8, 12); - G(_m[_blake2bSigma[round][2]], _m[_blake2bSigma[round][3]], 1, 5, 9, 13); - G(_m[_blake2bSigma[round][4]], _m[_blake2bSigma[round][5]], 2, 6, 10, 14); - G(_m[_blake2bSigma[round][6]], _m[_blake2bSigma[round][7]], 3, 7, 11, 15); - G(_m[_blake2bSigma[round][8]], _m[_blake2bSigma[round][9]], 0, 5, 10, 15); - G(_m[_blake2bSigma[round][10]], _m[_blake2bSigma[round][11]], 1, 6, 11, - 12); - G(_m[_blake2bSigma[round][12]], _m[_blake2bSigma[round][13]], 2, 7, 8, - 13); - G(_m[_blake2bSigma[round][14]], _m[_blake2bSigma[round][15]], 3, 4, 9, - 14); - } - - for (var offset = 0; offset < _chainValue!.length; ++offset) { - _chainValue![offset] - ..xor(_internalState[offset]) - ..xor(_internalState[offset + 8]); - } - } - - void G(Register64 m1, Register64 m2, int posA, int posB, int posC, int posD) { - // This variable is faster as a local. The allocation is probably sunk. - final r = Register64(); - - _internalState[posA].sumReg(r - ..set(_internalState[posB]) - ..sumReg(m1)); - _internalState[posD] - ..xor(_internalState[posA]) - ..rotr(32); - _internalState[posC].sumReg(_internalState[posD]); - _internalState[posB] - ..xor(_internalState[posC]) - ..rotr(24); - _internalState[posA].sumReg(r - ..set(_internalState[posB]) - ..sumReg(m2)); - _internalState[posD] - ..xor(_internalState[posA]) - ..rotr(16); - _internalState[posC].sumReg(_internalState[posD]); - _internalState[posB] - ..xor(_internalState[posC]) - ..rotr(63); - } - - @override - int get byteLength => 128; -} - -// Produced from the square root of primes 2, 3, 5, 7, 11, 13, 17, 19. -// The same as SHA-512 IV. -final _blake2bIV = Register64List.from([ - [0x6a09e667, 0xf3bcc908], - [0xbb67ae85, 0x84caa73b], - [0x3c6ef372, 0xfe94f82b], - [0xa54ff53a, 0x5f1d36f1], - [0x510e527f, 0xade682d1], - [0x9b05688c, 0x2b3e6c1f], - [0x1f83d9ab, 0xfb41bd6b], - [0x5be0cd19, 0x137e2179], -]); - -final _blake2bSigma = [ - [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - [14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3], - [11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4], - [7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8], - [9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13], - [2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9], - [12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11], - [13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10], - [6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5], - [10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0], - [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - [14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3], -]; diff --git a/pointycastle/lib/digests/cshake.dart b/pointycastle/lib/digests/cshake.dart deleted file mode 100644 index 98aa4e4..0000000 --- a/pointycastle/lib/digests/cshake.dart +++ /dev/null @@ -1,114 +0,0 @@ -// This file has been migrated. - -library impl.digest.cshake; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/digests/shake.dart'; -import 'package:pointycastle/digests/xof_utils.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/utils.dart'; - -/// -/// implementation of SHAKE based on following KeccakNISTInterface.c from http://keccak.noekeon.org/ -/// -/// Following the naming conventions used in the C source code to enable easy review of the implementation. -/// -class CSHAKEDigest extends SHAKEDigest implements Xof { - static final RegExp _cshakeREGEX = RegExp(r'^CSHAKE-([0-9]+)$'); - - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig( - Digest, - _cshakeREGEX, - (_, final Match match) => () { - var bitLength = int.parse(match.group(1)!); - return CSHAKEDigest(bitLength); - }); - - Uint8List? _diff; - final _padding = Uint8List(100); - - CSHAKEDigest([int bitLength = 256, Uint8List? N, Uint8List? S]) { - switch (bitLength) { - case 128: - case 256: - init(bitLength); - if ((N == null || N.isEmpty) && (S == null || S.isEmpty)) { - _diff = null; - } else { - _diff = concatUint8List([ - XofUtils.leftEncode(rate ~/ 8), - _encodeString(N), - _encodeString(S) - ]); - _diffPadAndAbsorb(); - } - - break; - default: - throw StateError( - 'invalid bitLength ($bitLength) for CSHAKE must only be 128 or 256'); - } - } - - @override - String get algorithmName => 'CSHAKE-$fixedOutputLength'; - @override - int doOutput(Uint8List out, int outOff, int outLen) { - if (_diff != null) { - if (!squeezing) { - absorbBits(0x00, 2); - } - - squeeze(out, outOff, outLen * 8); - - return outLen; - } else { - return super.doOutput(out, outOff, outLen); - } - } - - @override - void update(Uint8List inp, int inpOff, int len) { - absorbRange(inp, inpOff, len); - } - - @override - void reset() { - super.reset(); - - if (_diff != null) { - _diffPadAndAbsorb(); - } - } - - // bytepad in SP 800-185 - void _diffPadAndAbsorb() { - var blockSize = rate ~/ 8; - absorbRange(_diff!, 0, _diff!.length); - - var delta = _diff!.length % blockSize; - - // only add padding if needed - if (delta != 0) { - var required = blockSize - delta; - - while (required > _padding.length) { - absorbRange(_padding, 0, _padding.length); - required -= _padding.length; - } - - absorbRange(_padding, 0, required); - } - } - - Uint8List _encodeString(Uint8List? str) { - if (str == null || str.isEmpty) { - return XofUtils.leftEncode(0); - } - - return concatUint8List([XofUtils.leftEncode(str.length * 8), str]); - } -} diff --git a/pointycastle/lib/digests/keccak.dart b/pointycastle/lib/digests/keccak.dart deleted file mode 100644 index eac176c..0000000 --- a/pointycastle/lib/digests/keccak.dart +++ /dev/null @@ -1,49 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.keccak; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/keccak_engine.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// Implementation of Keccak digest. -class KeccakDigest extends KeccakEngine { - static final RegExp _keccakREGEX = RegExp(r'^Keccak\/([0-9]+)$'); - - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig( - Digest, - _keccakREGEX, - (_, final Match match) => () { - var bitLength = int.parse(match.group(1)!); - return KeccakDigest(bitLength); - }); - - KeccakDigest([int bitLength = 288]) { - switch (bitLength) { - case 128: - case 224: - case 256: - case 288: - case 384: - case 512: - init(bitLength); - break; - default: - throw StateError( - 'invalid bitLength ($bitLength) for Keccak must only be 128,224,256,288,384,512'); - } - } - - @override - String get algorithmName => 'Keccak/$fixedOutputLength'; - - @override - int doFinal(Uint8List out, int outOff) { - squeeze(out, outOff, fixedOutputLength); - reset(); - return digestSize; - } -} diff --git a/pointycastle/lib/digests/md2.dart b/pointycastle/lib/digests/md2.dart deleted file mode 100644 index 5fd73f1..0000000 --- a/pointycastle/lib/digests/md2.dart +++ /dev/null @@ -1,397 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.md2; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// Implementation of MD2 as outlined in RFC1319 by B.Kaliski from RSA Laboratories April 1992 -class MD2Digest extends BaseDigest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'MD2', () => MD2Digest()); - - static const _DIGEST_LENGTH = 16; - - /* X buffer */ - final _x = Uint8List(48); - int _xOff = 0; - - /* M buffer */ - final _m = Uint8List(16); - int _mOff = 0; - - /* check sum */ - final _c = Uint8List(16); - // ignore: unused_field - int _cOff = 0; - - @override - String get algorithmName => 'MD2'; - - @override - int get digestSize => _DIGEST_LENGTH; - - @override - void reset() { - _xOff = 0; - _x.fillRange(0, _x.length, 0); - - _mOff = 0; - _m.fillRange(0, _m.length, 0); - - _cOff = 0; - _c.fillRange(0, _c.length, 0); - } - - @override - void updateByte(int inp) { - _m[_mOff++] = inp; - - if (_mOff == 16) { - _processCheckSum(_m); - _processBlock(_m); - _mOff = 0; - } - } - - @override - void update(Uint8List inp, int inpOff, int len) { - // fill the current word - while ((_mOff != 0) && (len > 0)) { - updateByte(inp[inpOff]); - inpOff++; - len--; - } - - // process whole words. - while (len > 16) { - _m.setRange(0, 16, inp.sublist(inpOff)); - _processCheckSum(_m); - _processBlock(_m); - len -= 16; - inpOff += 16; - } - - // load in the remainder. - while (len > 0) { - updateByte(inp[inpOff]); - inpOff++; - len--; - } - } - - @override - int doFinal(Uint8List? out, int? outOff) { - // add padding - var paddingByte = _m.length - _mOff; - for (var i = _mOff; i < _m.length; i++) { - _m[i] = paddingByte; - } - - //do final check sum - _processCheckSum(_m); - - // do final block process - _processBlock(_m); - - _processBlock(_c); - - out!.setRange(outOff!, outOff + 16, _x.sublist(_xOff)); - - reset(); - - return _DIGEST_LENGTH; - } - - void _processBlock(Uint8List m) { - for (var i = 0; i < 16; i++) { - _x[i + 16] = m[i]; - _x[i + 32] = m[i] ^ _x[i]; - } - - // encrypt block - var t = 0; - - for (var j = 0; j < 18; j++) { - for (var k = 0; k < 48; k++) { - t = _x[k] ^= _s[t]; - t = t & 0xff; - } - t = (t + j) % 256; - } - } - - void _processCheckSum(Uint8List m) { - var L = _c[15]; - for (var i = 0; i < 16; i++) { - _c[i] ^= _s[(m[i] ^ L) & 0xff]; - L = _c[i]; - } - } - - // 256-byte random permutation constructed from the digits of PI - static final _s = [ - 41, - 46, - 67, - 201, - 162, - 216, - 124, - 1, - 61, - 54, - 84, - 161, - 236, - 240, - 6, - 19, - 98, - 167, - 5, - 243, - 192, - 199, - 115, - 140, - 152, - 147, - 43, - 217, - 188, - 76, - 130, - 202, - 30, - 155, - 87, - 60, - 253, - 212, - 224, - 22, - 103, - 66, - 111, - 24, - 138, - 23, - 229, - 18, - 190, - 78, - 196, - 214, - 218, - 158, - 222, - 73, - 160, - 251, - 245, - 142, - 187, - 47, - 238, - 122, - 169, - 104, - 121, - 145, - 21, - 178, - 7, - 63, - 148, - 194, - 16, - 137, - 11, - 34, - 95, - 33, - 128, - 127, - 93, - 154, - 90, - 144, - 50, - 39, - 53, - 62, - 204, - 231, - 191, - 247, - 151, - 3, - 255, - 25, - 48, - 179, - 72, - 165, - 181, - 209, - 215, - 94, - 146, - 42, - 172, - 86, - 170, - 198, - 79, - 184, - 56, - 210, - 150, - 164, - 125, - 182, - 118, - 252, - 107, - 226, - 156, - 116, - 4, - 241, - 69, - 157, - 112, - 89, - 100, - 113, - 135, - 32, - 134, - 91, - 207, - 101, - 230, - 45, - 168, - 2, - 27, - 96, - 37, - 173, - 174, - 176, - 185, - 246, - 28, - 70, - 97, - 105, - 52, - 64, - 126, - 15, - 85, - 71, - 163, - 35, - 221, - 81, - 175, - 58, - 195, - 92, - 249, - 206, - 186, - 197, - 234, - 38, - 44, - 83, - 13, - 110, - 133, - 40, - 132, - 9, - 211, - 223, - 205, - 244, - 65, - 129, - 77, - 82, - 106, - 220, - 55, - 200, - 108, - 193, - 171, - 250, - 36, - 225, - 123, - 8, - 12, - 189, - 177, - 74, - 120, - 136, - 149, - 139, - 227, - 99, - 232, - 109, - 233, - 203, - 213, - 254, - 59, - 0, - 29, - 57, - 242, - 239, - 183, - 14, - 102, - 88, - 208, - 228, - 166, - 119, - 114, - 248, - 235, - 117, - 75, - 10, - 49, - 68, - 80, - 180, - 143, - 237, - 31, - 26, - 219, - 153, - 141, - 51, - 159, - 17, - 131, - 20 - ]; - - @override - int get byteLength => 16; -} diff --git a/pointycastle/lib/digests/md4.dart b/pointycastle/lib/digests/md4.dart deleted file mode 100644 index 18e80c0..0000000 --- a/pointycastle/lib/digests/md4.dart +++ /dev/null @@ -1,128 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.md4; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/md4_family_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of MD4 digest -class MD4Digest extends MD4FamilyDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'MD4', () => MD4Digest()); - - static const _DIGEST_LENGTH = 16; - - MD4Digest() : super(Endian.little, 4, 16); - - @override - final algorithmName = 'MD4'; - @override - final digestSize = _DIGEST_LENGTH; - - @override - void resetState() { - state[0] = 0x67452301; - state[1] = 0xefcdab89; - state[2] = 0x98badcfe; - state[3] = 0x10325476; - } - - @override - void processBlock() { - var a = state[0]; - var b = state[1]; - var c = state[2]; - var d = state[3]; - - // Round 1 - F cycle, 16 times. - a = crotl32(a + _f(b, c, d) + buffer[0], _S11); - d = crotl32(d + _f(a, b, c) + buffer[1], _S12); - c = crotl32(c + _f(d, a, b) + buffer[2], _S13); - b = crotl32(b + _f(c, d, a) + buffer[3], _S14); - a = crotl32(a + _f(b, c, d) + buffer[4], _S11); - d = crotl32(d + _f(a, b, c) + buffer[5], _S12); - c = crotl32(c + _f(d, a, b) + buffer[6], _S13); - b = crotl32(b + _f(c, d, a) + buffer[7], _S14); - a = crotl32(a + _f(b, c, d) + buffer[8], _S11); - d = crotl32(d + _f(a, b, c) + buffer[9], _S12); - c = crotl32(c + _f(d, a, b) + buffer[10], _S13); - b = crotl32(b + _f(c, d, a) + buffer[11], _S14); - a = crotl32(a + _f(b, c, d) + buffer[12], _S11); - d = crotl32(d + _f(a, b, c) + buffer[13], _S12); - c = crotl32(c + _f(d, a, b) + buffer[14], _S13); - b = crotl32(b + _f(c, d, a) + buffer[15], _S14); - - // Round 2 - G cycle, 16 times. - a = crotl32(a + _g(b, c, d) + buffer[0] + 0x5a827999, _S21); - d = crotl32(d + _g(a, b, c) + buffer[4] + 0x5a827999, _S22); - c = crotl32(c + _g(d, a, b) + buffer[8] + 0x5a827999, _S23); - b = crotl32(b + _g(c, d, a) + buffer[12] + 0x5a827999, _S24); - a = crotl32(a + _g(b, c, d) + buffer[1] + 0x5a827999, _S21); - d = crotl32(d + _g(a, b, c) + buffer[5] + 0x5a827999, _S22); - c = crotl32(c + _g(d, a, b) + buffer[9] + 0x5a827999, _S23); - b = crotl32(b + _g(c, d, a) + buffer[13] + 0x5a827999, _S24); - a = crotl32(a + _g(b, c, d) + buffer[2] + 0x5a827999, _S21); - d = crotl32(d + _g(a, b, c) + buffer[6] + 0x5a827999, _S22); - c = crotl32(c + _g(d, a, b) + buffer[10] + 0x5a827999, _S23); - b = crotl32(b + _g(c, d, a) + buffer[14] + 0x5a827999, _S24); - a = crotl32(a + _g(b, c, d) + buffer[3] + 0x5a827999, _S21); - d = crotl32(d + _g(a, b, c) + buffer[7] + 0x5a827999, _S22); - c = crotl32(c + _g(d, a, b) + buffer[11] + 0x5a827999, _S23); - b = crotl32(b + _g(c, d, a) + buffer[15] + 0x5a827999, _S24); - - // Round 3 - H cycle, 16 times. - a = crotl32(a + _h(b, c, d) + buffer[0] + 0x6ed9eba1, _S31); - d = crotl32(d + _h(a, b, c) + buffer[8] + 0x6ed9eba1, _S32); - c = crotl32(c + _h(d, a, b) + buffer[4] + 0x6ed9eba1, _S33); - b = crotl32(b + _h(c, d, a) + buffer[12] + 0x6ed9eba1, _S34); - a = crotl32(a + _h(b, c, d) + buffer[2] + 0x6ed9eba1, _S31); - d = crotl32(d + _h(a, b, c) + buffer[10] + 0x6ed9eba1, _S32); - c = crotl32(c + _h(d, a, b) + buffer[6] + 0x6ed9eba1, _S33); - b = crotl32(b + _h(c, d, a) + buffer[14] + 0x6ed9eba1, _S34); - a = crotl32(a + _h(b, c, d) + buffer[1] + 0x6ed9eba1, _S31); - d = crotl32(d + _h(a, b, c) + buffer[9] + 0x6ed9eba1, _S32); - c = crotl32(c + _h(d, a, b) + buffer[5] + 0x6ed9eba1, _S33); - b = crotl32(b + _h(c, d, a) + buffer[13] + 0x6ed9eba1, _S34); - a = crotl32(a + _h(b, c, d) + buffer[3] + 0x6ed9eba1, _S31); - d = crotl32(d + _h(a, b, c) + buffer[11] + 0x6ed9eba1, _S32); - c = crotl32(c + _h(d, a, b) + buffer[7] + 0x6ed9eba1, _S33); - b = crotl32(b + _h(c, d, a) + buffer[15] + 0x6ed9eba1, _S34); - - state[0] = clip32(state[0] + a); - state[1] = clip32(state[1] + b); - state[2] = clip32(state[2] + c); - state[3] = clip32(state[3] + d); - } - - // round 1 left rotates - static const _S11 = 3; - static const _S12 = 7; - static const _S13 = 11; - static const _S14 = 19; - - // round 2 left rotates - static const _S21 = 3; - static const _S22 = 5; - static const _S23 = 9; - static const _S24 = 13; - - // round 3 left rotates - static const _S31 = 3; - static const _S32 = 9; - static const _S33 = 11; - static const _S34 = 15; - - // F, G and H are the basic MD4 functions. - int _f(int u, int v, int w) => (u & v) | (not32(u) & w); - - int _g(int u, int v, int w) => (u & v) | (u & w) | (v & w); - - int _h(int u, int v, int w) => u ^ v ^ w; - - @override - int get byteLength => 64; -} diff --git a/pointycastle/lib/digests/md5.dart b/pointycastle/lib/digests/md5.dart deleted file mode 100644 index 0a14c3f..0000000 --- a/pointycastle/lib/digests/md5.dart +++ /dev/null @@ -1,153 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.md5; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/md4_family_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of MD5 digest -class MD5Digest extends MD4FamilyDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'MD5', () => MD5Digest()); - - static const _DIGEST_LENGTH = 16; - - MD5Digest() : super(Endian.little, 4, 16); - - @override - final algorithmName = 'MD5'; - @override - final digestSize = _DIGEST_LENGTH; - - @override - void resetState() { - state[0] = 0x67452301; - state[1] = 0xefcdab89; - state[2] = 0x98badcfe; - state[3] = 0x10325476; - } - - @override - void processBlock() { - var a = state[0]; - var b = state[1]; - var c = state[2]; - var d = state[3]; - - // Round 1 - F cycle, 16 times. - a = sum32(crotl32(a + _f(b, c, d) + buffer[0] + 0xd76aa478, _S11), b); - d = sum32(crotl32(d + _f(a, b, c) + buffer[1] + 0xe8c7b756, _S12), a); - c = sum32(crotl32(c + _f(d, a, b) + buffer[2] + 0x242070db, _S13), d); - b = sum32(crotl32(b + _f(c, d, a) + buffer[3] + 0xc1bdceee, _S14), c); - a = sum32(crotl32(a + _f(b, c, d) + buffer[4] + 0xf57c0faf, _S11), b); - d = sum32(crotl32(d + _f(a, b, c) + buffer[5] + 0x4787c62a, _S12), a); - c = sum32(crotl32(c + _f(d, a, b) + buffer[6] + 0xa8304613, _S13), d); - b = sum32(crotl32(b + _f(c, d, a) + buffer[7] + 0xfd469501, _S14), c); - a = sum32(crotl32(a + _f(b, c, d) + buffer[8] + 0x698098d8, _S11), b); - d = sum32(crotl32(d + _f(a, b, c) + buffer[9] + 0x8b44f7af, _S12), a); - c = sum32(crotl32(c + _f(d, a, b) + buffer[10] + 0xffff5bb1, _S13), d); - b = sum32(crotl32(b + _f(c, d, a) + buffer[11] + 0x895cd7be, _S14), c); - a = sum32(crotl32(a + _f(b, c, d) + buffer[12] + 0x6b901122, _S11), b); - d = sum32(crotl32(d + _f(a, b, c) + buffer[13] + 0xfd987193, _S12), a); - c = sum32(crotl32(c + _f(d, a, b) + buffer[14] + 0xa679438e, _S13), d); - b = sum32(crotl32(b + _f(c, d, a) + buffer[15] + 0x49b40821, _S14), c); - - // Round 2 - G cycle, 16 time_S. - a = sum32(crotl32(a + _g(b, c, d) + buffer[1] + 0xf61e2562, _S21), b); - d = sum32(crotl32(d + _g(a, b, c) + buffer[6] + 0xc040b340, _S22), a); - c = sum32(crotl32(c + _g(d, a, b) + buffer[11] + 0x265e5a51, _S23), d); - b = sum32(crotl32(b + _g(c, d, a) + buffer[0] + 0xe9b6c7aa, _S24), c); - a = sum32(crotl32(a + _g(b, c, d) + buffer[5] + 0xd62f105d, _S21), b); - d = sum32(crotl32(d + _g(a, b, c) + buffer[10] + 0x02441453, _S22), a); - c = sum32(crotl32(c + _g(d, a, b) + buffer[15] + 0xd8a1e681, _S23), d); - b = sum32(crotl32(b + _g(c, d, a) + buffer[4] + 0xe7d3fbc8, _S24), c); - a = sum32(crotl32(a + _g(b, c, d) + buffer[9] + 0x21e1cde6, _S21), b); - d = sum32(crotl32(d + _g(a, b, c) + buffer[14] + 0xc33707d6, _S22), a); - c = sum32(crotl32(c + _g(d, a, b) + buffer[3] + 0xf4d50d87, _S23), d); - b = sum32(crotl32(b + _g(c, d, a) + buffer[8] + 0x455a14ed, _S24), c); - a = sum32(crotl32(a + _g(b, c, d) + buffer[13] + 0xa9e3e905, _S21), b); - d = sum32(crotl32(d + _g(a, b, c) + buffer[2] + 0xfcefa3f8, _S22), a); - c = sum32(crotl32(c + _g(d, a, b) + buffer[7] + 0x676f02d9, _S23), d); - b = sum32(crotl32(b + _g(c, d, a) + buffer[12] + 0x8d2a4c8a, _S24), c); - - // Round 3 - H cycle, 16 time_S. - a = sum32(crotl32(a + _h(b, c, d) + buffer[5] + 0xfffa3942, _S31), b); - d = sum32(crotl32(d + _h(a, b, c) + buffer[8] + 0x8771f681, _S32), a); - c = sum32(crotl32(c + _h(d, a, b) + buffer[11] + 0x6d9d6122, _S33), d); - b = sum32(crotl32(b + _h(c, d, a) + buffer[14] + 0xfde5380c, _S34), c); - a = sum32(crotl32(a + _h(b, c, d) + buffer[1] + 0xa4beea44, _S31), b); - d = sum32(crotl32(d + _h(a, b, c) + buffer[4] + 0x4bdecfa9, _S32), a); - c = sum32(crotl32(c + _h(d, a, b) + buffer[7] + 0xf6bb4b60, _S33), d); - b = sum32(crotl32(b + _h(c, d, a) + buffer[10] + 0xbebfbc70, _S34), c); - a = sum32(crotl32(a + _h(b, c, d) + buffer[13] + 0x289b7ec6, _S31), b); - d = sum32(crotl32(d + _h(a, b, c) + buffer[0] + 0xeaa127fa, _S32), a); - c = sum32(crotl32(c + _h(d, a, b) + buffer[3] + 0xd4ef3085, _S33), d); - b = sum32(crotl32(b + _h(c, d, a) + buffer[6] + 0x04881d05, _S34), c); - a = sum32(crotl32(a + _h(b, c, d) + buffer[9] + 0xd9d4d039, _S31), b); - d = sum32(crotl32(d + _h(a, b, c) + buffer[12] + 0xe6db99e5, _S32), a); - c = sum32(crotl32(c + _h(d, a, b) + buffer[15] + 0x1fa27cf8, _S33), d); - b = sum32(crotl32(b + _h(c, d, a) + buffer[2] + 0xc4ac5665, _S34), c); - - // Round 4 - K cycle, 16 time_S. - a = sum32(crotl32(a + _k(b, c, d) + buffer[0] + 0xf4292244, _S41), b); - d = sum32(crotl32(d + _k(a, b, c) + buffer[7] + 0x432aff97, _S42), a); - c = sum32(crotl32(c + _k(d, a, b) + buffer[14] + 0xab9423a7, _S43), d); - b = sum32(crotl32(b + _k(c, d, a) + buffer[5] + 0xfc93a039, _S44), c); - a = sum32(crotl32(a + _k(b, c, d) + buffer[12] + 0x655b59c3, _S41), b); - d = sum32(crotl32(d + _k(a, b, c) + buffer[3] + 0x8f0ccc92, _S42), a); - c = sum32(crotl32(c + _k(d, a, b) + buffer[10] + 0xffeff47d, _S43), d); - b = sum32(crotl32(b + _k(c, d, a) + buffer[1] + 0x85845dd1, _S44), c); - a = sum32(crotl32(a + _k(b, c, d) + buffer[8] + 0x6fa87e4f, _S41), b); - d = sum32(crotl32(d + _k(a, b, c) + buffer[15] + 0xfe2ce6e0, _S42), a); - c = sum32(crotl32(c + _k(d, a, b) + buffer[6] + 0xa3014314, _S43), d); - b = sum32(crotl32(b + _k(c, d, a) + buffer[13] + 0x4e0811a1, _S44), c); - a = sum32(crotl32(a + _k(b, c, d) + buffer[4] + 0xf7537e82, _S41), b); - d = sum32(crotl32(d + _k(a, b, c) + buffer[11] + 0xbd3af235, _S42), a); - c = sum32(crotl32(c + _k(d, a, b) + buffer[2] + 0x2ad7d2bb, _S43), d); - b = sum32(crotl32(b + _k(c, d, a) + buffer[9] + 0xeb86d391, _S44), c); - - state[0] = clip32(state[0] + a); - state[1] = clip32(state[1] + b); - state[2] = clip32(state[2] + c); - state[3] = clip32(state[3] + d); - } - - // round 1 left rotates - static const _S11 = 7; - static const _S12 = 12; - static const _S13 = 17; - static const _S14 = 22; - - // round 2 left rotates - static const _S21 = 5; - static const _S22 = 9; - static const _S23 = 14; - static const _S24 = 20; - - // round 3 left rotates - static const _S31 = 4; - static const _S32 = 11; - static const _S33 = 16; - static const _S34 = 23; - - // round 4 left rotates - static const _S41 = 6; - static const _S42 = 10; - static const _S43 = 15; - static const _S44 = 21; - - int _f(int u, int v, int w) => (u & v) | (not32(u) & w); - - int _g(int u, int v, int w) => (u & w) | (v & not32(w)); - - int _h(int u, int v, int w) => u ^ v ^ w; - - int _k(int u, int v, int w) => v ^ (u | not32(w)); - - @override - int get byteLength => 64; -} diff --git a/pointycastle/lib/digests/ripemd128.dart b/pointycastle/lib/digests/ripemd128.dart deleted file mode 100644 index 2b98944..0000000 --- a/pointycastle/lib/digests/ripemd128.dart +++ /dev/null @@ -1,232 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.ripemd128; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/md4_family_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of RIPEMD-128 digest -class RIPEMD128Digest extends MD4FamilyDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'RIPEMD-128', () => RIPEMD128Digest()); - - static const _DIGEST_LENGTH = 16; - - RIPEMD128Digest() : super(Endian.little, 4, 16); - - @override - final algorithmName = 'RIPEMD-128'; - - @override - final digestSize = _DIGEST_LENGTH; - - @override - void resetState() { - state[0] = 0x67452301; - state[1] = 0xefcdab89; - state[2] = 0x98badcfe; - state[3] = 0x10325476; - } - - @override - void processBlock() { - int? a, aa; - int? b, bb; - int? c, cc; - int? d, dd; - - a = aa = state[0]; - b = bb = state[1]; - c = cc = state[2]; - d = dd = state[3]; - - // Round 1 - a = _f1(a, b, c, d, buffer[0], 11); - d = _f1(d, a, b, c, buffer[1], 14); - c = _f1(c, d, a, b, buffer[2], 15); - b = _f1(b, c, d, a, buffer[3], 12); - a = _f1(a, b, c, d, buffer[4], 5); - d = _f1(d, a, b, c, buffer[5], 8); - c = _f1(c, d, a, b, buffer[6], 7); - b = _f1(b, c, d, a, buffer[7], 9); - a = _f1(a, b, c, d, buffer[8], 11); - d = _f1(d, a, b, c, buffer[9], 13); - c = _f1(c, d, a, b, buffer[10], 14); - b = _f1(b, c, d, a, buffer[11], 15); - a = _f1(a, b, c, d, buffer[12], 6); - d = _f1(d, a, b, c, buffer[13], 7); - c = _f1(c, d, a, b, buffer[14], 9); - b = _f1(b, c, d, a, buffer[15], 8); - - // Round 2 - a = _f2(a, b, c, d, buffer[7], 7); - d = _f2(d, a, b, c, buffer[4], 6); - c = _f2(c, d, a, b, buffer[13], 8); - b = _f2(b, c, d, a, buffer[1], 13); - a = _f2(a, b, c, d, buffer[10], 11); - d = _f2(d, a, b, c, buffer[6], 9); - c = _f2(c, d, a, b, buffer[15], 7); - b = _f2(b, c, d, a, buffer[3], 15); - a = _f2(a, b, c, d, buffer[12], 7); - d = _f2(d, a, b, c, buffer[0], 12); - c = _f2(c, d, a, b, buffer[9], 15); - b = _f2(b, c, d, a, buffer[5], 9); - a = _f2(a, b, c, d, buffer[2], 11); - d = _f2(d, a, b, c, buffer[14], 7); - c = _f2(c, d, a, b, buffer[11], 13); - b = _f2(b, c, d, a, buffer[8], 12); - - // Round 3 - a = _f3(a, b, c, d, buffer[3], 11); - d = _f3(d, a, b, c, buffer[10], 13); - c = _f3(c, d, a, b, buffer[14], 6); - b = _f3(b, c, d, a, buffer[4], 7); - a = _f3(a, b, c, d, buffer[9], 14); - d = _f3(d, a, b, c, buffer[15], 9); - c = _f3(c, d, a, b, buffer[8], 13); - b = _f3(b, c, d, a, buffer[1], 15); - a = _f3(a, b, c, d, buffer[2], 14); - d = _f3(d, a, b, c, buffer[7], 8); - c = _f3(c, d, a, b, buffer[0], 13); - b = _f3(b, c, d, a, buffer[6], 6); - a = _f3(a, b, c, d, buffer[13], 5); - d = _f3(d, a, b, c, buffer[11], 12); - c = _f3(c, d, a, b, buffer[5], 7); - b = _f3(b, c, d, a, buffer[12], 5); - - // Round 4 - a = _f4(a, b, c, d, buffer[1], 11); - d = _f4(d, a, b, c, buffer[9], 12); - c = _f4(c, d, a, b, buffer[11], 14); - b = _f4(b, c, d, a, buffer[10], 15); - a = _f4(a, b, c, d, buffer[0], 14); - d = _f4(d, a, b, c, buffer[8], 15); - c = _f4(c, d, a, b, buffer[12], 9); - b = _f4(b, c, d, a, buffer[4], 8); - a = _f4(a, b, c, d, buffer[13], 9); - d = _f4(d, a, b, c, buffer[3], 14); - c = _f4(c, d, a, b, buffer[7], 5); - b = _f4(b, c, d, a, buffer[15], 6); - a = _f4(a, b, c, d, buffer[14], 8); - d = _f4(d, a, b, c, buffer[5], 6); - c = _f4(c, d, a, b, buffer[6], 5); - b = _f4(b, c, d, a, buffer[2], 12); - - // Parallel round 1 - aa = _ff4(aa, bb, cc, dd, buffer[5], 8); - dd = _ff4(dd, aa, bb, cc, buffer[14], 9); - cc = _ff4(cc, dd, aa, bb, buffer[7], 9); - bb = _ff4(bb, cc, dd, aa, buffer[0], 11); - aa = _ff4(aa, bb, cc, dd, buffer[9], 13); - dd = _ff4(dd, aa, bb, cc, buffer[2], 15); - cc = _ff4(cc, dd, aa, bb, buffer[11], 15); - bb = _ff4(bb, cc, dd, aa, buffer[4], 5); - aa = _ff4(aa, bb, cc, dd, buffer[13], 7); - dd = _ff4(dd, aa, bb, cc, buffer[6], 7); - cc = _ff4(cc, dd, aa, bb, buffer[15], 8); - bb = _ff4(bb, cc, dd, aa, buffer[8], 11); - aa = _ff4(aa, bb, cc, dd, buffer[1], 14); - dd = _ff4(dd, aa, bb, cc, buffer[10], 14); - cc = _ff4(cc, dd, aa, bb, buffer[3], 12); - bb = _ff4(bb, cc, dd, aa, buffer[12], 6); - - // Parallel round 2 - aa = _ff3(aa, bb, cc, dd, buffer[6], 9); - dd = _ff3(dd, aa, bb, cc, buffer[11], 13); - cc = _ff3(cc, dd, aa, bb, buffer[3], 15); - bb = _ff3(bb, cc, dd, aa, buffer[7], 7); - aa = _ff3(aa, bb, cc, dd, buffer[0], 12); - dd = _ff3(dd, aa, bb, cc, buffer[13], 8); - cc = _ff3(cc, dd, aa, bb, buffer[5], 9); - bb = _ff3(bb, cc, dd, aa, buffer[10], 11); - aa = _ff3(aa, bb, cc, dd, buffer[14], 7); - dd = _ff3(dd, aa, bb, cc, buffer[15], 7); - cc = _ff3(cc, dd, aa, bb, buffer[8], 12); - bb = _ff3(bb, cc, dd, aa, buffer[12], 7); - aa = _ff3(aa, bb, cc, dd, buffer[4], 6); - dd = _ff3(dd, aa, bb, cc, buffer[9], 15); - cc = _ff3(cc, dd, aa, bb, buffer[1], 13); - bb = _ff3(bb, cc, dd, aa, buffer[2], 11); - - // Parallel round 3 - aa = _ff2(aa, bb, cc, dd, buffer[15], 9); - dd = _ff2(dd, aa, bb, cc, buffer[5], 7); - cc = _ff2(cc, dd, aa, bb, buffer[1], 15); - bb = _ff2(bb, cc, dd, aa, buffer[3], 11); - aa = _ff2(aa, bb, cc, dd, buffer[7], 8); - dd = _ff2(dd, aa, bb, cc, buffer[14], 6); - cc = _ff2(cc, dd, aa, bb, buffer[6], 6); - bb = _ff2(bb, cc, dd, aa, buffer[9], 14); - aa = _ff2(aa, bb, cc, dd, buffer[11], 12); - dd = _ff2(dd, aa, bb, cc, buffer[8], 13); - cc = _ff2(cc, dd, aa, bb, buffer[12], 5); - bb = _ff2(bb, cc, dd, aa, buffer[2], 14); - aa = _ff2(aa, bb, cc, dd, buffer[10], 13); - dd = _ff2(dd, aa, bb, cc, buffer[0], 13); - cc = _ff2(cc, dd, aa, bb, buffer[4], 7); - bb = _ff2(bb, cc, dd, aa, buffer[13], 5); - - // Parallel round 4 - aa = _ff1(aa, bb, cc, dd, buffer[8], 15); - dd = _ff1(dd, aa, bb, cc, buffer[6], 5); - cc = _ff1(cc, dd, aa, bb, buffer[4], 8); - bb = _ff1(bb, cc, dd, aa, buffer[1], 11); - aa = _ff1(aa, bb, cc, dd, buffer[3], 14); - dd = _ff1(dd, aa, bb, cc, buffer[11], 14); - cc = _ff1(cc, dd, aa, bb, buffer[15], 6); - bb = _ff1(bb, cc, dd, aa, buffer[0], 14); - aa = _ff1(aa, bb, cc, dd, buffer[5], 6); - dd = _ff1(dd, aa, bb, cc, buffer[12], 9); - cc = _ff1(cc, dd, aa, bb, buffer[2], 12); - bb = _ff1(bb, cc, dd, aa, buffer[13], 9); - aa = _ff1(aa, bb, cc, dd, buffer[9], 12); - dd = _ff1(dd, aa, bb, cc, buffer[7], 5); - cc = _ff1(cc, dd, aa, bb, buffer[10], 15); - bb = _ff1(bb, cc, dd, aa, buffer[14], 8); - - dd = clip32(dd + c + state[1]); - state[1] = clip32(state[2] + d + aa); - state[2] = clip32(state[3] + a + bb); - state[3] = clip32(state[0] + b + cc); - state[0] = dd; - } - - int _function1(int x, int y, int z) => x ^ y ^ z; - - int _function2(int x, int y, int z) => (x & y) | (~x & z); - - int _function3(int x, int y, int z) => (x | ~y) ^ z; - - int _function4(int x, int y, int z) => (x & z) | (y & ~z); - - int _f1(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function1(b, c, d) + x, s); - - int _f2(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function2(b, c, d) + x + 0x5a827999, s); - - int _f3(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function3(b, c, d) + x + 0x6ed9eba1, s); - - int _f4(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function4(b, c, d) + x + 0x8f1bbcdc, s); - - int _ff1(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function1(b, c, d) + x, s); - - int _ff2(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function2(b, c, d) + x + 0x6d703ef3, s); - - int _ff3(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function3(b, c, d) + x + 0x5c4dd124, s); - - int _ff4(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function4(b, c, d) + x + 0x50a28be6, s); - - @override - int get byteLength => 64; -} diff --git a/pointycastle/lib/digests/ripemd160.dart b/pointycastle/lib/digests/ripemd160.dart deleted file mode 100644 index 1384caf..0000000 --- a/pointycastle/lib/digests/ripemd160.dart +++ /dev/null @@ -1,415 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.ripemd160; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/md4_family_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of RIPEMD-160 digest. -class RIPEMD160Digest extends MD4FamilyDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'RIPEMD-160', () => RIPEMD160Digest()); - - static const _DIGEST_LENGTH = 20; - - RIPEMD160Digest() : super(Endian.little, 5, 16); - - @override - final algorithmName = 'RIPEMD-160'; - - @override - final digestSize = _DIGEST_LENGTH; - - @override - void resetState() { - state[0] = 0x67452301; - state[1] = 0xefcdab89; - state[2] = 0x98badcfe; - state[3] = 0x10325476; - state[4] = 0xc3d2e1f0; - } - - @override - void processBlock() { - int? a, aa; - int? b, bb; - int? c, cc; - int? d, dd; - int? e, ee; - - a = aa = state[0]; - b = bb = state[1]; - c = cc = state[2]; - d = dd = state[3]; - e = ee = state[4]; - - // Rounds 1 - 16 - // left - a = sum32(crotl32(a + _f1(b, c, d) + buffer[0], 11), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f1(a, b, c) + buffer[1], 14), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f1(e, a, b) + buffer[2], 15), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f1(d, e, a) + buffer[3], 12), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f1(c, d, e) + buffer[4], 5), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f1(b, c, d) + buffer[5], 8), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f1(a, b, c) + buffer[6], 7), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f1(e, a, b) + buffer[7], 9), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f1(d, e, a) + buffer[8], 11), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f1(c, d, e) + buffer[9], 13), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f1(b, c, d) + buffer[10], 14), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f1(a, b, c) + buffer[11], 15), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f1(e, a, b) + buffer[12], 6), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f1(d, e, a) + buffer[13], 7), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f1(c, d, e) + buffer[14], 9), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f1(b, c, d) + buffer[15], 8), e); - c = rotl32(c, 10); - - // right - aa = sum32(crotl32(aa + _f5(bb, cc, dd) + buffer[5] + 0x50a28be6, 8), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f5(aa, bb, cc) + buffer[14] + 0x50a28be6, 9), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f5(ee, aa, bb) + buffer[7] + 0x50a28be6, 9), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f5(dd, ee, aa) + buffer[0] + 0x50a28be6, 11), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f5(cc, dd, ee) + buffer[9] + 0x50a28be6, 13), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f5(bb, cc, dd) + buffer[2] + 0x50a28be6, 15), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f5(aa, bb, cc) + buffer[11] + 0x50a28be6, 15), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f5(ee, aa, bb) + buffer[4] + 0x50a28be6, 5), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f5(dd, ee, aa) + buffer[13] + 0x50a28be6, 7), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f5(cc, dd, ee) + buffer[6] + 0x50a28be6, 7), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f5(bb, cc, dd) + buffer[15] + 0x50a28be6, 8), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f5(aa, bb, cc) + buffer[8] + 0x50a28be6, 11), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f5(ee, aa, bb) + buffer[1] + 0x50a28be6, 14), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f5(dd, ee, aa) + buffer[10] + 0x50a28be6, 14), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f5(cc, dd, ee) + buffer[3] + 0x50a28be6, 12), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f5(bb, cc, dd) + buffer[12] + 0x50a28be6, 6), ee); - cc = rotl32(cc, 10); - - // Rounds 16-31 - // left - e = sum32(crotl32(e + _f2(a, b, c) + buffer[7] + 0x5a827999, 7), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f2(e, a, b) + buffer[4] + 0x5a827999, 6), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f2(d, e, a) + buffer[13] + 0x5a827999, 8), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f2(c, d, e) + buffer[1] + 0x5a827999, 13), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f2(b, c, d) + buffer[10] + 0x5a827999, 11), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f2(a, b, c) + buffer[6] + 0x5a827999, 9), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f2(e, a, b) + buffer[15] + 0x5a827999, 7), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f2(d, e, a) + buffer[3] + 0x5a827999, 15), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f2(c, d, e) + buffer[12] + 0x5a827999, 7), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f2(b, c, d) + buffer[0] + 0x5a827999, 12), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f2(a, b, c) + buffer[9] + 0x5a827999, 15), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f2(e, a, b) + buffer[5] + 0x5a827999, 9), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f2(d, e, a) + buffer[2] + 0x5a827999, 11), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f2(c, d, e) + buffer[14] + 0x5a827999, 7), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f2(b, c, d) + buffer[11] + 0x5a827999, 13), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f2(a, b, c) + buffer[8] + 0x5a827999, 12), d); - b = rotl32(b, 10); - - // right - ee = sum32(crotl32(ee + _f4(aa, bb, cc) + buffer[6] + 0x5c4dd124, 9), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f4(ee, aa, bb) + buffer[11] + 0x5c4dd124, 13), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f4(dd, ee, aa) + buffer[3] + 0x5c4dd124, 15), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f4(cc, dd, ee) + buffer[7] + 0x5c4dd124, 7), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f4(bb, cc, dd) + buffer[0] + 0x5c4dd124, 12), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f4(aa, bb, cc) + buffer[13] + 0x5c4dd124, 8), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f4(ee, aa, bb) + buffer[5] + 0x5c4dd124, 9), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f4(dd, ee, aa) + buffer[10] + 0x5c4dd124, 11), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f4(cc, dd, ee) + buffer[14] + 0x5c4dd124, 7), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f4(bb, cc, dd) + buffer[15] + 0x5c4dd124, 7), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f4(aa, bb, cc) + buffer[8] + 0x5c4dd124, 12), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f4(ee, aa, bb) + buffer[12] + 0x5c4dd124, 7), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f4(dd, ee, aa) + buffer[4] + 0x5c4dd124, 6), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f4(cc, dd, ee) + buffer[9] + 0x5c4dd124, 15), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f4(bb, cc, dd) + buffer[1] + 0x5c4dd124, 13), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f4(aa, bb, cc) + buffer[2] + 0x5c4dd124, 11), dd); - bb = rotl32(bb, 10); - - // Rounds 32-47 - // left - d = sum32(crotl32(d + _f3(e, a, b) + buffer[3] + 0x6ed9eba1, 11), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f3(d, e, a) + buffer[10] + 0x6ed9eba1, 13), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f3(c, d, e) + buffer[14] + 0x6ed9eba1, 6), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f3(b, c, d) + buffer[4] + 0x6ed9eba1, 7), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f3(a, b, c) + buffer[9] + 0x6ed9eba1, 14), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f3(e, a, b) + buffer[15] + 0x6ed9eba1, 9), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f3(d, e, a) + buffer[8] + 0x6ed9eba1, 13), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f3(c, d, e) + buffer[1] + 0x6ed9eba1, 15), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f3(b, c, d) + buffer[2] + 0x6ed9eba1, 14), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f3(a, b, c) + buffer[7] + 0x6ed9eba1, 8), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f3(e, a, b) + buffer[0] + 0x6ed9eba1, 13), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f3(d, e, a) + buffer[6] + 0x6ed9eba1, 6), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f3(c, d, e) + buffer[13] + 0x6ed9eba1, 5), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f3(b, c, d) + buffer[11] + 0x6ed9eba1, 12), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f3(a, b, c) + buffer[5] + 0x6ed9eba1, 7), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f3(e, a, b) + buffer[12] + 0x6ed9eba1, 5), c); - a = rotl32(a, 10); - - // right - dd = sum32(crotl32(dd + _f3(ee, aa, bb) + buffer[15] + 0x6d703ef3, 9), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f3(dd, ee, aa) + buffer[5] + 0x6d703ef3, 7), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f3(cc, dd, ee) + buffer[1] + 0x6d703ef3, 15), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f3(bb, cc, dd) + buffer[3] + 0x6d703ef3, 11), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f3(aa, bb, cc) + buffer[7] + 0x6d703ef3, 8), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f3(ee, aa, bb) + buffer[14] + 0x6d703ef3, 6), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f3(dd, ee, aa) + buffer[6] + 0x6d703ef3, 6), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f3(cc, dd, ee) + buffer[9] + 0x6d703ef3, 14), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f3(bb, cc, dd) + buffer[11] + 0x6d703ef3, 12), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f3(aa, bb, cc) + buffer[8] + 0x6d703ef3, 13), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f3(ee, aa, bb) + buffer[12] + 0x6d703ef3, 5), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f3(dd, ee, aa) + buffer[2] + 0x6d703ef3, 14), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f3(cc, dd, ee) + buffer[10] + 0x6d703ef3, 13), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f3(bb, cc, dd) + buffer[0] + 0x6d703ef3, 13), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f3(aa, bb, cc) + buffer[4] + 0x6d703ef3, 7), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f3(ee, aa, bb) + buffer[13] + 0x6d703ef3, 5), cc); - aa = rotl32(aa, 10); - - // Rounds 48-63 - // left - c = sum32(crotl32(c + _f4(d, e, a) + buffer[1] + 0x8f1bbcdc, 11), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f4(c, d, e) + buffer[9] + 0x8f1bbcdc, 12), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f4(b, c, d) + buffer[11] + 0x8f1bbcdc, 14), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f4(a, b, c) + buffer[10] + 0x8f1bbcdc, 15), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f4(e, a, b) + buffer[0] + 0x8f1bbcdc, 14), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f4(d, e, a) + buffer[8] + 0x8f1bbcdc, 15), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f4(c, d, e) + buffer[12] + 0x8f1bbcdc, 9), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f4(b, c, d) + buffer[4] + 0x8f1bbcdc, 8), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f4(a, b, c) + buffer[13] + 0x8f1bbcdc, 9), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f4(e, a, b) + buffer[3] + 0x8f1bbcdc, 14), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f4(d, e, a) + buffer[7] + 0x8f1bbcdc, 5), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f4(c, d, e) + buffer[15] + 0x8f1bbcdc, 6), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f4(b, c, d) + buffer[14] + 0x8f1bbcdc, 8), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f4(a, b, c) + buffer[5] + 0x8f1bbcdc, 6), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f4(e, a, b) + buffer[6] + 0x8f1bbcdc, 5), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f4(d, e, a) + buffer[2] + 0x8f1bbcdc, 12), b); - e = rotl32(e, 10); - - // right - cc = sum32(crotl32(cc + _f2(dd, ee, aa) + buffer[8] + 0x7a6d76e9, 15), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f2(cc, dd, ee) + buffer[6] + 0x7a6d76e9, 5), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f2(bb, cc, dd) + buffer[4] + 0x7a6d76e9, 8), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f2(aa, bb, cc) + buffer[1] + 0x7a6d76e9, 11), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f2(ee, aa, bb) + buffer[3] + 0x7a6d76e9, 14), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f2(dd, ee, aa) + buffer[11] + 0x7a6d76e9, 14), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f2(cc, dd, ee) + buffer[15] + 0x7a6d76e9, 6), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f2(bb, cc, dd) + buffer[0] + 0x7a6d76e9, 14), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f2(aa, bb, cc) + buffer[5] + 0x7a6d76e9, 6), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f2(ee, aa, bb) + buffer[12] + 0x7a6d76e9, 9), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f2(dd, ee, aa) + buffer[2] + 0x7a6d76e9, 12), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f2(cc, dd, ee) + buffer[13] + 0x7a6d76e9, 9), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f2(bb, cc, dd) + buffer[9] + 0x7a6d76e9, 12), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f2(aa, bb, cc) + buffer[7] + 0x7a6d76e9, 5), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f2(ee, aa, bb) + buffer[10] + 0x7a6d76e9, 15), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f2(dd, ee, aa) + buffer[14] + 0x7a6d76e9, 8), bb); - ee = rotl32(ee, 10); - - // Rounds 64-79 - // left - b = sum32(crotl32(b + _f5(c, d, e) + buffer[4] + 0xa953fd4e, 9), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f5(b, c, d) + buffer[0] + 0xa953fd4e, 15), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f5(a, b, c) + buffer[5] + 0xa953fd4e, 5), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f5(e, a, b) + buffer[9] + 0xa953fd4e, 11), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f5(d, e, a) + buffer[7] + 0xa953fd4e, 6), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f5(c, d, e) + buffer[12] + 0xa953fd4e, 8), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f5(b, c, d) + buffer[2] + 0xa953fd4e, 13), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f5(a, b, c) + buffer[10] + 0xa953fd4e, 12), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f5(e, a, b) + buffer[14] + 0xa953fd4e, 5), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f5(d, e, a) + buffer[1] + 0xa953fd4e, 12), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f5(c, d, e) + buffer[3] + 0xa953fd4e, 13), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f5(b, c, d) + buffer[8] + 0xa953fd4e, 14), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f5(a, b, c) + buffer[11] + 0xa953fd4e, 11), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f5(e, a, b) + buffer[6] + 0xa953fd4e, 8), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f5(d, e, a) + buffer[15] + 0xa953fd4e, 5), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f5(c, d, e) + buffer[13] + 0xa953fd4e, 6), a); - d = rotl32(d, 10); - - // right - bb = sum32(crotl32(bb + _f1(cc, dd, ee) + buffer[12], 8), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f1(bb, cc, dd) + buffer[15], 5), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f1(aa, bb, cc) + buffer[10], 12), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f1(ee, aa, bb) + buffer[4], 9), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f1(dd, ee, aa) + buffer[1], 12), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f1(cc, dd, ee) + buffer[5], 5), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f1(bb, cc, dd) + buffer[8], 14), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f1(aa, bb, cc) + buffer[7], 6), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f1(ee, aa, bb) + buffer[6], 8), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f1(dd, ee, aa) + buffer[2], 13), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f1(cc, dd, ee) + buffer[13], 6), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f1(bb, cc, dd) + buffer[14], 5), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f1(aa, bb, cc) + buffer[0], 15), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f1(ee, aa, bb) + buffer[3], 13), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f1(dd, ee, aa) + buffer[9], 11), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f1(cc, dd, ee) + buffer[11], 11), aa); - dd = rotl32(dd, 10); - - dd = clip32(dd + c + state[1]); - state[1] = clip32(state[2] + d + ee); - state[2] = clip32(state[3] + e + aa); - state[3] = clip32(state[4] + a + bb); - state[4] = clip32(state[0] + b + cc); - state[0] = dd; - } - - int _f1(int x, int y, int z) => x ^ y ^ z; - - int _f2(int x, int y, int z) => (x & y) | (~x & z); - - int _f3(int x, int y, int z) => (x | ~y) ^ z; - - int _f4(int x, int y, int z) => (x & z) | (y & ~z); - - int _f5(int x, int y, int z) => x ^ (y | ~z); - - @override - int get byteLength => 64; -} diff --git a/pointycastle/lib/digests/ripemd256.dart b/pointycastle/lib/digests/ripemd256.dart deleted file mode 100644 index 8e4722e..0000000 --- a/pointycastle/lib/digests/ripemd256.dart +++ /dev/null @@ -1,256 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.ripemd256; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/md4_family_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of RIPEMD-256 digest. -class RIPEMD256Digest extends MD4FamilyDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'RIPEMD-256', () => RIPEMD256Digest()); - - static const _DIGEST_LENGTH = 32; - - RIPEMD256Digest() : super(Endian.little, 8, 16); - - @override - final algorithmName = 'RIPEMD-256'; - - @override - final digestSize = _DIGEST_LENGTH; - - @override - void resetState() { - state[0] = 0x67452301; - state[1] = 0xefcdab89; - state[2] = 0x98badcfe; - state[3] = 0x10325476; - state[4] = 0x76543210; - state[5] = 0xFEDCBA98; - state[6] = 0x89ABCDEF; - state[7] = 0x01234567; - } - - @override - void processBlock() { - int? a, aa; - int? b, bb; - int? c, cc; - int? d, dd; - int t; - - a = state[0]; - b = state[1]; - c = state[2]; - d = state[3]; - aa = state[4]; - bb = state[5]; - cc = state[6]; - dd = state[7]; - - // Round 1 - a = _f1(a, b, c, d, buffer[0], 11); - d = _f1(d, a, b, c, buffer[1], 14); - c = _f1(c, d, a, b, buffer[2], 15); - b = _f1(b, c, d, a, buffer[3], 12); - a = _f1(a, b, c, d, buffer[4], 5); - d = _f1(d, a, b, c, buffer[5], 8); - c = _f1(c, d, a, b, buffer[6], 7); - b = _f1(b, c, d, a, buffer[7], 9); - a = _f1(a, b, c, d, buffer[8], 11); - d = _f1(d, a, b, c, buffer[9], 13); - c = _f1(c, d, a, b, buffer[10], 14); - b = _f1(b, c, d, a, buffer[11], 15); - a = _f1(a, b, c, d, buffer[12], 6); - d = _f1(d, a, b, c, buffer[13], 7); - c = _f1(c, d, a, b, buffer[14], 9); - b = _f1(b, c, d, a, buffer[15], 8); - - aa = _ff4(aa, bb, cc, dd, buffer[5], 8); - dd = _ff4(dd, aa, bb, cc, buffer[14], 9); - cc = _ff4(cc, dd, aa, bb, buffer[7], 9); - bb = _ff4(bb, cc, dd, aa, buffer[0], 11); - aa = _ff4(aa, bb, cc, dd, buffer[9], 13); - dd = _ff4(dd, aa, bb, cc, buffer[2], 15); - cc = _ff4(cc, dd, aa, bb, buffer[11], 15); - bb = _ff4(bb, cc, dd, aa, buffer[4], 5); - aa = _ff4(aa, bb, cc, dd, buffer[13], 7); - dd = _ff4(dd, aa, bb, cc, buffer[6], 7); - cc = _ff4(cc, dd, aa, bb, buffer[15], 8); - bb = _ff4(bb, cc, dd, aa, buffer[8], 11); - aa = _ff4(aa, bb, cc, dd, buffer[1], 14); - dd = _ff4(dd, aa, bb, cc, buffer[10], 14); - cc = _ff4(cc, dd, aa, bb, buffer[3], 12); - bb = _ff4(bb, cc, dd, aa, buffer[12], 6); - - t = a; - a = aa; - aa = t; - - // Round 2 - a = _f2(a, b, c, d, buffer[7], 7); - d = _f2(d, a, b, c, buffer[4], 6); - c = _f2(c, d, a, b, buffer[13], 8); - b = _f2(b, c, d, a, buffer[1], 13); - a = _f2(a, b, c, d, buffer[10], 11); - d = _f2(d, a, b, c, buffer[6], 9); - c = _f2(c, d, a, b, buffer[15], 7); - b = _f2(b, c, d, a, buffer[3], 15); - a = _f2(a, b, c, d, buffer[12], 7); - d = _f2(d, a, b, c, buffer[0], 12); - c = _f2(c, d, a, b, buffer[9], 15); - b = _f2(b, c, d, a, buffer[5], 9); - a = _f2(a, b, c, d, buffer[2], 11); - d = _f2(d, a, b, c, buffer[14], 7); - c = _f2(c, d, a, b, buffer[11], 13); - b = _f2(b, c, d, a, buffer[8], 12); - - aa = _ff3(aa, bb, cc, dd, buffer[6], 9); - dd = _ff3(dd, aa, bb, cc, buffer[11], 13); - cc = _ff3(cc, dd, aa, bb, buffer[3], 15); - bb = _ff3(bb, cc, dd, aa, buffer[7], 7); - aa = _ff3(aa, bb, cc, dd, buffer[0], 12); - dd = _ff3(dd, aa, bb, cc, buffer[13], 8); - cc = _ff3(cc, dd, aa, bb, buffer[5], 9); - bb = _ff3(bb, cc, dd, aa, buffer[10], 11); - aa = _ff3(aa, bb, cc, dd, buffer[14], 7); - dd = _ff3(dd, aa, bb, cc, buffer[15], 7); - cc = _ff3(cc, dd, aa, bb, buffer[8], 12); - bb = _ff3(bb, cc, dd, aa, buffer[12], 7); - aa = _ff3(aa, bb, cc, dd, buffer[4], 6); - dd = _ff3(dd, aa, bb, cc, buffer[9], 15); - cc = _ff3(cc, dd, aa, bb, buffer[1], 13); - bb = _ff3(bb, cc, dd, aa, buffer[2], 11); - - t = b; - b = bb; - bb = t; - - // Round 3 - a = _f3(a, b, c, d, buffer[3], 11); - d = _f3(d, a, b, c, buffer[10], 13); - c = _f3(c, d, a, b, buffer[14], 6); - b = _f3(b, c, d, a, buffer[4], 7); - a = _f3(a, b, c, d, buffer[9], 14); - d = _f3(d, a, b, c, buffer[15], 9); - c = _f3(c, d, a, b, buffer[8], 13); - b = _f3(b, c, d, a, buffer[1], 15); - a = _f3(a, b, c, d, buffer[2], 14); - d = _f3(d, a, b, c, buffer[7], 8); - c = _f3(c, d, a, b, buffer[0], 13); - b = _f3(b, c, d, a, buffer[6], 6); - a = _f3(a, b, c, d, buffer[13], 5); - d = _f3(d, a, b, c, buffer[11], 12); - c = _f3(c, d, a, b, buffer[5], 7); - b = _f3(b, c, d, a, buffer[12], 5); - - aa = _ff2(aa, bb, cc, dd, buffer[15], 9); - dd = _ff2(dd, aa, bb, cc, buffer[5], 7); - cc = _ff2(cc, dd, aa, bb, buffer[1], 15); - bb = _ff2(bb, cc, dd, aa, buffer[3], 11); - aa = _ff2(aa, bb, cc, dd, buffer[7], 8); - dd = _ff2(dd, aa, bb, cc, buffer[14], 6); - cc = _ff2(cc, dd, aa, bb, buffer[6], 6); - bb = _ff2(bb, cc, dd, aa, buffer[9], 14); - aa = _ff2(aa, bb, cc, dd, buffer[11], 12); - dd = _ff2(dd, aa, bb, cc, buffer[8], 13); - cc = _ff2(cc, dd, aa, bb, buffer[12], 5); - bb = _ff2(bb, cc, dd, aa, buffer[2], 14); - aa = _ff2(aa, bb, cc, dd, buffer[10], 13); - dd = _ff2(dd, aa, bb, cc, buffer[0], 13); - cc = _ff2(cc, dd, aa, bb, buffer[4], 7); - bb = _ff2(bb, cc, dd, aa, buffer[13], 5); - - t = c; - c = cc; - cc = t; - - // Round 4 - a = _f4(a, b, c, d, buffer[1], 11); - d = _f4(d, a, b, c, buffer[9], 12); - c = _f4(c, d, a, b, buffer[11], 14); - b = _f4(b, c, d, a, buffer[10], 15); - a = _f4(a, b, c, d, buffer[0], 14); - d = _f4(d, a, b, c, buffer[8], 15); - c = _f4(c, d, a, b, buffer[12], 9); - b = _f4(b, c, d, a, buffer[4], 8); - a = _f4(a, b, c, d, buffer[13], 9); - d = _f4(d, a, b, c, buffer[3], 14); - c = _f4(c, d, a, b, buffer[7], 5); - b = _f4(b, c, d, a, buffer[15], 6); - a = _f4(a, b, c, d, buffer[14], 8); - d = _f4(d, a, b, c, buffer[5], 6); - c = _f4(c, d, a, b, buffer[6], 5); - b = _f4(b, c, d, a, buffer[2], 12); - - aa = _ff1(aa, bb, cc, dd, buffer[8], 15); - dd = _ff1(dd, aa, bb, cc, buffer[6], 5); - cc = _ff1(cc, dd, aa, bb, buffer[4], 8); - bb = _ff1(bb, cc, dd, aa, buffer[1], 11); - aa = _ff1(aa, bb, cc, dd, buffer[3], 14); - dd = _ff1(dd, aa, bb, cc, buffer[11], 14); - cc = _ff1(cc, dd, aa, bb, buffer[15], 6); - bb = _ff1(bb, cc, dd, aa, buffer[0], 14); - aa = _ff1(aa, bb, cc, dd, buffer[5], 6); - dd = _ff1(dd, aa, bb, cc, buffer[12], 9); - cc = _ff1(cc, dd, aa, bb, buffer[2], 12); - bb = _ff1(bb, cc, dd, aa, buffer[13], 9); - aa = _ff1(aa, bb, cc, dd, buffer[9], 12); - dd = _ff1(dd, aa, bb, cc, buffer[7], 5); - cc = _ff1(cc, dd, aa, bb, buffer[10], 15); - bb = _ff1(bb, cc, dd, aa, buffer[14], 8); - - t = d; - d = dd; - dd = t; - - state[0] = sum32(state[0], a); - state[1] = sum32(state[1], b); - state[2] = sum32(state[2], c); - state[3] = sum32(state[3], d); - state[4] = sum32(state[4], aa); - state[5] = sum32(state[5], bb); - state[6] = sum32(state[6], cc); - state[7] = sum32(state[7], dd); - } - - int _function1(int x, int y, int z) => x ^ y ^ z; - - int _function2(int x, int y, int z) => (x & y) | (~x & z); - - int _function3(int x, int y, int z) => (x | ~y) ^ z; - - int _function4(int x, int y, int z) => (x & z) | (y & ~z); - - int _f1(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function1(b, c, d) + x, s); - - int _f2(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function2(b, c, d) + x + 0x5a827999, s); - - int _f3(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function3(b, c, d) + x + 0x6ed9eba1, s); - - int _f4(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function4(b, c, d) + x + 0x8f1bbcdc, s); - - int _ff1(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function1(b, c, d) + x, s); - - int _ff2(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function2(b, c, d) + x + 0x6d703ef3, s); - - int _ff3(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function3(b, c, d) + x + 0x5c4dd124, s); - - int _ff4(int a, int b, int c, int d, int x, int s) => - crotl32(a + _function4(b, c, d) + x + 0x50a28be6, s); - - @override - int get byteLength => 64; -} diff --git a/pointycastle/lib/digests/ripemd320.dart b/pointycastle/lib/digests/ripemd320.dart deleted file mode 100644 index 1cdb878..0000000 --- a/pointycastle/lib/digests/ripemd320.dart +++ /dev/null @@ -1,456 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.ripemd320; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/md4_family_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of RIPEMD-320 digest. -class RIPEMD320Digest extends MD4FamilyDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'RIPEMD-320', () => RIPEMD320Digest()); - - static const _DIGEST_LENGTH = 40; - - RIPEMD320Digest() : super(Endian.little, 10, 16); - @override - final algorithmName = 'RIPEMD-320'; - - @override - final digestSize = _DIGEST_LENGTH; - - @override - void resetState() { - state[0] = 0x67452301; - state[1] = 0xefcdab89; - state[2] = 0x98badcfe; - state[3] = 0x10325476; - state[4] = 0xc3d2e1f0; - state[5] = 0x76543210; - state[6] = 0xFEDCBA98; - state[7] = 0x89ABCDEF; - state[8] = 0x01234567; - state[9] = 0x3C2D1E0F; - } - - @override - void processBlock() { - int? a, aa; - int? b, bb; - int? c, cc; - int? d, dd; - int? e, ee; - int t; - - a = state[0]; - b = state[1]; - c = state[2]; - d = state[3]; - e = state[4]; - aa = state[5]; - bb = state[6]; - cc = state[7]; - dd = state[8]; - ee = state[9]; - - // - // Rounds 1 - 16 - // - // left - a = sum32(crotl32(a + _f1(b, c, d) + buffer[0], 11), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f1(a, b, c) + buffer[1], 14), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f1(e, a, b) + buffer[2], 15), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f1(d, e, a) + buffer[3], 12), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f1(c, d, e) + buffer[4], 5), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f1(b, c, d) + buffer[5], 8), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f1(a, b, c) + buffer[6], 7), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f1(e, a, b) + buffer[7], 9), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f1(d, e, a) + buffer[8], 11), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f1(c, d, e) + buffer[9], 13), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f1(b, c, d) + buffer[10], 14), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f1(a, b, c) + buffer[11], 15), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f1(e, a, b) + buffer[12], 6), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f1(d, e, a) + buffer[13], 7), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f1(c, d, e) + buffer[14], 9), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f1(b, c, d) + buffer[15], 8), e); - c = rotl32(c, 10); - - // right - aa = sum32(crotl32(aa + _f5(bb, cc, dd) + buffer[5] + 0x50a28be6, 8), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f5(aa, bb, cc) + buffer[14] + 0x50a28be6, 9), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f5(ee, aa, bb) + buffer[7] + 0x50a28be6, 9), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f5(dd, ee, aa) + buffer[0] + 0x50a28be6, 11), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f5(cc, dd, ee) + buffer[9] + 0x50a28be6, 13), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f5(bb, cc, dd) + buffer[2] + 0x50a28be6, 15), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f5(aa, bb, cc) + buffer[11] + 0x50a28be6, 15), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f5(ee, aa, bb) + buffer[4] + 0x50a28be6, 5), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f5(dd, ee, aa) + buffer[13] + 0x50a28be6, 7), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f5(cc, dd, ee) + buffer[6] + 0x50a28be6, 7), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f5(bb, cc, dd) + buffer[15] + 0x50a28be6, 8), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f5(aa, bb, cc) + buffer[8] + 0x50a28be6, 11), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f5(ee, aa, bb) + buffer[1] + 0x50a28be6, 14), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f5(dd, ee, aa) + buffer[10] + 0x50a28be6, 14), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f5(cc, dd, ee) + buffer[3] + 0x50a28be6, 12), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f5(bb, cc, dd) + buffer[12] + 0x50a28be6, 6), ee); - cc = rotl32(cc, 10); - - t = a; - a = aa; - aa = t; - - // - // Rounds 16-31 - // - // left - e = sum32(crotl32(e + _f2(a, b, c) + buffer[7] + 0x5a827999, 7), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f2(e, a, b) + buffer[4] + 0x5a827999, 6), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f2(d, e, a) + buffer[13] + 0x5a827999, 8), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f2(c, d, e) + buffer[1] + 0x5a827999, 13), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f2(b, c, d) + buffer[10] + 0x5a827999, 11), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f2(a, b, c) + buffer[6] + 0x5a827999, 9), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f2(e, a, b) + buffer[15] + 0x5a827999, 7), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f2(d, e, a) + buffer[3] + 0x5a827999, 15), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f2(c, d, e) + buffer[12] + 0x5a827999, 7), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f2(b, c, d) + buffer[0] + 0x5a827999, 12), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f2(a, b, c) + buffer[9] + 0x5a827999, 15), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f2(e, a, b) + buffer[5] + 0x5a827999, 9), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f2(d, e, a) + buffer[2] + 0x5a827999, 11), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f2(c, d, e) + buffer[14] + 0x5a827999, 7), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f2(b, c, d) + buffer[11] + 0x5a827999, 13), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f2(a, b, c) + buffer[8] + 0x5a827999, 12), d); - b = rotl32(b, 10); - - // right - ee = sum32(crotl32(ee + _f4(aa, bb, cc) + buffer[6] + 0x5c4dd124, 9), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f4(ee, aa, bb) + buffer[11] + 0x5c4dd124, 13), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f4(dd, ee, aa) + buffer[3] + 0x5c4dd124, 15), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f4(cc, dd, ee) + buffer[7] + 0x5c4dd124, 7), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f4(bb, cc, dd) + buffer[0] + 0x5c4dd124, 12), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f4(aa, bb, cc) + buffer[13] + 0x5c4dd124, 8), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f4(ee, aa, bb) + buffer[5] + 0x5c4dd124, 9), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f4(dd, ee, aa) + buffer[10] + 0x5c4dd124, 11), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f4(cc, dd, ee) + buffer[14] + 0x5c4dd124, 7), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f4(bb, cc, dd) + buffer[15] + 0x5c4dd124, 7), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f4(aa, bb, cc) + buffer[8] + 0x5c4dd124, 12), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f4(ee, aa, bb) + buffer[12] + 0x5c4dd124, 7), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f4(dd, ee, aa) + buffer[4] + 0x5c4dd124, 6), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f4(cc, dd, ee) + buffer[9] + 0x5c4dd124, 15), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f4(bb, cc, dd) + buffer[1] + 0x5c4dd124, 13), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f4(aa, bb, cc) + buffer[2] + 0x5c4dd124, 11), dd); - bb = rotl32(bb, 10); - - t = b; - b = bb; - bb = t; - - // - // Rounds 32-47 - // - // left - d = sum32(crotl32(d + _f3(e, a, b) + buffer[3] + 0x6ed9eba1, 11), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f3(d, e, a) + buffer[10] + 0x6ed9eba1, 13), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f3(c, d, e) + buffer[14] + 0x6ed9eba1, 6), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f3(b, c, d) + buffer[4] + 0x6ed9eba1, 7), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f3(a, b, c) + buffer[9] + 0x6ed9eba1, 14), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f3(e, a, b) + buffer[15] + 0x6ed9eba1, 9), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f3(d, e, a) + buffer[8] + 0x6ed9eba1, 13), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f3(c, d, e) + buffer[1] + 0x6ed9eba1, 15), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f3(b, c, d) + buffer[2] + 0x6ed9eba1, 14), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f3(a, b, c) + buffer[7] + 0x6ed9eba1, 8), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f3(e, a, b) + buffer[0] + 0x6ed9eba1, 13), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f3(d, e, a) + buffer[6] + 0x6ed9eba1, 6), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f3(c, d, e) + buffer[13] + 0x6ed9eba1, 5), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f3(b, c, d) + buffer[11] + 0x6ed9eba1, 12), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f3(a, b, c) + buffer[5] + 0x6ed9eba1, 7), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f3(e, a, b) + buffer[12] + 0x6ed9eba1, 5), c); - a = rotl32(a, 10); - - // right - dd = sum32(crotl32(dd + _f3(ee, aa, bb) + buffer[15] + 0x6d703ef3, 9), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f3(dd, ee, aa) + buffer[5] + 0x6d703ef3, 7), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f3(cc, dd, ee) + buffer[1] + 0x6d703ef3, 15), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f3(bb, cc, dd) + buffer[3] + 0x6d703ef3, 11), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f3(aa, bb, cc) + buffer[7] + 0x6d703ef3, 8), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f3(ee, aa, bb) + buffer[14] + 0x6d703ef3, 6), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f3(dd, ee, aa) + buffer[6] + 0x6d703ef3, 6), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f3(cc, dd, ee) + buffer[9] + 0x6d703ef3, 14), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f3(bb, cc, dd) + buffer[11] + 0x6d703ef3, 12), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f3(aa, bb, cc) + buffer[8] + 0x6d703ef3, 13), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f3(ee, aa, bb) + buffer[12] + 0x6d703ef3, 5), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f3(dd, ee, aa) + buffer[2] + 0x6d703ef3, 14), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f3(cc, dd, ee) + buffer[10] + 0x6d703ef3, 13), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f3(bb, cc, dd) + buffer[0] + 0x6d703ef3, 13), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f3(aa, bb, cc) + buffer[4] + 0x6d703ef3, 7), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f3(ee, aa, bb) + buffer[13] + 0x6d703ef3, 5), cc); - aa = rotl32(aa, 10); - - t = c; - c = cc; - cc = t; - - // - // Rounds 48-63 - // - // left - c = sum32(crotl32(c + _f4(d, e, a) + buffer[1] + 0x8f1bbcdc, 11), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f4(c, d, e) + buffer[9] + 0x8f1bbcdc, 12), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f4(b, c, d) + buffer[11] + 0x8f1bbcdc, 14), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f4(a, b, c) + buffer[10] + 0x8f1bbcdc, 15), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f4(e, a, b) + buffer[0] + 0x8f1bbcdc, 14), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f4(d, e, a) + buffer[8] + 0x8f1bbcdc, 15), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f4(c, d, e) + buffer[12] + 0x8f1bbcdc, 9), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f4(b, c, d) + buffer[4] + 0x8f1bbcdc, 8), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f4(a, b, c) + buffer[13] + 0x8f1bbcdc, 9), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f4(e, a, b) + buffer[3] + 0x8f1bbcdc, 14), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f4(d, e, a) + buffer[7] + 0x8f1bbcdc, 5), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f4(c, d, e) + buffer[15] + 0x8f1bbcdc, 6), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f4(b, c, d) + buffer[14] + 0x8f1bbcdc, 8), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f4(a, b, c) + buffer[5] + 0x8f1bbcdc, 6), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f4(e, a, b) + buffer[6] + 0x8f1bbcdc, 5), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f4(d, e, a) + buffer[2] + 0x8f1bbcdc, 12), b); - e = rotl32(e, 10); - - // right - cc = sum32(crotl32(cc + _f2(dd, ee, aa) + buffer[8] + 0x7a6d76e9, 15), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f2(cc, dd, ee) + buffer[6] + 0x7a6d76e9, 5), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f2(bb, cc, dd) + buffer[4] + 0x7a6d76e9, 8), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f2(aa, bb, cc) + buffer[1] + 0x7a6d76e9, 11), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f2(ee, aa, bb) + buffer[3] + 0x7a6d76e9, 14), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f2(dd, ee, aa) + buffer[11] + 0x7a6d76e9, 14), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f2(cc, dd, ee) + buffer[15] + 0x7a6d76e9, 6), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f2(bb, cc, dd) + buffer[0] + 0x7a6d76e9, 14), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f2(aa, bb, cc) + buffer[5] + 0x7a6d76e9, 6), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f2(ee, aa, bb) + buffer[12] + 0x7a6d76e9, 9), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f2(dd, ee, aa) + buffer[2] + 0x7a6d76e9, 12), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f2(cc, dd, ee) + buffer[13] + 0x7a6d76e9, 9), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f2(bb, cc, dd) + buffer[9] + 0x7a6d76e9, 12), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f2(aa, bb, cc) + buffer[7] + 0x7a6d76e9, 5), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f2(ee, aa, bb) + buffer[10] + 0x7a6d76e9, 15), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f2(dd, ee, aa) + buffer[14] + 0x7a6d76e9, 8), bb); - ee = rotl32(ee, 10); - - t = d; - d = dd; - dd = t; - - // - // Rounds 64-79 - // - // left - b = sum32(crotl32(b + _f5(c, d, e) + buffer[4] + 0xa953fd4e, 9), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f5(b, c, d) + buffer[0] + 0xa953fd4e, 15), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f5(a, b, c) + buffer[5] + 0xa953fd4e, 5), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f5(e, a, b) + buffer[9] + 0xa953fd4e, 11), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f5(d, e, a) + buffer[7] + 0xa953fd4e, 6), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f5(c, d, e) + buffer[12] + 0xa953fd4e, 8), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f5(b, c, d) + buffer[2] + 0xa953fd4e, 13), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f5(a, b, c) + buffer[10] + 0xa953fd4e, 12), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f5(e, a, b) + buffer[14] + 0xa953fd4e, 5), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f5(d, e, a) + buffer[1] + 0xa953fd4e, 12), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f5(c, d, e) + buffer[3] + 0xa953fd4e, 13), a); - d = rotl32(d, 10); - a = sum32(crotl32(a + _f5(b, c, d) + buffer[8] + 0xa953fd4e, 14), e); - c = rotl32(c, 10); - e = sum32(crotl32(e + _f5(a, b, c) + buffer[11] + 0xa953fd4e, 11), d); - b = rotl32(b, 10); - d = sum32(crotl32(d + _f5(e, a, b) + buffer[6] + 0xa953fd4e, 8), c); - a = rotl32(a, 10); - c = sum32(crotl32(c + _f5(d, e, a) + buffer[15] + 0xa953fd4e, 5), b); - e = rotl32(e, 10); - b = sum32(crotl32(b + _f5(c, d, e) + buffer[13] + 0xa953fd4e, 6), a); - d = rotl32(d, 10); - - // right - bb = sum32(crotl32(bb + _f1(cc, dd, ee) + buffer[12], 8), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f1(bb, cc, dd) + buffer[15], 5), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f1(aa, bb, cc) + buffer[10], 12), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f1(ee, aa, bb) + buffer[4], 9), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f1(dd, ee, aa) + buffer[1], 12), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f1(cc, dd, ee) + buffer[5], 5), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f1(bb, cc, dd) + buffer[8], 14), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f1(aa, bb, cc) + buffer[7], 6), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f1(ee, aa, bb) + buffer[6], 8), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f1(dd, ee, aa) + buffer[2], 13), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f1(cc, dd, ee) + buffer[13], 6), aa); - dd = rotl32(dd, 10); - aa = sum32(crotl32(aa + _f1(bb, cc, dd) + buffer[14], 5), ee); - cc = rotl32(cc, 10); - ee = sum32(crotl32(ee + _f1(aa, bb, cc) + buffer[0], 15), dd); - bb = rotl32(bb, 10); - dd = sum32(crotl32(dd + _f1(ee, aa, bb) + buffer[3], 13), cc); - aa = rotl32(aa, 10); - cc = sum32(crotl32(cc + _f1(dd, ee, aa) + buffer[9], 11), bb); - ee = rotl32(ee, 10); - bb = sum32(crotl32(bb + _f1(cc, dd, ee) + buffer[11], 11), aa); - dd = rotl32(dd, 10); - - // do (e, ee) swap as part of assignment. - state[0] = sum32(state[0], a); - state[1] = sum32(state[1], b); - state[2] = sum32(state[2], c); - state[3] = sum32(state[3], d); - state[4] = sum32(state[4], ee); - state[5] = sum32(state[5], aa); - state[6] = sum32(state[6], bb); - state[7] = sum32(state[7], cc); - state[8] = sum32(state[8], dd); - state[9] = sum32(state[9], e); - } - - int _f1(int x, int y, int z) => x ^ y ^ z; - - int _f2(int x, int y, int z) => (x & y) | (~x & z); - - int _f3(int x, int y, int z) => (x | ~y) ^ z; - - int _f4(int x, int y, int z) => (x & z) | (y & ~z); - - int _f5(int x, int y, int z) => x ^ (y | ~z); - - @override - int get byteLength => 64; -} diff --git a/pointycastle/lib/digests/sha1.dart b/pointycastle/lib/digests/sha1.dart deleted file mode 100644 index 7ad74ea..0000000 --- a/pointycastle/lib/digests/sha1.dart +++ /dev/null @@ -1,145 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.sha1; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/md4_family_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of SHA-1 digest -class SHA1Digest extends MD4FamilyDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'SHA-1', () => SHA1Digest()); - - static const _DIGEST_LENGTH = 20; - - SHA1Digest() : super(Endian.big, 5, 80); - - @override - final algorithmName = 'SHA-1'; - @override - final digestSize = _DIGEST_LENGTH; - - @override - void resetState() { - state[0] = 0x67452301; - state[1] = 0xefcdab89; - state[2] = 0x98badcfe; - state[3] = 0x10325476; - state[4] = 0xc3d2e1f0; - } - - @override - void processBlock() { - // expand 16 word block into 80 word block. - for (var i = 16; i < 80; i++) { - var t = buffer[i - 3] ^ buffer[i - 8] ^ buffer[i - 14] ^ buffer[i - 16]; - buffer[i] = rotl32(t, 1); - } - - // set up working variables. - var A = state[0]; - var B = state[1]; - var C = state[2]; - var D = state[3]; - var E = state[4]; - - var idx = 0; - - // round 1 - for (var j = 0; j < 4; j++) { - E = clip32(E + rotl32(A, 5) + _f(B, C, D) + buffer[idx++] + _Y1); - B = rotl32(B, 30); - - D = clip32(D + rotl32(E, 5) + _f(A, B, C) + buffer[idx++] + _Y1); - A = rotl32(A, 30); - - C = clip32(C + rotl32(D, 5) + _f(E, A, B) + buffer[idx++] + _Y1); - E = rotl32(E, 30); - - B = clip32(B + rotl32(C, 5) + _f(D, E, A) + buffer[idx++] + _Y1); - D = rotl32(D, 30); - - A = clip32(A + rotl32(B, 5) + _f(C, D, E) + buffer[idx++] + _Y1); - C = rotl32(C, 30); - } - - // round 2 - for (var j = 0; j < 4; j++) { - E = clip32(E + rotl32(A, 5) + _h(B, C, D) + buffer[idx++] + _Y2); - B = rotl32(B, 30); - - D = clip32(D + rotl32(E, 5) + _h(A, B, C) + buffer[idx++] + _Y2); - A = rotl32(A, 30); - - C = clip32(C + rotl32(D, 5) + _h(E, A, B) + buffer[idx++] + _Y2); - E = rotl32(E, 30); - - B = clip32(B + rotl32(C, 5) + _h(D, E, A) + buffer[idx++] + _Y2); - D = rotl32(D, 30); - - A = clip32(A + rotl32(B, 5) + _h(C, D, E) + buffer[idx++] + _Y2); - C = rotl32(C, 30); - } - - // round 3 - for (var j = 0; j < 4; j++) { - E = clip32(E + rotl32(A, 5) + _g(B, C, D) + buffer[idx++] + _Y3); - B = rotl32(B, 30); - - D = clip32(D + rotl32(E, 5) + _g(A, B, C) + buffer[idx++] + _Y3); - A = rotl32(A, 30); - - C = clip32(C + rotl32(D, 5) + _g(E, A, B) + buffer[idx++] + _Y3); - E = rotl32(E, 30); - - B = clip32(B + rotl32(C, 5) + _g(D, E, A) + buffer[idx++] + _Y3); - D = rotl32(D, 30); - - A = clip32(A + rotl32(B, 5) + _g(C, D, E) + buffer[idx++] + _Y3); - C = rotl32(C, 30); - } - - // round 4 - for (var j = 0; j < 4; j++) { - E = clip32(E + rotl32(A, 5) + _h(B, C, D) + buffer[idx++] + _Y4); - B = rotl32(B, 30); - - D = clip32(D + rotl32(E, 5) + _h(A, B, C) + buffer[idx++] + _Y4); - A = rotl32(A, 30); - - C = clip32(C + rotl32(D, 5) + _h(E, A, B) + buffer[idx++] + _Y4); - E = rotl32(E, 30); - - B = clip32(B + rotl32(C, 5) + _h(D, E, A) + buffer[idx++] + _Y4); - D = rotl32(D, 30); - - A = clip32(A + rotl32(B, 5) + _h(C, D, E) + buffer[idx++] + _Y4); - C = rotl32(C, 30); - } - - state[0] = clip32(state[0] + A); - state[1] = clip32(state[1] + B); - state[2] = clip32(state[2] + C); - state[3] = clip32(state[3] + D); - state[4] = clip32(state[4] + E); - } - - // Additive constants - static const _Y1 = 0x5a827999; - static const _Y2 = 0x6ed9eba1; - static const _Y3 = 0x8f1bbcdc; - static const _Y4 = 0xca62c1d6; - - int _f(int u, int v, int w) => (u & v) | ((~u) & w); - - int _h(int u, int v, int w) => u ^ v ^ w; - - int _g(int u, int v, int w) => (u & v) | (u & w) | (v & w); - - @override - int get byteLength => 64; -} diff --git a/pointycastle/lib/digests/sha224.dart b/pointycastle/lib/digests/sha224.dart deleted file mode 100644 index 9b7a4da..0000000 --- a/pointycastle/lib/digests/sha224.dart +++ /dev/null @@ -1,203 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.sha224; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/md4_family_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of SHA-224 digest. -class SHA224Digest extends MD4FamilyDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'SHA-224', () => SHA224Digest()); - - static const _DIGEST_LENGTH = 28; - - SHA224Digest() : super(Endian.big, 8, 64, 7); - - @override - final algorithmName = 'SHA-224'; - @override - final digestSize = _DIGEST_LENGTH; - - @override - void resetState() { - state[0] = 0xc1059ed8; - state[1] = 0x367cd507; - state[2] = 0x3070dd17; - state[3] = 0xf70e5939; - state[4] = 0xffc00b31; - state[5] = 0x68581511; - state[6] = 0x64f98fa7; - state[7] = 0xbefa4fa4; - } - - @override - void processBlock() { - // expand 16 word block into 64 word blocks. - for (var t = 16; t < 64; t++) { - buffer[t] = clip32(_theta1(buffer[t - 2]) + - buffer[t - 7] + - _theta0(buffer[t - 15]) + - buffer[t - 16]); - } - - // set up working variables. - var a = state[0]; - var b = state[1]; - var c = state[2]; - var d = state[3]; - var e = state[4]; - var f = state[5]; - var g = state[6]; - var h = state[7]; - - var t = 0; - - for (var i = 0; i < 8; i++) { - // t = 8 * i - h = clip32(h + _sum1(e) + _ch(e, f, g) + _k[t] + buffer[t]); - d = clip32(d + h); - h = clip32(h + _sum0(a) + _maj(a, b, c)); - ++t; - - // t = 8 * i + 1 - g = clip32(g + _sum1(d) + _ch(d, e, f) + _k[t] + buffer[t]); - c = clip32(c + g); - g = clip32(g + _sum0(h) + _maj(h, a, b)); - ++t; - - // t = 8 * i + 2 - f = clip32(f + _sum1(c) + _ch(c, d, e) + _k[t] + buffer[t]); - b = clip32(b + f); - f = clip32(f + _sum0(g) + _maj(g, h, a)); - ++t; - - // t = 8 * i + 3 - e = clip32(e + _sum1(b) + _ch(b, c, d) + _k[t] + buffer[t]); - a = clip32(a + e); - e = clip32(e + _sum0(f) + _maj(f, g, h)); - ++t; - - // t = 8 * i + 4 - d = clip32(d + _sum1(a) + _ch(a, b, c) + _k[t] + buffer[t]); - h = clip32(h + d); - d = clip32(d + _sum0(e) + _maj(e, f, g)); - ++t; - - // t = 8 * i + 5 - c = clip32(c + _sum1(h) + _ch(h, a, b) + _k[t] + buffer[t]); - g = clip32(g + c); - c = clip32(c + _sum0(d) + _maj(d, e, f)); - ++t; - - // t = 8 * i + 6 - b = clip32(b + _sum1(g) + _ch(g, h, a) + _k[t] + buffer[t]); - f = clip32(f + b); - b = clip32(b + _sum0(c) + _maj(c, d, e)); - ++t; - - // t = 8 * i + 7 - a = clip32(a + _sum1(f) + _ch(f, g, h) + _k[t] + buffer[t]); - e = clip32(e + a); - a = clip32(a + _sum0(b) + _maj(b, c, d)); - ++t; - } - - state[0] = clip32(state[0] + a); - state[1] = clip32(state[1] + b); - state[2] = clip32(state[2] + c); - state[3] = clip32(state[3] + d); - state[4] = clip32(state[4] + e); - state[5] = clip32(state[5] + f); - state[6] = clip32(state[6] + g); - state[7] = clip32(state[7] + h); - } - - int _ch(int x, int y, int z) => (x & y) ^ ((~x) & z); - - int _maj(int x, int y, int z) => (x & y) ^ (x & z) ^ (y & z); - - int _sum0(int x) => rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22); - - int _sum1(int x) => rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25); - - int _theta0(int x) => rotr32(x, 7) ^ rotr32(x, 18) ^ shiftr32(x, 3); - - int _theta1(int x) => rotr32(x, 17) ^ rotr32(x, 19) ^ shiftr32(x, 10); - - /// SHA-224 Constants (represent the first 32 bits of the fractional parts of the cube roots of the - /// first sixty-four prime numbers) - static final _k = [ - 0x428a2f98, - 0x71374491, - 0xb5c0fbcf, - 0xe9b5dba5, - 0x3956c25b, - 0x59f111f1, - 0x923f82a4, - 0xab1c5ed5, - 0xd807aa98, - 0x12835b01, - 0x243185be, - 0x550c7dc3, - 0x72be5d74, - 0x80deb1fe, - 0x9bdc06a7, - 0xc19bf174, - 0xe49b69c1, - 0xefbe4786, - 0x0fc19dc6, - 0x240ca1cc, - 0x2de92c6f, - 0x4a7484aa, - 0x5cb0a9dc, - 0x76f988da, - 0x983e5152, - 0xa831c66d, - 0xb00327c8, - 0xbf597fc7, - 0xc6e00bf3, - 0xd5a79147, - 0x06ca6351, - 0x14292967, - 0x27b70a85, - 0x2e1b2138, - 0x4d2c6dfc, - 0x53380d13, - 0x650a7354, - 0x766a0abb, - 0x81c2c92e, - 0x92722c85, - 0xa2bfe8a1, - 0xa81a664b, - 0xc24b8b70, - 0xc76c51a3, - 0xd192e819, - 0xd6990624, - 0xf40e3585, - 0x106aa070, - 0x19a4c116, - 0x1e376c08, - 0x2748774c, - 0x34b0bcb5, - 0x391c0cb3, - 0x4ed8aa4a, - 0x5b9cca4f, - 0x682e6ff3, - 0x748f82ee, - 0x78a5636f, - 0x84c87814, - 0x8cc70208, - 0x90befffa, - 0xa4506ceb, - 0xbef9a3f7, - 0xc67178f2 - ]; - - @override - int get byteLength => 64; -} diff --git a/pointycastle/lib/digests/sha256.dart b/pointycastle/lib/digests/sha256.dart deleted file mode 100644 index c9aa1c3..0000000 --- a/pointycastle/lib/digests/sha256.dart +++ /dev/null @@ -1,203 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.sha256; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/md4_family_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of SHA-256 digest. -class SHA256Digest extends MD4FamilyDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'SHA-256', () => SHA256Digest()); - - static const _DIGEST_LENGTH = 32; - - SHA256Digest() : super(Endian.big, 8, 64); - - @override - final algorithmName = 'SHA-256'; - @override - final digestSize = _DIGEST_LENGTH; - - @override - void resetState() { - state[0] = 0x6a09e667; - state[1] = 0xbb67ae85; - state[2] = 0x3c6ef372; - state[3] = 0xa54ff53a; - state[4] = 0x510e527f; - state[5] = 0x9b05688c; - state[6] = 0x1f83d9ab; - state[7] = 0x5be0cd19; - } - - @override - void processBlock() { - // expand 16 word block into 64 word blocks. - for (var t = 16; t < 64; t++) { - buffer[t] = clip32(_theta1(buffer[t - 2]) + - buffer[t - 7] + - _theta0(buffer[t - 15]) + - buffer[t - 16]); - } - - // set up working variables. - var a = state[0]; - var b = state[1]; - var c = state[2]; - var d = state[3]; - var e = state[4]; - var f = state[5]; - var g = state[6]; - var h = state[7]; - - var t = 0; - - for (var i = 0; i < 8; i++) { - // t = 8 * i - h = clip32(h + _sum1(e) + _ch(e, f, g) + _k[t] + buffer[t]); - d = clip32(d + h); - h = clip32(h + _sum0(a) + _maj(a, b, c)); - ++t; - - // t = 8 * i + 1 - g = clip32(g + _sum1(d) + _ch(d, e, f) + _k[t] + buffer[t]); - c = clip32(c + g); - g = clip32(g + _sum0(h) + _maj(h, a, b)); - ++t; - - // t = 8 * i + 2 - f = clip32(f + _sum1(c) + _ch(c, d, e) + _k[t] + buffer[t]); - b = clip32(b + f); - f = clip32(f + _sum0(g) + _maj(g, h, a)); - ++t; - - // t = 8 * i + 3 - e = clip32(e + _sum1(b) + _ch(b, c, d) + _k[t] + buffer[t]); - a = clip32(a + e); - e = clip32(e + _sum0(f) + _maj(f, g, h)); - ++t; - - // t = 8 * i + 4 - d = clip32(d + _sum1(a) + _ch(a, b, c) + _k[t] + buffer[t]); - h = clip32(h + d); - d = clip32(d + _sum0(e) + _maj(e, f, g)); - ++t; - - // t = 8 * i + 5 - c = clip32(c + _sum1(h) + _ch(h, a, b) + _k[t] + buffer[t]); - g = clip32(g + c); - c = clip32(c + _sum0(d) + _maj(d, e, f)); - ++t; - - // t = 8 * i + 6 - b = clip32(b + _sum1(g) + _ch(g, h, a) + _k[t] + buffer[t]); - f = clip32(f + b); - b = clip32(b + _sum0(c) + _maj(c, d, e)); - ++t; - - // t = 8 * i + 7 - a = clip32(a + _sum1(f) + _ch(f, g, h) + _k[t] + buffer[t]); - e = clip32(e + a); - a = clip32(a + _sum0(b) + _maj(b, c, d)); - ++t; - } - - state[0] = clip32(state[0] + a); - state[1] = clip32(state[1] + b); - state[2] = clip32(state[2] + c); - state[3] = clip32(state[3] + d); - state[4] = clip32(state[4] + e); - state[5] = clip32(state[5] + f); - state[6] = clip32(state[6] + g); - state[7] = clip32(state[7] + h); - } - - int _ch(int x, int y, int z) => (x & y) ^ ((~x) & z); - - int _maj(int x, int y, int z) => (x & y) ^ (x & z) ^ (y & z); - - int _sum0(int x) => rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22); - - int _sum1(int x) => rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25); - - int _theta0(int x) => rotr32(x, 7) ^ rotr32(x, 18) ^ shiftr32(x, 3); - - int _theta1(int x) => rotr32(x, 17) ^ rotr32(x, 19) ^ shiftr32(x, 10); - - /// SHA-256 Constants (represent the first 32 bits of the fractional parts of the cube roots of the - /// first sixty-four prime numbers) - static final _k = [ - 0x428a2f98, - 0x71374491, - 0xb5c0fbcf, - 0xe9b5dba5, - 0x3956c25b, - 0x59f111f1, - 0x923f82a4, - 0xab1c5ed5, - 0xd807aa98, - 0x12835b01, - 0x243185be, - 0x550c7dc3, - 0x72be5d74, - 0x80deb1fe, - 0x9bdc06a7, - 0xc19bf174, - 0xe49b69c1, - 0xefbe4786, - 0x0fc19dc6, - 0x240ca1cc, - 0x2de92c6f, - 0x4a7484aa, - 0x5cb0a9dc, - 0x76f988da, - 0x983e5152, - 0xa831c66d, - 0xb00327c8, - 0xbf597fc7, - 0xc6e00bf3, - 0xd5a79147, - 0x06ca6351, - 0x14292967, - 0x27b70a85, - 0x2e1b2138, - 0x4d2c6dfc, - 0x53380d13, - 0x650a7354, - 0x766a0abb, - 0x81c2c92e, - 0x92722c85, - 0xa2bfe8a1, - 0xa81a664b, - 0xc24b8b70, - 0xc76c51a3, - 0xd192e819, - 0xd6990624, - 0xf40e3585, - 0x106aa070, - 0x19a4c116, - 0x1e376c08, - 0x2748774c, - 0x34b0bcb5, - 0x391c0cb3, - 0x4ed8aa4a, - 0x5b9cca4f, - 0x682e6ff3, - 0x748f82ee, - 0x78a5636f, - 0x84c87814, - 0x8cc70208, - 0x90befffa, - 0xa4506ceb, - 0xbef9a3f7, - 0xc67178f2 - ]; - - @override - int get byteLength => 64; -} diff --git a/pointycastle/lib/digests/sha3.dart b/pointycastle/lib/digests/sha3.dart deleted file mode 100644 index 2a8b06d..0000000 --- a/pointycastle/lib/digests/sha3.dart +++ /dev/null @@ -1,50 +0,0 @@ -// This file has been migrated. - -library impl.digest.sha3; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/keccak_engine.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// Implementation of SHA3 digest. -/// https://csrc.nist.gov/publications/detail/fips/202/final -class SHA3Digest extends KeccakEngine { - static final RegExp _sha3REGEX = RegExp(r'^SHA3-([0-9]+)$'); - - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig( - Digest, - _sha3REGEX, - (_, final Match match) => () { - var bitLength = int.parse(match.group(1)!); - return SHA3Digest(bitLength); - }); - - SHA3Digest([int? bitLength = 288]) { - switch (bitLength) { - case 224: - case 256: - case 384: - case 512: - init(bitLength!); - break; - default: - throw StateError( - 'invalid bitLength ($bitLength) for SHA-3 must only be 224,256,384,512'); - } - } - - @override - String get algorithmName => 'SHA3-$fixedOutputLength'; - - @override - int doFinal(Uint8List out, int outOff) { - // FIPS 202 SHA3 https://github.com/PointyCastle/pointycastle/issues/128 - absorbBits(0x02, 2); - squeeze(out, outOff, fixedOutputLength); - reset(); - return digestSize; - } -} diff --git a/pointycastle/lib/digests/sha384.dart b/pointycastle/lib/digests/sha384.dart deleted file mode 100644 index b5cfaab..0000000 --- a/pointycastle/lib/digests/sha384.dart +++ /dev/null @@ -1,57 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.sha384; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/long_sha2_family_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// Implementation of SHA-384 digest. -class SHA384Digest extends LongSHA2FamilyDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'SHA-384', () => SHA384Digest()); - - static const _DIGEST_LENGTH = 48; - - SHA384Digest() { - reset(); - } - - @override - final algorithmName = 'SHA-384'; - @override - final digestSize = _DIGEST_LENGTH; - - @override - void reset() { - super.reset(); - - h1.set(0xcbbb9d5d, 0xc1059ed8); - h2.set(0x629a292a, 0x367cd507); - h3.set(0x9159015a, 0x3070dd17); - h4.set(0x152fecd8, 0xf70e5939); - h5.set(0x67332667, 0xffc00b31); - h6.set(0x8eb44a87, 0x68581511); - h7.set(0xdb0c2e0d, 0x64f98fa7); - h8.set(0x47b5481d, 0xbefa4fa4); - } - - @override - int doFinal(Uint8List out, int outOff) { - finish(); - - var view = ByteData.view(out.buffer, out.offsetInBytes, out.length); - h1.pack(view, outOff, Endian.big); - h2.pack(view, outOff + 8, Endian.big); - h3.pack(view, outOff + 16, Endian.big); - h4.pack(view, outOff + 24, Endian.big); - h5.pack(view, outOff + 32, Endian.big); - h6.pack(view, outOff + 40, Endian.big); - - reset(); - - return _DIGEST_LENGTH; - } -} diff --git a/pointycastle/lib/digests/sha512.dart b/pointycastle/lib/digests/sha512.dart deleted file mode 100644 index 61bb16d..0000000 --- a/pointycastle/lib/digests/sha512.dart +++ /dev/null @@ -1,59 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.sha512; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/long_sha2_family_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// Implementation of SHA-512 digest. -class SHA512Digest extends LongSHA2FamilyDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'SHA-512', () => SHA512Digest()); - - static const _DIGEST_LENGTH = 64; - - SHA512Digest() { - reset(); - } - - @override - final algorithmName = 'SHA-512'; - @override - final digestSize = _DIGEST_LENGTH; - - @override - void reset() { - super.reset(); - - h1.set(0x6a09e667, 0xf3bcc908); - h2.set(0xbb67ae85, 0x84caa73b); - h3.set(0x3c6ef372, 0xfe94f82b); - h4.set(0xa54ff53a, 0x5f1d36f1); - h5.set(0x510e527f, 0xade682d1); - h6.set(0x9b05688c, 0x2b3e6c1f); - h7.set(0x1f83d9ab, 0xfb41bd6b); - h8.set(0x5be0cd19, 0x137e2179); - } - - @override - int doFinal(Uint8List out, int outOff) { - finish(); - - var view = ByteData.view(out.buffer, out.offsetInBytes, out.length); - h1.pack(view, outOff, Endian.big); - h2.pack(view, outOff + 8, Endian.big); - h3.pack(view, outOff + 16, Endian.big); - h4.pack(view, outOff + 24, Endian.big); - h5.pack(view, outOff + 32, Endian.big); - h6.pack(view, outOff + 40, Endian.big); - h7.pack(view, outOff + 48, Endian.big); - h8.pack(view, outOff + 56, Endian.big); - - reset(); - - return _DIGEST_LENGTH; - } -} diff --git a/pointycastle/lib/digests/sha512t.dart b/pointycastle/lib/digests/sha512t.dart deleted file mode 100644 index e4dc0e4..0000000 --- a/pointycastle/lib/digests/sha512t.dart +++ /dev/null @@ -1,157 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.sha512t; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/long_sha2_family_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of SHA-512/t digest (see FIPS 180-4). -class SHA512tDigest extends LongSHA2FamilyDigest implements Digest { - static final RegExp _nameRegex = RegExp(r'^SHA-512\/([0-9]+)$'); - - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig( - Digest, - _nameRegex, - (_, final Match match) => () { - var bitLength = int.parse(match.group(1)!); - if ((bitLength % 8) != 0) { - throw RegistryFactoryException( - 'Digest length for SHA-512/t is not a multiple of 8: $bitLength'); - } - return SHA512tDigest(bitLength ~/ 8); - }); - - static final Register64 _hMask = Register64(0xa5a5a5a5, 0xa5a5a5a5); - - @override - final int digestSize; - - final _h1t = Register64(); - final _h2t = Register64(); - final _h3t = Register64(); - final _h4t = Register64(); - final _h5t = Register64(); - final _h6t = Register64(); - final _h7t = Register64(); - final _h8t = Register64(); - - SHA512tDigest(this.digestSize) { - if (digestSize >= 64) { - throw ArgumentError('Digest size cannot be >= 64 bytes (512 bits)'); - } - if (digestSize == 48) { - throw ArgumentError( - 'Digest size cannot be 48 bytes (384 bits): use SHA-384 instead'); - } - - _generateIVs(digestSize * 8); - - reset(); - } - - @override - String get algorithmName => 'SHA-512/${digestSize * 8}'; - - @override - void reset() { - super.reset(); - - h1.set(_h1t); - h2.set(_h2t); - h3.set(_h3t); - h4.set(_h4t); - h5.set(_h5t); - h6.set(_h6t); - h7.set(_h7t); - h8.set(_h8t); - } - - @override - int doFinal(Uint8List out, int outOff) { - finish(); - - var tmp = Uint8List(64); - - var view = ByteData.view(tmp.buffer, tmp.offsetInBytes, tmp.length); - h1.pack(view, 0, Endian.big); - h2.pack(view, 8, Endian.big); - h3.pack(view, 16, Endian.big); - h4.pack(view, 24, Endian.big); - h5.pack(view, 32, Endian.big); - h6.pack(view, 40, Endian.big); - h7.pack(view, 48, Endian.big); - h8.pack(view, 56, Endian.big); - - out.setRange(outOff, outOff + digestSize, tmp); - - reset(); - - return digestSize; - } - - void _generateIVs(int bitLength) { - h1 - ..set(0x6a09e667, 0xf3bcc908) - ..xor(_hMask); - h2 - ..set(0xbb67ae85, 0x84caa73b) - ..xor(_hMask); - h3 - ..set(0x3c6ef372, 0xfe94f82b) - ..xor(_hMask); - h4 - ..set(0xa54ff53a, 0x5f1d36f1) - ..xor(_hMask); - h5 - ..set(0x510e527f, 0xade682d1) - ..xor(_hMask); - h6 - ..set(0x9b05688c, 0x2b3e6c1f) - ..xor(_hMask); - h7 - ..set(0x1f83d9ab, 0xfb41bd6b) - ..xor(_hMask); - h8 - ..set(0x5be0cd19, 0x137e2179) - ..xor(_hMask); - - updateByte(0x53); - updateByte(0x48); - updateByte(0x41); - updateByte(0x2D); - updateByte(0x35); - updateByte(0x31); - updateByte(0x32); - updateByte(0x2F); - - if (bitLength > 100) { - updateByte(bitLength ~/ 100 + 0x30); - bitLength = bitLength % 100; - updateByte(bitLength ~/ 10 + 0x30); - bitLength = bitLength % 10; - updateByte(bitLength + 0x30); - } else if (bitLength > 10) { - updateByte(bitLength ~/ 10 + 0x30); - bitLength = bitLength % 10; - updateByte(bitLength + 0x30); - } else { - updateByte(bitLength + 0x30); - } - - finish(); - - _h1t.set(h1); - _h2t.set(h2); - _h3t.set(h3); - _h4t.set(h4); - _h5t.set(h5); - _h6t.set(h6); - _h7t.set(h7); - _h8t.set(h8); - } -} diff --git a/pointycastle/lib/digests/shake.dart b/pointycastle/lib/digests/shake.dart deleted file mode 100644 index 53f9290..0000000 --- a/pointycastle/lib/digests/shake.dart +++ /dev/null @@ -1,92 +0,0 @@ -// This file has been migrated. - -library impl.digest.shake; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/keccak_engine.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// -/// implementation of SHAKE based on following KeccakNISTInterface.c from http://keccak.noekeon.org/ -/// -/// Following the naming conventions used in the C source code to enable easy review of the implementation. -/// -class SHAKEDigest extends KeccakEngine implements Xof { - static final RegExp _shakeREGEX = RegExp(r'^SHAKE-([0-9]+)$'); - - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig( - Digest, - _shakeREGEX, - (_, final Match match) => () { - var bitLength = int.parse(match.group(1)!); - return SHAKEDigest(bitLength); - }); - - SHAKEDigest([int bitLength = 256]) { - switch (bitLength) { - case 128: - case 256: - init(bitLength); - break; - default: - throw StateError( - 'invalid bitLength ($bitLength) for SHAKE must only be 128 or 256'); - } - } - - @override - String get algorithmName => 'SHAKE-$fixedOutputLength'; - - @override - int doFinal(Uint8List out, int outOff) { - return doFinalRange(out, digestSize, digestSize); - } - - @override - int doFinalRange(Uint8List out, int outOff, int outLen) { - var length = doOutput(out, outOff, outLen); - reset(); - return length; - } - - int doFinalPartial( - Uint8List out, int outOff, int outLen, int partialByte, int partialBits) { - if (partialBits < 0 || partialBits > 7) { - throw ArgumentError('partialBits must be in the range [0,7]'); - } - - var finalInput = - (partialByte & ((1 << partialBits) - 1)) | (0x0F << partialBits); - var finalBits = partialBits + 4; - - if (finalBits >= 8) { - absorb(finalInput); - finalBits -= 8; - finalInput >>= 8; - } - - if (finalBits > 0) { - absorbBits(finalInput, finalBits); - } - - squeeze(out, outOff, outLen * 8); - - reset(); - - return outLen; - } - - @override - int doOutput(Uint8List out, int outOff, int outLen) { - if (!squeezing) { - absorbBits(0x0F, 4); - } - - squeeze(out, outOff, outLen * 8); - - return outLen; - } -} diff --git a/pointycastle/lib/digests/sm3.dart b/pointycastle/lib/digests/sm3.dart deleted file mode 100644 index 6ea8639..0000000 --- a/pointycastle/lib/digests/sm3.dart +++ /dev/null @@ -1,130 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.sm3; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/md4_family_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of Chinese SM3 Hash Function (GM/T 0004-2012) as -/// described at [Reference 1][REF1] and at [Reference 2][REF2]. -/// -/// 这是一个依据 [参考文献1][REF1] 和 [参考文献2][REF2] 的 SM3 哈希函数的实现. -/// -/// [REF1]: http://www.sca.gov.cn/sca/xwdt/2010-12/17/content_1002389.shtml -/// [REF2]: https://tools.ietf.org/html/draft-shen-sm3-hash -class SM3Digest extends MD4FamilyDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'SM3', () => SM3Digest()); - - static const _DIGEST_LENGTH = 32; - - final List _W; - - SM3Digest() - : _W = List.filled(68, 0, growable: false), - super(Endian.big, 8, 16); - - @override - final algorithmName = 'SM3'; - @override - final digestSize = _DIGEST_LENGTH; - - @override - void resetState() { - state[0] = 0x7380166f; - state[1] = 0x4914b2b9; - state[2] = 0x172442d7; - state[3] = 0xda8a0600; - state[4] = 0xa96f30bc; - state[5] = 0x163138aa; - state[6] = 0xe38dee4d; - state[7] = 0xb0fb0e4e; - } - - @override - void processBlock() { - int i; - // [REF1] 5.3.2 消息扩展 - // [REF2] 3.3.2 Message Extension - _W.setAll(0, buffer); - for (i = 16; i < 68; ++i) { - _W[i] = _P1(_W[i - 16] ^ _W[i - 9] ^ rotl32(_W[i - 3], 15)) ^ - rotl32(_W[i - 13], 7) ^ - _W[i - 6]; - } - // [REF1] 5.3.3 压缩函数 - // [REF2] 3.3.3 Compression Function - var A = state[0]; - var B = state[1]; - var C = state[2]; - var D = state[3]; - var E = state[4]; - var F = state[5]; - var G = state[6]; - var H = state[7]; - int SS1, SS2, TT1, TT2, Tj; - for (i = 0; i < 16; ++i) { - Tj = 0x79cc4519; - SS1 = rotl32(clip32(rotl32(A, 12) + E + rotl32(Tj, i)), 7); - SS2 = SS1 ^ rotl32(A, 12); - TT1 = clip32(_FF1(A, B, C) + D + SS2 + (_W[i] ^ _W[i + 4])); - TT2 = clip32(_GG1(E, F, G) + H + SS1 + _W[i]); - D = C; - C = rotl32(B, 9); - B = A; - A = TT1; - H = G; - G = rotl32(F, 19); - F = E; - E = _P0(TT2); - } - for (i = 16; i < 64; ++i) { - Tj = 0x7a879d8a; - SS1 = rotl32(clip32(rotl32(A, 12) + E + rotl32(Tj, i)), 7); - SS2 = SS1 ^ rotl32(A, 12); - TT1 = clip32(_FF2(A, B, C) + D + SS2 + (_W[i] ^ _W[i + 4])); - TT2 = clip32(_GG2(E, F, G) + H + SS1 + _W[i]); - D = C; - C = rotl32(B, 9); - B = A; - A = TT1; - H = G; - G = rotl32(F, 19); - F = E; - E = _P0(TT2); - } - state[0] ^= A; - state[1] ^= B; - state[2] ^= C; - state[3] ^= D; - state[4] ^= E; - state[5] ^= F; - state[6] ^= G; - state[7] ^= H; - } - - /// FF1 Function - static int _FF1(int X, int Y, int Z) => X ^ Y ^ Z; - - /// FF2 Function - static int _FF2(int X, int Y, int Z) => (X & Y) | (X & Z) | (Y & Z); - - /// GG1 Function - static final _GG1 = _FF1; - - /// GG2 Function - static int _GG2(int X, int Y, int Z) => (X & Y) | ((~X) & Z); - - /// P0 Function - static int _P0(int X) => X ^ rotl32(X, 9) ^ rotl32(X, 17); - - /// P1 Function - static int _P1(int X) => X ^ rotl32(X, 15) ^ rotl32(X, 23); - - @override - int get byteLength => 64; -} diff --git a/pointycastle/lib/digests/tiger.dart b/pointycastle/lib/digests/tiger.dart deleted file mode 100644 index 8fe9444..0000000 --- a/pointycastle/lib/digests/tiger.dart +++ /dev/null @@ -1,1321 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.tiger; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of Tiger digest. -class TigerDigest extends BaseDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'Tiger', () => TigerDigest()); - - static const _DIGEST_LENGTH = 24; - static final _keyMask0 = Register64(0xA5A5A5A5, 0xA5A5A5A5); - static final _keyMask7 = Register64(0x01234567, 0x89ABCDEF); - - final _a = Register64(); - final _b = Register64(); - final _c = Register64(); - - final _byteCount = Register64(); - - final _wordBuffer = Uint8List(8); - int _wordBufferOffset = 0; - - final _buffer = Register64List(8); - int _bufferOffset = 0; - - TigerDigest() { - reset(); - } - - @override - final algorithmName = 'Tiger'; - @override - final digestSize = _DIGEST_LENGTH; - - @override - void reset() { - _a.set(0x01234567, 0x89ABCDEF); - _b.set(0xFEDCBA98, 0x76543210); - _c.set(0xF096A5B4, 0xC3B2E187); - - _bufferOffset = 0; - _buffer.fillRange(0, _buffer.length, 0); - - _wordBufferOffset = 0; - _wordBuffer.fillRange(0, _wordBuffer.length, 0); - - _byteCount.set(0); - } - - @override - int doFinal(Uint8List out, int outOff) { - _finish(); - - _a.pack(out, outOff, Endian.little); - _b.pack(out, outOff + 8, Endian.little); - _c.pack(out, outOff + 16, Endian.little); - - reset(); - - return _DIGEST_LENGTH; - } - - @override - void updateByte(int inp) { - _wordBuffer[_wordBufferOffset++] = inp; - - if (_wordBufferOffset == _wordBuffer.length) { - _processWord(_wordBuffer, 0); - } - - _byteCount.sum(1); - } - - @override - void update(Uint8List? inp, int inpOff, int? len) { - // fill the current word - while ((_wordBufferOffset != 0) && (len! > 0)) { - updateByte(inp![inpOff]); - - inpOff++; - len--; - } - - // process whole words. - while (len! > 8) { - _processWord(inp, inpOff); - - inpOff += 8; - len -= 8; - _byteCount.sum(8); - } - - // load in the remainder. - while (len! > 0) { - updateByte(inp![inpOff]); - - inpOff++; - len--; - } - } - - void _processWord(Uint8List? b, int off) { - _buffer[_bufferOffset++].unpack(b, off, Endian.little); - - if (_bufferOffset == _buffer.length) { - _processBlock(); - } - _wordBufferOffset = 0; - } - - void _processBlock() { - // save abc - final aa = Register64(_a); - final bb = Register64(_b); - final cc = Register64(_c); - - // rounds and schedule - _roundABC(_buffer[0], 5); - _roundBCA(_buffer[1], 5); - _roundCAB(_buffer[2], 5); - _roundABC(_buffer[3], 5); - _roundBCA(_buffer[4], 5); - _roundCAB(_buffer[5], 5); - _roundABC(_buffer[6], 5); - _roundBCA(_buffer[7], 5); - - _keySchedule(); - - _roundCAB(_buffer[0], 7); - _roundABC(_buffer[1], 7); - _roundBCA(_buffer[2], 7); - _roundCAB(_buffer[3], 7); - _roundABC(_buffer[4], 7); - _roundBCA(_buffer[5], 7); - _roundCAB(_buffer[6], 7); - _roundABC(_buffer[7], 7); - - _keySchedule(); - - _roundBCA(_buffer[0], 9); - _roundCAB(_buffer[1], 9); - _roundABC(_buffer[2], 9); - _roundBCA(_buffer[3], 9); - _roundCAB(_buffer[4], 9); - _roundABC(_buffer[5], 9); - _roundBCA(_buffer[6], 9); - _roundCAB(_buffer[7], 9); - - // feed forward - _a.xor(aa); - _b.sub(bb); - _c.sum(cc); - - // clear the x buffer - _bufferOffset = 0; - _buffer.fillRange(0, _buffer.length, 0); - } - - void _processLength(Register64 bitLength) { - _buffer[7].set(bitLength); - } - - void _finish() { - var bitLength = Register64(_byteCount)..shiftl(3); - - updateByte(0x01); - - while (_wordBufferOffset != 0) { - updateByte(0); - } - - _processLength(bitLength); - - _processBlock(); - } - - void _keySchedule() { - final r = Register64(); - - _buffer[0].sub(r - ..set(_buffer[7]) - ..xor(_keyMask0)); - _buffer[1].xor(_buffer[0]); - _buffer[2].sum(_buffer[1]); - _buffer[3].sub(r - ..set(_buffer[1]) - ..not() - ..shiftl(19) - ..xor(_buffer[2])); - _buffer[4].xor(_buffer[3]); - _buffer[5].sum(_buffer[4]); - _buffer[6].sub(r - ..set(_buffer[4]) - ..not() - ..shiftr(23) - ..xor(_buffer[5])); - _buffer[7].xor(_buffer[6]); - _buffer[0].sum(_buffer[7]); - _buffer[1].sub(r - ..set(_buffer[7]) - ..not() - ..shiftl(19) - ..xor(_buffer[0])); - _buffer[2].xor(_buffer[1]); - _buffer[3].sum(_buffer[2]); - _buffer[4].sub(r - ..set(_buffer[2]) - ..not() - ..shiftr(23) - ..xor(_buffer[3])); - _buffer[5].xor(_buffer[4]); - _buffer[6].sum(_buffer[5]); - _buffer[7].sub(r - ..set(_buffer[6]) - ..xor(_keyMask7)); - } - - void _roundABC(Register64 x, int mul) { - final r = Register64(); - final c = Uint8List(8); - - _c.xor(x); - _c.pack(c, 0, Endian.little); - _a.sub(r - ..set(_t1[c[0]]) - ..xor(_t2[c[2]]) - ..xor(_t3[c[4]]) - ..xor(_t4[c[6]])); - _b.sum(r - ..set(_t4[c[1]]) - ..xor(_t3[c[3]]) - ..xor(_t2[c[5]]) - ..xor(_t1[c[7]])); - _b.mul(mul); - } - - void _roundBCA(Register64 x, int mul) { - final r = Register64(); - final a = Uint8List(8); - - _a.xor(x); - _a.pack(a, 0, Endian.little); - _b.sub(r - ..set(_t1[a[0]]) - ..xor(_t2[a[2]]) - ..xor(_t3[a[4]]) - ..xor(_t4[a[6]])); - _c.sum(r - ..set(_t4[a[1]]) - ..xor(_t3[a[3]]) - ..xor(_t2[a[5]]) - ..xor(_t1[a[7]])); - _c.mul(mul); - } - - void _roundCAB(Register64 x, int mul) { - final r = Register64(); - final b = Uint8List(8); - - _b.xor(x); - _b.pack(b, 0, Endian.little); - _c.sub(r - ..set(_t1[b[0]]) - ..xor(_t2[b[2]]) - ..xor(_t3[b[4]]) - ..xor(_t4[b[6]])); - _a.sum(r - ..set(_t4[b[1]]) - ..xor(_t3[b[3]]) - ..xor(_t2[b[5]]) - ..xor(_t1[b[7]])); - _a.mul(mul); - } - - @override - int get byteLength => 64; -} - -// S-Boxes -final _t1 = [ - Register64(0x02aab17c, 0xf7e90c5e), - Register64(0xac424b03, 0xe243a8ec), - Register64(0x72cd5be3, 0x0dd5fcd3), - Register64(0x6d019b93, 0xf6f97f3a), - Register64(0xcd9978ff, 0xd21f9193), - Register64(0x7573a1c9, 0x708029e2), - Register64(0xb164326b, 0x922a83c3), - Register64(0x46883eee, 0x04915870), - Register64(0xeaace305, 0x7103ece6), - Register64(0xc54169b8, 0x08a3535c), - Register64(0x4ce75491, 0x8ddec47c), - Register64(0x0aa2f4df, 0xdc0df40c), - Register64(0x10b76f18, 0xa74dbefa), - Register64(0xc6ccb623, 0x5ad1ab6a), - Register64(0x13726121, 0x572fe2ff), - Register64(0x1a488c6f, 0x199d921e), - Register64(0x4bc9f9f4, 0xda0007ca), - Register64(0x26f5e6f6, 0xe85241c7), - Register64(0x859079db, 0xea5947b6), - Register64(0x4f1885c5, 0xc99e8c92), - Register64(0xd78e761e, 0xa96f864b), - Register64(0x8e36428c, 0x52b5c17d), - Register64(0x69cf6827, 0x373063c1), - Register64(0xb607c93d, 0x9bb4c56e), - Register64(0x7d820e76, 0x0e76b5ea), - Register64(0x645c9cc6, 0xf07fdc42), - Register64(0xbf38a078, 0x243342e0), - Register64(0x5f6b343c, 0x9d2e7d04), - Register64(0xf2c28aeb, 0x600b0ec6), - Register64(0x6c0ed85f, 0x7254bcac), - Register64(0x71592281, 0xa4db4fe5), - Register64(0x1967fa69, 0xce0fed9f), - Register64(0xfd5293f8, 0xb96545db), - Register64(0xc879e9d7, 0xf2a7600b), - Register64(0x86024892, 0x0193194e), - Register64(0xa4f9533b, 0x2d9cc0b3), - Register64(0x9053836c, 0x15957613), - Register64(0xdb6dcf8a, 0xfc357bf1), - Register64(0x18beea7a, 0x7a370f57), - Register64(0x037117ca, 0x50b99066), - Register64(0x6ab30a97, 0x74424a35), - Register64(0xf4e92f02, 0xe325249b), - Register64(0x7739db07, 0x061ccae1), - Register64(0xd8f3b49c, 0xeca42a05), - Register64(0xbd56be3f, 0x51382f73), - Register64(0x45faed58, 0x43b0bb28), - Register64(0x1c813d5c, 0x11bf1f83), - Register64(0x8af0e4b6, 0xd75fa169), - Register64(0x33ee18a4, 0x87ad9999), - Register64(0x3c26e8ea, 0xb1c94410), - Register64(0xb510102b, 0xc0a822f9), - Register64(0x141eef31, 0x0ce6123b), - Register64(0xfc65b900, 0x59ddb154), - Register64(0xe0158640, 0xc5e0e607), - Register64(0x884e0798, 0x26c3a3cf), - Register64(0x930d0d95, 0x23c535fd), - Register64(0x35638d75, 0x4e9a2b00), - Register64(0x4085fccf, 0x40469dd5), - Register64(0xc4b17ad2, 0x8be23a4c), - Register64(0xcab2f0fc, 0x6a3e6a2e), - Register64(0x2860971a, 0x6b943fcd), - Register64(0x3dde6ee2, 0x12e30446), - Register64(0x6222f32a, 0xe01765ae), - Register64(0x5d550bb5, 0x478308fe), - Register64(0xa9efa98d, 0xa0eda22a), - Register64(0xc351a716, 0x86c40da7), - Register64(0x1105586d, 0x9c867c84), - Register64(0xdcffee85, 0xfda22853), - Register64(0xccfbd026, 0x2c5eef76), - Register64(0xbaf294cb, 0x8990d201), - Register64(0xe69464f5, 0x2afad975), - Register64(0x94b013af, 0xdf133e14), - Register64(0x06a7d1a3, 0x2823c958), - Register64(0x6f95fe51, 0x30f61119), - Register64(0xd92ab34e, 0x462c06c0), - Register64(0xed7bde33, 0x887c71d2), - Register64(0x79746d6e, 0x6518393e), - Register64(0x5ba41938, 0x5d713329), - Register64(0x7c1ba6b9, 0x48a97564), - Register64(0x31987c19, 0x7bfdac67), - Register64(0xde6c23c4, 0x4b053d02), - Register64(0x581c49fe, 0xd002d64d), - Register64(0xdd474d63, 0x38261571), - Register64(0xaa4546c3, 0xe473d062), - Register64(0x928fce34, 0x9455f860), - Register64(0x48161bba, 0xcaab94d9), - Register64(0x63912430, 0x770e6f68), - Register64(0x6ec8a5e6, 0x02c6641c), - Register64(0x87282515, 0x337ddd2b), - Register64(0x2cda6b42, 0x034b701b), - Register64(0xb03d37c1, 0x81cb096d), - Register64(0xe1084382, 0x66c71c6f), - Register64(0x2b3180c7, 0xeb51b255), - Register64(0xdf92b82f, 0x96c08bbc), - Register64(0x5c68c8c0, 0xa632f3ba), - Register64(0x5504cc86, 0x1c3d0556), - Register64(0xabbfa4e5, 0x5fb26b8f), - Register64(0x41848b0a, 0xb3baceb4), - Register64(0xb334a273, 0xaa445d32), - Register64(0xbca696f0, 0xa85ad881), - Register64(0x24f6ec65, 0xb528d56c), - Register64(0x0ce1512e, 0x90f4524a), - Register64(0x4e9dd79d, 0x5506d35a), - Register64(0x258905fa, 0xc6ce9779), - Register64(0x2019295b, 0x3e109b33), - Register64(0xf8a9478b, 0x73a054cc), - Register64(0x2924f2f9, 0x34417eb0), - Register64(0x3993357d, 0x536d1bc4), - Register64(0x38a81ac2, 0x1db6ff8b), - Register64(0x47c4fbf1, 0x7d6016bf), - Register64(0x1e0faadd, 0x7667e3f5), - Register64(0x7abcff62, 0x938beb96), - Register64(0xa78dad94, 0x8fc179c9), - Register64(0x8f1f98b7, 0x2911e50d), - Register64(0x61e48eae, 0x27121a91), - Register64(0x4d62f7ad, 0x31859808), - Register64(0xeceba345, 0xef5ceaeb), - Register64(0xf5ceb25e, 0xbc9684ce), - Register64(0xf633e20c, 0xb7f76221), - Register64(0xa32cdf06, 0xab8293e4), - Register64(0x985a202c, 0xa5ee2ca4), - Register64(0xcf0b8447, 0xcc8a8fb1), - Register64(0x9f765244, 0x979859a3), - Register64(0xa8d516b1, 0xa1240017), - Register64(0x0bd7ba3e, 0xbb5dc726), - Register64(0xe54bca55, 0xb86adb39), - Register64(0x1d7a3afd, 0x6c478063), - Register64(0x519ec608, 0xe7669edd), - Register64(0x0e5715a2, 0xd149aa23), - Register64(0x177d4571, 0x848ff194), - Register64(0xeeb55f32, 0x41014c22), - Register64(0x0f5e5ca1, 0x3a6e2ec2), - Register64(0x8029927b, 0x75f5c361), - Register64(0xad139fab, 0xc3d6e436), - Register64(0x0d5df1a9, 0x4ccf402f), - Register64(0x3e8bd948, 0xbea5dfc8), - Register64(0xa5a0d357, 0xbd3ff77e), - Register64(0xa2d12e25, 0x1f74f645), - Register64(0x66fd9e52, 0x5e81a082), - Register64(0x2e0c90ce, 0x7f687a49), - Register64(0xc2e8bcbe, 0xba973bc5), - Register64(0x000001bc, 0xe509745f), - Register64(0x423777bb, 0xe6dab3d6), - Register64(0xd1661c7e, 0xaef06eb5), - Register64(0xa1781f35, 0x4daacfd8), - Register64(0x2d11284a, 0x2b16affc), - Register64(0xf1fc4f67, 0xfa891d1f), - Register64(0x73ecc25d, 0xcb920ada), - Register64(0xae610c22, 0xc2a12651), - Register64(0x96e0a810, 0xd356b78a), - Register64(0x5a9a381f, 0x2fe7870f), - Register64(0xd5ad62ed, 0xe94e5530), - Register64(0xd225e5e8, 0x368d1427), - Register64(0x65977b70, 0xc7af4631), - Register64(0x99f889b2, 0xde39d74f), - Register64(0x233f30bf, 0x54e1d143), - Register64(0x9a9675d3, 0xd9a63c97), - Register64(0x5470554f, 0xf334f9a8), - Register64(0x166acb74, 0x4a4f5688), - Register64(0x70c74caa, 0xb2e4aead), - Register64(0xf0d09164, 0x6f294d12), - Register64(0x57b82a89, 0x684031d1), - Register64(0xefd95a5a, 0x61be0b6b), - Register64(0x2fbd12e9, 0x69f2f29a), - Register64(0x9bd37013, 0xfeff9fe8), - Register64(0x3f9b0404, 0xd6085a06), - Register64(0x4940c1f3, 0x166cfe15), - Register64(0x09542c4d, 0xcdf3defb), - Register64(0xb4c52183, 0x85cd5ce3), - Register64(0xc935b7dc, 0x4462a641), - Register64(0x3417f8a6, 0x8ed3b63f), - Register64(0xb8095929, 0x5b215b40), - Register64(0xf99cdaef, 0x3b8c8572), - Register64(0x018c0614, 0xf8fcb95d), - Register64(0x1b14accd, 0x1a3acdf3), - Register64(0x84d471f2, 0x00bb732d), - Register64(0xc1a3110e, 0x95e8da16), - Register64(0x430a7220, 0xbf1a82b8), - Register64(0xb77e090d, 0x39df210e), - Register64(0x5ef4bd9f, 0x3cd05e9d), - Register64(0x9d4ff6da, 0x7e57a444), - Register64(0xda1d60e1, 0x83d4a5f8), - Register64(0xb287c384, 0x17998e47), - Register64(0xfe3edc12, 0x1bb31886), - Register64(0xc7fe3ccc, 0x980ccbef), - Register64(0xe46fb590, 0x189bfd03), - Register64(0x3732fd46, 0x9a4c57dc), - Register64(0x7ef700a0, 0x7cf1ad65), - Register64(0x59c64468, 0xa31d8859), - Register64(0x762fb0b4, 0xd45b61f6), - Register64(0x155baed0, 0x99047718), - Register64(0x68755e4c, 0x3d50baa6), - Register64(0xe9214e7f, 0x22d8b4df), - Register64(0x2addbf53, 0x2eac95f4), - Register64(0x32ae3909, 0xb4bd0109), - Register64(0x834df537, 0xb08e3450), - Register64(0xfa209da8, 0x4220728d), - Register64(0x9e691d9b, 0x9efe23f7), - Register64(0x0446d288, 0xc4ae8d7f), - Register64(0x7b4cc524, 0xe169785b), - Register64(0x21d87f01, 0x35ca1385), - Register64(0xcebb400f, 0x137b8aa5), - Register64(0x272e2b66, 0x580796be), - Register64(0x36122641, 0x25c2b0de), - Register64(0x057702bd, 0xad1efbb2), - Register64(0xd4babb8e, 0xacf84be9), - Register64(0x91583139, 0x641bc67b), - Register64(0x8bdc2de0, 0x8036e024), - Register64(0x603c8156, 0xf49f68ed), - Register64(0xf7d236f7, 0xdbef5111), - Register64(0x9727c459, 0x8ad21e80), - Register64(0xa08a0896, 0x670a5fd7), - Register64(0xcb4a8f43, 0x09eba9cb), - Register64(0x81af564b, 0x0f7036a1), - Register64(0xc0b99aa7, 0x78199abd), - Register64(0x959f1ec8, 0x3fc8e952), - Register64(0x8c505077, 0x794a81b9), - Register64(0x3acaaf8f, 0x056338f0), - Register64(0x07b43f50, 0x627a6778), - Register64(0x4a44ab49, 0xf5eccc77), - Register64(0x3bc3d6e4, 0xb679ee98), - Register64(0x9cc0d4d1, 0xcf14108c), - Register64(0x4406c00b, 0x206bc8a0), - Register64(0x82a18854, 0xc8d72d89), - Register64(0x67e366b3, 0x5c3c432c), - Register64(0xb923dd61, 0x102b37f2), - Register64(0x56ab2779, 0xd884271d), - Register64(0xbe83e1b0, 0xff1525af), - Register64(0xfb7c65d4, 0x217e49a9), - Register64(0x6bdbe0e7, 0x6d48e7d4), - Register64(0x08df8287, 0x45d9179e), - Register64(0x22ea6a9a, 0xdd53bd34), - Register64(0xe36e141c, 0x5622200a), - Register64(0x7f805d1b, 0x8cb750ee), - Register64(0xafe5c7a5, 0x9f58e837), - Register64(0xe27f996a, 0x4fb1c23c), - Register64(0xd3867dfb, 0x0775f0d0), - Register64(0xd0e673de, 0x6e88891a), - Register64(0x123aeb9e, 0xafb86c25), - Register64(0x30f1d5d5, 0xc145b895), - Register64(0xbb434a2d, 0xee7269e7), - Register64(0x78cb67ec, 0xf931fa38), - Register64(0xf33b0372, 0x323bbf9c), - Register64(0x52d66336, 0xfb279c74), - Register64(0x505f33ac, 0x0afb4eaa), - Register64(0xe8a5cd99, 0xa2cce187), - Register64(0x53497480, 0x1e2d30bb), - Register64(0x8d2d5711, 0xd5876d90), - Register64(0x1f1a4128, 0x91bc038e), - Register64(0xd6e2e71d, 0x82e56648), - Register64(0x74036c3a, 0x497732b7), - Register64(0x89b67ed9, 0x6361f5ab), - Register64(0xffed95d8, 0xf1ea02a2), - Register64(0xe72b3bd6, 0x1464d43d), - Register64(0xa6300f17, 0x0bdc4820), - Register64(0xebc18760, 0xed78a77a), -]; - -final _t2 = [ - Register64(0xe6a6be5a, 0x05a12138), - Register64(0xb5a122a5, 0xb4f87c98), - Register64(0x563c6089, 0x140b6990), - Register64(0x4c46cb2e, 0x391f5dd5), - Register64(0xd932addb, 0xc9b79434), - Register64(0x08ea70e4, 0x2015aff5), - Register64(0xd765a667, 0x3e478cf1), - Register64(0xc4fb757e, 0xab278d99), - Register64(0xdf11c686, 0x2d6e0692), - Register64(0xddeb84f1, 0x0d7f3b16), - Register64(0x6f2ef604, 0xa665ea04), - Register64(0x4a8e0f0f, 0xf0e0dfb3), - Register64(0xa5edeef8, 0x3dbcba51), - Register64(0xfc4f0a2a, 0x0ea4371e), - Register64(0xe83e1da8, 0x5cb38429), - Register64(0xdc8ff882, 0xba1b1ce2), - Register64(0xcd45505e, 0x8353e80d), - Register64(0x18d19a00, 0xd4db0717), - Register64(0x34a0cfed, 0xa5f38101), - Register64(0x0be77e51, 0x8887caf2), - Register64(0x1e341438, 0xb3c45136), - Register64(0xe05797f4, 0x9089ccf9), - Register64(0xffd23f9d, 0xf2591d14), - Register64(0x543dda22, 0x8595c5cd), - Register64(0x661f81fd, 0x99052a33), - Register64(0x8736e641, 0xdb0f7b76), - Register64(0x15227725, 0x418e5307), - Register64(0xe25f7f46, 0x162eb2fa), - Register64(0x48a8b212, 0x6c13d9fe), - Register64(0xafdc5417, 0x92e76eea), - Register64(0x03d912bf, 0xc6d1898f), - Register64(0x31b1aafa, 0x1b83f51b), - Register64(0xf1ac2796, 0xe42ab7d9), - Register64(0x40a3a7d7, 0xfcd2ebac), - Register64(0x1056136d, 0x0afbbcc5), - Register64(0x7889e1dd, 0x9a6d0c85), - Register64(0xd3352578, 0x2a7974aa), - Register64(0xa7e25d09, 0x078ac09b), - Register64(0xbd4138b3, 0xeac6edd0), - Register64(0x920abfbe, 0x71eb9e70), - Register64(0xa2a5d0f5, 0x4fc2625c), - Register64(0xc054e36b, 0x0b1290a3), - Register64(0xf6dd59ff, 0x62fe932b), - Register64(0x35373545, 0x11a8ac7d), - Register64(0xca845e91, 0x72fadcd4), - Register64(0x84f82b60, 0x329d20dc), - Register64(0x79c62ce1, 0xcd672f18), - Register64(0x8b09a2ad, 0xd124642c), - Register64(0xd0c1e96a, 0x19d9e726), - Register64(0x5a786a9b, 0x4ba9500c), - Register64(0x0e020336, 0x634c43f3), - Register64(0xc17b474a, 0xeb66d822), - Register64(0x6a731ae3, 0xec9baac2), - Register64(0x8226667a, 0xe0840258), - Register64(0x67d45676, 0x91caeca5), - Register64(0x1d94155c, 0x4875adb5), - Register64(0x6d00fd98, 0x5b813fdf), - Register64(0x51286efc, 0xb774cd06), - Register64(0x5e883447, 0x1fa744af), - Register64(0xf72ca0ae, 0xe761ae2e), - Register64(0xbe40e4cd, 0xaee8e09a), - Register64(0xe9970bbb, 0x5118f665), - Register64(0x726e4beb, 0x33df1964), - Register64(0x703b0007, 0x29199762), - Register64(0x4631d816, 0xf5ef30a7), - Register64(0xb880b5b5, 0x1504a6be), - Register64(0x641793c3, 0x7ed84b6c), - Register64(0x7b21ed77, 0xf6e97d96), - Register64(0x77630631, 0x2ef96b73), - Register64(0xae528948, 0xe86ff3f4), - Register64(0x53dbd7f2, 0x86a3f8f8), - Register64(0x16cadce7, 0x4cfc1063), - Register64(0x005c19bd, 0xfa52c6dd), - Register64(0x68868f5d, 0x64d46ad3), - Register64(0x3a9d512c, 0xcf1e186a), - Register64(0x367e62c2, 0x385660ae), - Register64(0xe359e7ea, 0x77dcb1d7), - Register64(0x526c0773, 0x749abe6e), - Register64(0x735ae5f9, 0xd09f734b), - Register64(0x493fc7cc, 0x8a558ba8), - Register64(0xb0b9c153, 0x3041ab45), - Register64(0x321958ba, 0x470a59bd), - Register64(0x852db00b, 0x5f46c393), - Register64(0x91209b2b, 0xd336b0e5), - Register64(0x6e604f7d, 0x659ef19f), - Register64(0xb99a8ae2, 0x782ccb24), - Register64(0xccf52ab6, 0xc814c4c7), - Register64(0x4727d9af, 0xbe11727b), - Register64(0x7e950d0c, 0x0121b34d), - Register64(0x756f4356, 0x70ad471f), - Register64(0xf5add442, 0x615a6849), - Register64(0x4e87e099, 0x80b9957a), - Register64(0x2acfa1df, 0x50aee355), - Register64(0xd898263a, 0xfd2fd556), - Register64(0xc8f4924d, 0xd80c8fd6), - Register64(0xcf99ca3d, 0x754a173a), - Register64(0xfe477bac, 0xaf91bf3c), - Register64(0xed5371f6, 0xd690c12d), - Register64(0x831a5c28, 0x5e687094), - Register64(0xc5d3c90a, 0x3708a0a4), - Register64(0x0f7f9037, 0x17d06580), - Register64(0x19f9bb13, 0xb8fdf27f), - Register64(0xb1bd6f1b, 0x4d502843), - Register64(0x1c761ba3, 0x8fff4012), - Register64(0x0d1530c4, 0xe2e21f3b), - Register64(0x8943ce69, 0xa7372c8a), - Register64(0xe5184e11, 0xfeb5ce66), - Register64(0x618bdb80, 0xbd736621), - Register64(0x7d29bad6, 0x8b574d0b), - Register64(0x81bb613e, 0x25e6fe5b), - Register64(0x071c9c10, 0xbc07913f), - Register64(0xc7beeb79, 0x09ac2d97), - Register64(0xc3e58d35, 0x3bc5d757), - Register64(0xeb017892, 0xf38f61e8), - Register64(0xd4effb9c, 0x9b1cc21a), - Register64(0x99727d26, 0xf494f7ab), - Register64(0xa3e063a2, 0x956b3e03), - Register64(0x9d4a8b9a, 0x4aa09c30), - Register64(0x3f6ab7d5, 0x00090fb4), - Register64(0x9cc0f2a0, 0x57268ac0), - Register64(0x3dee9d2d, 0xedbf42d1), - Register64(0x330f49c8, 0x7960a972), - Register64(0xc6b27202, 0x87421b41), - Register64(0x0ac59ec0, 0x7c00369c), - Register64(0xef4eac49, 0xcb353425), - Register64(0xf450244e, 0xef0129d8), - Register64(0x8acc46e5, 0xcaf4deb6), - Register64(0x2ffeab63, 0x989263f7), - Register64(0x8f7cb9fe, 0x5d7a4578), - Register64(0x5bd8f764, 0x4e634635), - Register64(0x427a7315, 0xbf2dc900), - Register64(0x17d0c4aa, 0x2125261c), - Register64(0x3992486c, 0x93518e50), - Register64(0xb4cbfee0, 0xa2d7d4c3), - Register64(0x7c75d620, 0x2c5ddd8d), - Register64(0xdbc295d8, 0xe35b6c61), - Register64(0x60b369d3, 0x02032b19), - Register64(0xce42685f, 0xdce44132), - Register64(0x06f3ddb9, 0xddf65610), - Register64(0x8ea4d21d, 0xb5e148f0), - Register64(0x20b0fce6, 0x2fcd496f), - Register64(0x2c1b9123, 0x58b0ee31), - Register64(0xb28317b8, 0x18f5a308), - Register64(0xa89c1e18, 0x9ca6d2cf), - Register64(0x0c6b1857, 0x6aaadbc8), - Register64(0xb65deaa9, 0x1299fae3), - Register64(0xfb2b794b, 0x7f1027e7), - Register64(0x04e4317f, 0x443b5beb), - Register64(0x4b852d32, 0x5939d0a6), - Register64(0xd5ae6bee, 0xfb207ffc), - Register64(0x309682b2, 0x81c7d374), - Register64(0xbae309a1, 0x94c3b475), - Register64(0x8cc3f97b, 0x13b49f05), - Register64(0x98a9422f, 0xf8293967), - Register64(0x244b16b0, 0x1076ff7c), - Register64(0xf8bf571c, 0x663d67ee), - Register64(0x1f0d6758, 0xeee30da1), - Register64(0xc9b611d9, 0x7adeb9b7), - Register64(0xb7afd588, 0x7b6c57a2), - Register64(0x6290ae84, 0x6b984fe1), - Register64(0x94df4cde, 0xacc1a5fd), - Register64(0x058a5bd1, 0xc5483aff), - Register64(0x63166cc1, 0x42ba3c37), - Register64(0x8db8526e, 0xb2f76f40), - Register64(0xe1088003, 0x6f0d6d4e), - Register64(0x9e0523c9, 0x971d311d), - Register64(0x45ec2824, 0xcc7cd691), - Register64(0x575b8359, 0xe62382c9), - Register64(0xfa9e400d, 0xc4889995), - Register64(0xd1823ecb, 0x45721568), - Register64(0xdafd983b, 0x8206082f), - Register64(0xaa7d2908, 0x2386a8cb), - Register64(0x269fcd44, 0x03b87588), - Register64(0x1b91f5f7, 0x28bdd1e0), - Register64(0xe4669f39, 0x040201f6), - Register64(0x7a1d7c21, 0x8cf04ade), - Register64(0x65623c29, 0xd79ce5ce), - Register64(0x23684490, 0x96c00bb1), - Register64(0xab9bf187, 0x9da503ba), - Register64(0xbc23ecb1, 0xa458058e), - Register64(0x9a58df01, 0xbb401ecc), - Register64(0xa070e868, 0xa85f143d), - Register64(0x4ff18830, 0x7df2239e), - Register64(0x14d565b4, 0x1a641183), - Register64(0xee133374, 0x52701602), - Register64(0x950e3dcf, 0x3f285e09), - Register64(0x59930254, 0xb9c80953), - Register64(0x3bf29940, 0x8930da6d), - Register64(0xa955943f, 0x53691387), - Register64(0xa15edeca, 0xa9cb8784), - Register64(0x29142127, 0x352be9a0), - Register64(0x76f0371f, 0xff4e7afb), - Register64(0x0239f450, 0x274f2228), - Register64(0xbb073af0, 0x1d5e868b), - Register64(0xbfc80571, 0xc10e96c1), - Register64(0xd2670885, 0x68222e23), - Register64(0x9671a3d4, 0x8e80b5b0), - Register64(0x55b5d38a, 0xe193bb81), - Register64(0x693ae2d0, 0xa18b04b8), - Register64(0x5c48b4ec, 0xadd5335f), - Register64(0xfd743b19, 0x4916a1ca), - Register64(0x25770181, 0x34be98c4), - Register64(0xe77987e8, 0x3c54a4ad), - Register64(0x28e11014, 0xda33e1b9), - Register64(0x270cc59e, 0x226aa213), - Register64(0x71495f75, 0x6d1a5f60), - Register64(0x9be853fb, 0x60afef77), - Register64(0xadc786a7, 0xf7443dbf), - Register64(0x09044561, 0x73b29a82), - Register64(0x58bc7a66, 0xc232bd5e), - Register64(0xf306558c, 0x673ac8b2), - Register64(0x41f639c6, 0xb6c9772a), - Register64(0x216defe9, 0x9fda35da), - Register64(0x11640cc7, 0x1c7be615), - Register64(0x93c43694, 0x565c5527), - Register64(0xea038e62, 0x46777839), - Register64(0xf9abf3ce, 0x5a3e2469), - Register64(0x741e768d, 0x0fd312d2), - Register64(0x0144b883, 0xced652c6), - Register64(0xc20b5a5b, 0xa33f8552), - Register64(0x1ae69633, 0xc3435a9d), - Register64(0x97a28ca4, 0x088cfdec), - Register64(0x8824a43c, 0x1e96f420), - Register64(0x37612fa6, 0x6eeea746), - Register64(0x6b4cb165, 0xf9cf0e5a), - Register64(0x43aa1c06, 0xa0abfb4a), - Register64(0x7f4dc26f, 0xf162796b), - Register64(0x6cbacc8e, 0x54ed9b0f), - Register64(0xa6b7ffef, 0xd2bb253e), - Register64(0x2e25bc95, 0xb0a29d4f), - Register64(0x86d6a58b, 0xdef1388c), - Register64(0xded74ac5, 0x76b6f054), - Register64(0x8030bdbc, 0x2b45805d), - Register64(0x3c81af70, 0xe94d9289), - Register64(0x3eff6dda, 0x9e3100db), - Register64(0xb38dc39f, 0xdfcc8847), - Register64(0x12388552, 0x8d17b87e), - Register64(0xf2da0ed2, 0x40b1b642), - Register64(0x44cefadc, 0xd54bf9a9), - Register64(0x1312200e, 0x433c7ee6), - Register64(0x9ffcc84f, 0x3a78c748), - Register64(0xf0cd1f72, 0x248576bb), - Register64(0xec697405, 0x3638cfe4), - Register64(0x2ba7b67c, 0x0cec4e4c), - Register64(0xac2f4df3, 0xe5ce32ed), - Register64(0xcb33d143, 0x26ea4c11), - Register64(0xa4e9044c, 0xc77e58bc), - Register64(0x5f513293, 0xd934fcef), - Register64(0x5dc96455, 0x06e55444), - Register64(0x50de418f, 0x317de40a), - Register64(0x388cb31a, 0x69dde259), - Register64(0x2db4a834, 0x55820a86), - Register64(0x9010a91e, 0x84711ae9), - Register64(0x4df7f0b7, 0xb1498371), - Register64(0xd62a2eab, 0xc0977179), - Register64(0x22fac097, 0xaa8d5c0e), -]; - -final _t3 = [ - Register64(0xf49fcc2f, 0xf1daf39b), - Register64(0x487fd5c6, 0x6ff29281), - Register64(0xe8a30667, 0xfcdca83f), - Register64(0x2c9b4be3, 0xd2fcce63), - Register64(0xda3ff74b, 0x93fbbbc2), - Register64(0x2fa165d2, 0xfe70ba66), - Register64(0xa103e279, 0x970e93d4), - Register64(0xbecdec77, 0xb0e45e71), - Register64(0xcfb41e72, 0x3985e497), - Register64(0xb70aaa02, 0x5ef75017), - Register64(0xd42309f0, 0x3840b8e0), - Register64(0x8efc1ad0, 0x35898579), - Register64(0x96c6920b, 0xe2b2abc5), - Register64(0x66af4163, 0x375a9172), - Register64(0x2174abdc, 0xca7127fb), - Register64(0xb33ccea6, 0x4a72ff41), - Register64(0xf04a4933, 0x083066a5), - Register64(0x8d970acd, 0xd7289af5), - Register64(0x8f96e8e0, 0x31c8c25e), - Register64(0xf3fec022, 0x76875d47), - Register64(0xec7bf310, 0x056190dd), - Register64(0xf5adb0ae, 0xbb0f1491), - Register64(0x9b50f885, 0x0fd58892), - Register64(0x49754883, 0x58b74de8), - Register64(0xa3354ff6, 0x91531c61), - Register64(0x0702bbe4, 0x81d2c6ee), - Register64(0x89fb2405, 0x7deded98), - Register64(0xac307513, 0x8596e902), - Register64(0x1d2d3580, 0x172772ed), - Register64(0xeb738fc2, 0x8e6bc30d), - Register64(0x5854ef8f, 0x63044326), - Register64(0x9e5c5232, 0x5add3bbe), - Register64(0x90aa53cf, 0x325c4623), - Register64(0xc1d24d51, 0x349dd067), - Register64(0x2051cfee, 0xa69ea624), - Register64(0x13220f0a, 0x862e7e4f), - Register64(0xce393994, 0x04e04864), - Register64(0xd9c42ca4, 0x7086fcb7), - Register64(0x685ad223, 0x8a03e7cc), - Register64(0x066484b2, 0xab2ff1db), - Register64(0xfe9d5d70, 0xefbf79ec), - Register64(0x5b13b9dd, 0x9c481854), - Register64(0x15f0d475, 0xed1509ad), - Register64(0x0bebcd06, 0x0ec79851), - Register64(0xd58c6791, 0x183ab7f8), - Register64(0xd1187c50, 0x52f3eee4), - Register64(0xc95d1192, 0xe54e82ff), - Register64(0x86eea14c, 0xb9ac6ca2), - Register64(0x3485beb1, 0x53677d5d), - Register64(0xdd191d78, 0x1f8c492a), - Register64(0xf60866ba, 0xa784ebf9), - Register64(0x518f643b, 0xa2d08c74), - Register64(0x8852e956, 0xe1087c22), - Register64(0xa768cb8d, 0xc410ae8d), - Register64(0x38047726, 0xbfec8e1a), - Register64(0xa67738b4, 0xcd3b45aa), - Register64(0xad16691c, 0xec0dde19), - Register64(0xc6d43193, 0x80462e07), - Register64(0xc5a5876d, 0x0ba61938), - Register64(0x16b9fa1f, 0xa58fd840), - Register64(0x188ab117, 0x3ca74f18), - Register64(0xabda2f98, 0xc99c021f), - Register64(0x3e0580ab, 0x134ae816), - Register64(0x5f3b05b7, 0x73645abb), - Register64(0x2501a2be, 0x5575f2f6), - Register64(0x1b2f7400, 0x4e7e8ba9), - Register64(0x1cd75803, 0x71e8d953), - Register64(0x7f6ed895, 0x62764e30), - Register64(0xb15926ff, 0x596f003d), - Register64(0x9f65293d, 0xa8c5d6b9), - Register64(0x6ecef04d, 0xd690f84c), - Register64(0x4782275f, 0xff33af88), - Register64(0xe4143308, 0x3f820801), - Register64(0xfd0dfe40, 0x9a1af9b5), - Register64(0x4325a334, 0x2cdb396b), - Register64(0x8ae77e62, 0xb301b252), - Register64(0xc36f9e9f, 0x6655615a), - Register64(0x85455a2d, 0x92d32c09), - Register64(0xf2c7dea9, 0x49477485), - Register64(0x63cfb4c1, 0x33a39eba), - Register64(0x83b040cc, 0x6ebc5462), - Register64(0x3b9454c8, 0xfdb326b0), - Register64(0x56f56a9e, 0x87ffd78c), - Register64(0x2dc2940d, 0x99f42bc6), - Register64(0x98f7df09, 0x6b096e2d), - Register64(0x19a6e01e, 0x3ad852bf), - Register64(0x42a99ccb, 0xdbd4b40b), - Register64(0xa59998af, 0x45e9c559), - Register64(0x366295e8, 0x07d93186), - Register64(0x6b48181b, 0xfaa1f773), - Register64(0x1fec57e2, 0x157a0a1d), - Register64(0x4667446a, 0xf6201ad5), - Register64(0xe615ebca, 0xcfb0f075), - Register64(0xb8f31f4f, 0x68290778), - Register64(0x22713ed6, 0xce22d11e), - Register64(0x3057c1a7, 0x2ec3c93b), - Register64(0xcb46acc3, 0x7c3f1f2f), - Register64(0xdbb893fd, 0x02aaf50e), - Register64(0x331fd92e, 0x600b9fcf), - Register64(0xa498f961, 0x48ea3ad6), - Register64(0xa8d8426e, 0x8b6a83ea), - Register64(0xa089b274, 0xb7735cdc), - Register64(0x87f6b373, 0x1e524a11), - Register64(0x118808e5, 0xcbc96749), - Register64(0x9906e4c7, 0xb19bd394), - Register64(0xafed7f7e, 0x9b24a20c), - Register64(0x6509eade, 0xeb3644a7), - Register64(0x6c1ef1d3, 0xe8ef0ede), - Register64(0xb9c97d43, 0xe9798fb4), - Register64(0xa2f2d784, 0x740c28a3), - Register64(0x7b849647, 0x6197566f), - Register64(0x7a5be3e6, 0xb65f069d), - Register64(0xf96330ed, 0x78be6f10), - Register64(0xeee60de7, 0x7a076a15), - Register64(0x2b4bee4a, 0xa08b9bd0), - Register64(0x6a56a63e, 0xc7b8894e), - Register64(0x02121359, 0xba34fef4), - Register64(0x4cbf99f8, 0x283703fc), - Register64(0x39807135, 0x0caf30c8), - Register64(0xd0a77a89, 0xf017687a), - Register64(0xf1c1a9eb, 0x9e423569), - Register64(0x8c797628, 0x2dee8199), - Register64(0x5d1737a5, 0xdd1f7abd), - Register64(0x4f53433c, 0x09a9fa80), - Register64(0xfa8b0c53, 0xdf7ca1d9), - Register64(0x3fd9dcbc, 0x886ccb77), - Register64(0xc040917c, 0xa91b4720), - Register64(0x7dd00142, 0xf9d1dcdf), - Register64(0x8476fc1d, 0x4f387b58), - Register64(0x23f8e7c5, 0xf3316503), - Register64(0x032a2244, 0xe7e37339), - Register64(0x5c87a5d7, 0x50f5a74b), - Register64(0x082b4cc4, 0x3698992e), - Register64(0xdf917bec, 0xb858f63c), - Register64(0x3270b8fc, 0x5bf86dda), - Register64(0x10ae72bb, 0x29b5dd76), - Register64(0x576ac94e, 0x7700362b), - Register64(0x1ad112da, 0xc61efb8f), - Register64(0x691bc30e, 0xc5faa427), - Register64(0xff246311, 0xcc327143), - Register64(0x3142368e, 0x30e53206), - Register64(0x71380e31, 0xe02ca396), - Register64(0x958d5c96, 0x0aad76f1), - Register64(0xf8d6f430, 0xc16da536), - Register64(0xc8ffd13f, 0x1be7e1d2), - Register64(0x7578ae66, 0x004ddbe1), - Register64(0x05833f01, 0x067be646), - Register64(0xbb34b5ad, 0x3bfe586d), - Register64(0x095f34c9, 0xa12b97f0), - Register64(0x247ab645, 0x25d60ca8), - Register64(0xdcdbc6f3, 0x017477d1), - Register64(0x4a2e14d4, 0xdecad24d), - Register64(0xbdb5e6d9, 0xbe0a1eeb), - Register64(0x2a7e70f7, 0x794301ab), - Register64(0xdef42d8a, 0x270540fd), - Register64(0x01078ec0, 0xa34c22c1), - Register64(0xe5de511a, 0xf4c16387), - Register64(0x7ebb3a52, 0xbd9a330a), - Register64(0x77697857, 0xaa7d6435), - Register64(0x004e8316, 0x03ae4c32), - Register64(0xe7a21020, 0xad78e312), - Register64(0x9d41a70c, 0x6ab420f2), - Register64(0x28e06c18, 0xea1141e6), - Register64(0xd2b28cbd, 0x984f6b28), - Register64(0x26b75f6c, 0x446e9d83), - Register64(0xba47568c, 0x4d418d7f), - Register64(0xd80badbf, 0xe6183d8e), - Register64(0x0e206d7f, 0x5f166044), - Register64(0xe258a439, 0x11cbca3e), - Register64(0x723a1746, 0xb21dc0bc), - Register64(0xc7caa854, 0xf5d7cdd3), - Register64(0x7cac3288, 0x3d261d9c), - Register64(0x7690c264, 0x23ba942c), - Register64(0x17e55524, 0x478042b8), - Register64(0xe0be4776, 0x56a2389f), - Register64(0x4d289b5e, 0x67ab2da0), - Register64(0x44862b9c, 0x8fbbfd31), - Register64(0xb47cc804, 0x9d141365), - Register64(0x822c1b36, 0x2b91c793), - Register64(0x4eb14655, 0xfb13dfd8), - Register64(0x1ecbba07, 0x14e2a97b), - Register64(0x6143459d, 0x5cde5f14), - Register64(0x53a8fbf1, 0xd5f0ac89), - Register64(0x97ea04d8, 0x1c5e5b00), - Register64(0x622181a8, 0xd4fdb3f3), - Register64(0xe9bcd341, 0x572a1208), - Register64(0x14112586, 0x43cce58a), - Register64(0x9144c5fe, 0xa4c6e0a4), - Register64(0x0d33d065, 0x65cf620f), - Register64(0x54a48d48, 0x9f219ca1), - Register64(0xc43e5eac, 0x6d63c821), - Register64(0xa9728b3a, 0x72770daf), - Register64(0xd7934e7b, 0x20df87ef), - Register64(0xe35503b6, 0x1a3e86e5), - Register64(0xcae321fb, 0xc819d504), - Register64(0x129a50b3, 0xac60bfa6), - Register64(0xcd5e68ea, 0x7e9fb6c3), - Register64(0xb01c9019, 0x9483b1c7), - Register64(0x3de93cd5, 0xc295376c), - Register64(0xaed52edf, 0x2ab9ad13), - Register64(0x2e60f512, 0xc0a07884), - Register64(0xbc3d86a3, 0xe36210c9), - Register64(0x35269d9b, 0x163951ce), - Register64(0x0c7d6e2a, 0xd0cdb5fa), - Register64(0x59e86297, 0xd87f5733), - Register64(0x298ef221, 0x898db0e7), - Register64(0x55000029, 0xd1a5aa7e), - Register64(0x8bc08ae1, 0xb5061b45), - Register64(0xc2c31c2b, 0x6c92703a), - Register64(0x94cc596b, 0xaf25ef42), - Register64(0x0a1d73db, 0x22540456), - Register64(0x04b6a0f9, 0xd9c4179a), - Register64(0xeffdafa2, 0xae3d3c60), - Register64(0xf7c8075b, 0xb49496c4), - Register64(0x9cc5c714, 0x1d1cd4e3), - Register64(0x78bd1638, 0x218e5534), - Register64(0xb2f11568, 0xf850246a), - Register64(0xedfabcfa, 0x9502bc29), - Register64(0x796ce5f2, 0xda23051b), - Register64(0xaae128b0, 0xdc93537c), - Register64(0x3a493da0, 0xee4b29ae), - Register64(0xb5df6b2c, 0x416895d7), - Register64(0xfcabbd25, 0x122d7f37), - Register64(0x70810b58, 0x105dc4b1), - Register64(0xe10fdd37, 0xf7882a90), - Register64(0x524dcab5, 0x518a3f5c), - Register64(0x3c9e8587, 0x8451255b), - Register64(0x40298281, 0x19bd34e2), - Register64(0x74a05b6f, 0x5d3ceccb), - Register64(0xb6100215, 0x42e13eca), - Register64(0x0ff979d1, 0x2f59e2ac), - Register64(0x6037da27, 0xe4f9cc50), - Register64(0x5e92975a, 0x0df1847d), - Register64(0xd66de190, 0xd3e623fe), - Register64(0x5032d6b8, 0x7b568048), - Register64(0x9a36b7ce, 0x8235216e), - Register64(0x80272a7a, 0x24f64b4a), - Register64(0x93efed8b, 0x8c6916f7), - Register64(0x37ddbff4, 0x4cce1555), - Register64(0x4b95db5d, 0x4b99bd25), - Register64(0x92d3fda1, 0x69812fc0), - Register64(0xfb1a4a9a, 0x90660bb6), - Register64(0x730c1969, 0x46a4b9b2), - Register64(0x81e289aa, 0x7f49da68), - Register64(0x64669a0f, 0x83b1a05f), - Register64(0x27b3ff7d, 0x9644f48b), - Register64(0xcc6b615c, 0x8db675b3), - Register64(0x674f20b9, 0xbcebbe95), - Register64(0x6f312382, 0x75655982), - Register64(0x5ae48871, 0x3e45cf05), - Register64(0xbf619f99, 0x54c21157), - Register64(0xeabac460, 0x40a8eae9), - Register64(0x454c6fe9, 0xf2c0c1cd), - Register64(0x419cf649, 0x6412691c), - Register64(0xd3dc3bef, 0x265b0f70), - Register64(0x6d0e60f5, 0xc3578a9e), -]; - -final _t4 = [ - Register64(0x5b0e6085, 0x26323c55), - Register64(0x1a46c1a9, 0xfa1b59f5), - Register64(0xa9e245a1, 0x7c4c8ffa), - Register64(0x65ca5159, 0xdb2955d7), - Register64(0x05db0a76, 0xce35afc2), - Register64(0x81eac77e, 0xa9113d45), - Register64(0x528ef88a, 0xb6ac0a0d), - Register64(0xa09ea253, 0x597be3ff), - Register64(0x430ddfb3, 0xac48cd56), - Register64(0xc4b3a67a, 0xf45ce46f), - Register64(0x4ececfd8, 0xfbe2d05e), - Register64(0x3ef56f10, 0xb39935f0), - Register64(0x0b22d682, 0x9cd619c6), - Register64(0x17fd460a, 0x74df2069), - Register64(0x6cf8cc8e, 0x8510ed40), - Register64(0xd6c824bf, 0x3a6ecaa7), - Register64(0x61243d58, 0x1a817049), - Register64(0x048bacb6, 0xbbc163a2), - Register64(0xd9a38ac2, 0x7d44cc32), - Register64(0x7fddff5b, 0xaaf410ab), - Register64(0xad6d495a, 0xa804824b), - Register64(0xe1a6a74f, 0x2d8c9f94), - Register64(0xd4f78512, 0x35dee8e3), - Register64(0xfd4b7f88, 0x6540d893), - Register64(0x247c2004, 0x2aa4bfda), - Register64(0x096ea1c5, 0x17d1327c), - Register64(0xd56966b4, 0x361a6685), - Register64(0x277da5c3, 0x1221057d), - Register64(0x94d59893, 0xa43acff7), - Register64(0x64f0c51c, 0xcdc02281), - Register64(0x3d33bcc4, 0xff6189db), - Register64(0xe005cb18, 0x4ce66af1), - Register64(0xff5ccd1d, 0x1db99bea), - Register64(0xb0b854a7, 0xfe42980f), - Register64(0x7bd46a6a, 0x718d4b9f), - Register64(0xd10fa8cc, 0x22a5fd8c), - Register64(0xd3148495, 0x2be4bd31), - Register64(0xc7fa975f, 0xcb243847), - Register64(0x4886ed1e, 0x5846c407), - Register64(0x28cddb79, 0x1eb70b04), - Register64(0xc2b00be2, 0xf573417f), - Register64(0x5c959045, 0x2180f877), - Register64(0x7a6bddff, 0xf370eb00), - Register64(0xce509e38, 0xd6d9d6a4), - Register64(0xebeb0f00, 0x647fa702), - Register64(0x1dcc06cf, 0x76606f06), - Register64(0xe4d9f28b, 0xa286ff0a), - Register64(0xd85a305d, 0xc918c262), - Register64(0x475b1d87, 0x32225f54), - Register64(0x2d4fb516, 0x68ccb5fe), - Register64(0xa679b9d9, 0xd72bba20), - Register64(0x53841c0d, 0x912d43a5), - Register64(0x3b7eaa48, 0xbf12a4e8), - Register64(0x781e0e47, 0xf22f1ddf), - Register64(0xeff20ce6, 0x0ab50973), - Register64(0x20d261d1, 0x9dffb742), - Register64(0x16a12b03, 0x062a2e39), - Register64(0x1960eb22, 0x39650495), - Register64(0x251c16fe, 0xd50eb8b8), - Register64(0x9ac0c330, 0xf826016e), - Register64(0xed152665, 0x953e7671), - Register64(0x02d63194, 0xa6369570), - Register64(0x5074f083, 0x94b1c987), - Register64(0x70ba598c, 0x90b25ce1), - Register64(0x794a1581, 0x0b9742f6), - Register64(0x0d5925e9, 0xfcaf8c6c), - Register64(0x3067716c, 0xd868744e), - Register64(0x910ab077, 0xe8d7731b), - Register64(0x6a61bbdb, 0x5ac42f61), - Register64(0x93513efb, 0xf0851567), - Register64(0xf494724b, 0x9e83e9d5), - Register64(0xe887e198, 0x5c09648d), - Register64(0x34b1d3c6, 0x75370cfd), - Register64(0xdc35e433, 0xbc0d255d), - Register64(0xd0aab842, 0x34131be0), - Register64(0x08042a50, 0xb48b7eaf), - Register64(0x9997c4ee, 0x44a3ab35), - Register64(0x829a7b49, 0x201799d0), - Register64(0x263b8307, 0xb7c54441), - Register64(0x752f95f4, 0xfd6a6ca6), - Register64(0x92721740, 0x2c08c6e5), - Register64(0x2a8ab754, 0xa795d9ee), - Register64(0xa442f755, 0x2f72943d), - Register64(0x2c31334e, 0x19781208), - Register64(0x4fa98d7c, 0xeaee6291), - Register64(0x55c3862f, 0x665db309), - Register64(0xbd061017, 0x5d53b1f3), - Register64(0x46fe6cb8, 0x40413f27), - Register64(0x3fe03792, 0xdf0cfa59), - Register64(0xcfe70037, 0x2eb85e8f), - Register64(0xa7be29e7, 0xadbce118), - Register64(0xe544ee5c, 0xde8431dd), - Register64(0x8a781b1b, 0x41f1873e), - Register64(0xa5c94c78, 0xa0d2f0e7), - Register64(0x39412e28, 0x77b60728), - Register64(0xa1265ef3, 0xafc9a62c), - Register64(0xbcc2770c, 0x6a2506c5), - Register64(0x3ab66dd5, 0xdce1ce12), - Register64(0xe65499d0, 0x4a675b37), - Register64(0x7d8f5234, 0x81bfd216), - Register64(0x0f6f64fc, 0xec15f389), - Register64(0x74efbe61, 0x8b5b13c8), - Register64(0xacdc82b7, 0x14273e1d), - Register64(0xdd40bfe0, 0x03199d17), - Register64(0x37e99257, 0xe7e061f8), - Register64(0xfa526269, 0x04775aaa), - Register64(0x8bbbf63a, 0x463d56f9), - Register64(0xf0013f15, 0x43a26e64), - Register64(0xa8307e9f, 0x879ec898), - Register64(0xcc4c27a4, 0x150177cc), - Register64(0x1b432f2c, 0xca1d3348), - Register64(0xde1d1f8f, 0x9f6fa013), - Register64(0x606602a0, 0x47a7ddd6), - Register64(0xd237ab64, 0xcc1cb2c7), - Register64(0x9b938e72, 0x25fcd1d3), - Register64(0xec4e0370, 0x8e0ff476), - Register64(0xfeb2fbda, 0x3d03c12d), - Register64(0xae0bced2, 0xee43889a), - Register64(0x22cb8923, 0xebfb4f43), - Register64(0x69360d01, 0x3cf7396d), - Register64(0x855e3602, 0xd2d4e022), - Register64(0x073805ba, 0xd01f784c), - Register64(0x33e17a13, 0x3852f546), - Register64(0xdf487405, 0x8ac7b638), - Register64(0xba92b29c, 0x678aa14a), - Register64(0x0ce89fc7, 0x6cfaadcd), - Register64(0x5f9d4e09, 0x08339e34), - Register64(0xf1afe929, 0x1f5923b9), - Register64(0x6e3480f6, 0x0f4a265f), - Register64(0xeebf3a2a, 0xb29b841c), - Register64(0xe21938a8, 0x8f91b4ad), - Register64(0x57dfeff8, 0x45c6d3c3), - Register64(0x2f006b0b, 0xf62caaf2), - Register64(0x62f479ef, 0x6f75ee78), - Register64(0x11a55ad4, 0x1c8916a9), - Register64(0xf229d290, 0x84fed453), - Register64(0x42f1c27b, 0x16b000e6), - Register64(0x2b1f7674, 0x9823c074), - Register64(0x4b76eca3, 0xc2745360), - Register64(0x8c98f463, 0xb91691bd), - Register64(0x14bcc93c, 0xf1ade66a), - Register64(0x8885213e, 0x6d458397), - Register64(0x8e177df0, 0x274d4711), - Register64(0xb49b73b5, 0x503f2951), - Register64(0x10168168, 0xc3f96b6b), - Register64(0x0e3d963b, 0x63cab0ae), - Register64(0x8dfc4b56, 0x55a1db14), - Register64(0xf789f135, 0x6e14de5c), - Register64(0x683e68af, 0x4e51dac1), - Register64(0xc9a84f9d, 0x8d4b0fd9), - Register64(0x3691e03f, 0x52a0f9d1), - Register64(0x5ed86e46, 0xe1878e80), - Register64(0x3c711a0e, 0x99d07150), - Register64(0x5a0865b2, 0x0c4e9310), - Register64(0x56fbfc1f, 0xe4f0682e), - Register64(0xea8d5de3, 0x105edf9b), - Register64(0x71abfdb1, 0x2379187a), - Register64(0x2eb99de1, 0xbee77b9c), - Register64(0x21ecc0ea, 0x33cf4523), - Register64(0x59a4d752, 0x1805c7a1), - Register64(0x3896f5eb, 0x56ae7c72), - Register64(0xaa638f3d, 0xb18f75dc), - Register64(0x9f39358d, 0xabe9808e), - Register64(0xb7defa91, 0xc00b72ac), - Register64(0x6b5541fd, 0x62492d92), - Register64(0x6dc6dee8, 0xf92e4d5b), - Register64(0x353f57ab, 0xc4beea7e), - Register64(0x735769d6, 0xda5690ce), - Register64(0x0a234aa6, 0x42391484), - Register64(0xf6f95080, 0x28f80d9d), - Register64(0xb8e319a2, 0x7ab3f215), - Register64(0x31ad9c11, 0x51341a4d), - Register64(0x773c22a5, 0x7bef5805), - Register64(0x45c7561a, 0x07968633), - Register64(0xf913da9e, 0x249dbe36), - Register64(0xda652d9b, 0x78a64c68), - Register64(0x4c27a97f, 0x3bc334ef), - Register64(0x76621220, 0xe66b17f4), - Register64(0x96774389, 0x9acd7d0b), - Register64(0xf3ee5bca, 0xe0ed6782), - Register64(0x409f7536, 0x00c879fc), - Register64(0x06d09a39, 0xb5926db6), - Register64(0x6f83aeb0, 0x317ac588), - Register64(0x01e6ca4a, 0x86381f21), - Register64(0x66ff3462, 0xd19f3025), - Register64(0x72207c24, 0xddfd3bfb), - Register64(0x4af6b6d3, 0xe2ece2eb), - Register64(0x9c994dbe, 0xc7ea08de), - Register64(0x49ace597, 0xb09a8bc4), - Register64(0xb38c4766, 0xcf0797ba), - Register64(0x131b9373, 0xc57c2a75), - Register64(0xb1822cce, 0x61931e58), - Register64(0x9d7555b9, 0x09ba1c0c), - Register64(0x127fafdd, 0x937d11d2), - Register64(0x29da3bad, 0xc66d92e4), - Register64(0xa2c1d571, 0x54c2ecbc), - Register64(0x58c5134d, 0x82f6fe24), - Register64(0x1c3ae351, 0x5b62274f), - Register64(0xe907c82e, 0x01cb8126), - Register64(0xf8ed0919, 0x13e37fcb), - Register64(0x3249d8f9, 0xc80046c9), - Register64(0x80cf9bed, 0xe388fb63), - Register64(0x1881539a, 0x116cf19e), - Register64(0x5103f3f7, 0x6bd52457), - Register64(0x15b7e6f5, 0xae47f7a8), - Register64(0xdbd7c6de, 0xd47e9ccf), - Register64(0x44e55c41, 0x0228bb1a), - Register64(0xb647d425, 0x5edb4e99), - Register64(0x5d11882b, 0xb8aafc30), - Register64(0xf5098bbb, 0x29d3212a), - Register64(0x8fb5ea14, 0xe90296b3), - Register64(0x677b9421, 0x57dd025a), - Register64(0xfb58e7c0, 0xa390acb5), - Register64(0x89d3674c, 0x83bd4a01), - Register64(0x9e2da4df, 0x4bf3b93b), - Register64(0xfcc41e32, 0x8cab4829), - Register64(0x03f38c96, 0xba582c52), - Register64(0xcad1bdbd, 0x7fd85db2), - Register64(0xbbb442c1, 0x6082ae83), - Register64(0xb95fe86b, 0xa5da9ab0), - Register64(0xb22e0467, 0x3771a93f), - Register64(0x845358c9, 0x493152d8), - Register64(0xbe2a4886, 0x97b4541e), - Register64(0x95a2dc2d, 0xd38e6966), - Register64(0xc02c11ac, 0x923c852b), - Register64(0x2388b199, 0x0df2a87b), - Register64(0x7c8008fa, 0x1b4f37be), - Register64(0x1f70d0c8, 0x4d54e503), - Register64(0x5490adec, 0x7ece57d4), - Register64(0x002b3c27, 0xd9063a3a), - Register64(0x7eaea384, 0x8030a2bf), - Register64(0xc602326d, 0xed2003c0), - Register64(0x83a7287d, 0x69a94086), - Register64(0xc57a5fcb, 0x30f57a8a), - Register64(0xb56844e4, 0x79ebe779), - Register64(0xa373b40f, 0x05dcbce9), - Register64(0xd71a786e, 0x88570ee2), - Register64(0x879cbacd, 0xbde8f6a0), - Register64(0x976ad1bc, 0xc164a32f), - Register64(0xab21e25e, 0x9666d78b), - Register64(0x901063aa, 0xe5e5c33c), - Register64(0x9818b344, 0x48698d90), - Register64(0xe36487ae, 0x3e1e8abb), - Register64(0xafbdf931, 0x893bdcb4), - Register64(0x6345a0dc, 0x5fbbd519), - Register64(0x8628fe26, 0x9b9465ca), - Register64(0x1e5d0160, 0x3f9c51ec), - Register64(0x4de44006, 0xa15049b7), - Register64(0xbf6c70e5, 0xf776cbb1), - Register64(0x411218f2, 0xef552bed), - Register64(0xcb0c0708, 0x705a36a3), - Register64(0xe74d1475, 0x4f986044), - Register64(0xcd56d943, 0x0ea8280e), - Register64(0xc12591d7, 0x535f5065), - Register64(0xc83223f1, 0x720aef96), - Register64(0xc3a0396f, 0x7363a51f), -]; diff --git a/pointycastle/lib/digests/whirlpool.dart b/pointycastle/lib/digests/whirlpool.dart deleted file mode 100644 index 8b5ddf8..0000000 --- a/pointycastle/lib/digests/whirlpool.dart +++ /dev/null @@ -1,2297 +0,0 @@ -// See file LICENSE for more information. - -library impl.digest.whirlpool; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_digest.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of Whirlpool digest. -class WhirlpoolDigest extends BaseDigest implements Digest { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Digest, 'Whirlpool', () => WhirlpoolDigest()); - - static const _DIGEST_lENGTH_BYTES = 512 ~/ 8; - static const _BUFFER_SIZE = 64; - static const _ROUNDS = 10; - static final _r64Zero = Register64(0); - - static final _zerosList = Uint8List(_BUFFER_SIZE); - - final _buffer = Uint8List(_BUFFER_SIZE); - int _bufferPos = 0; - - final _bitCount = Register64List(4); - - final _hash = Register64List(8); - final _k = Register64List(8); - final _l = Register64List(8); - final _block = Register64List(8); - final _state = Register64List(8); - - WhirlpoolDigest() { - reset(); - } - - @override - final algorithmName = 'Whirlpool'; - @override - final digestSize = _DIGEST_lENGTH_BYTES; - - @override - void reset() { - _bufferPos = 0; - _buffer.fillRange(0, _buffer.length, 0); - - _bitCount.fillRange(0, _bitCount.length, 0); - - _hash.fillRange(0, _hash.length, 0); - _k.fillRange(0, _k.length, 0); - _l.fillRange(0, _l.length, 0); - _block.fillRange(0, _block.length, 0); - _state.fillRange(0, _state.length, 0); - } - - @override - void updateByte(int inp) { - _buffer[_bufferPos++] = inp; - - if (_bufferPos == _buffer.length) { - _processFilledBuffer(_buffer, 0); - } - - _increment(); - } - - @override - void update(Uint8List inp, int inpOff, int len) { - for (var i = 0; i < len; i++) { - _buffer[_bufferPos++] = inp[inpOff + i]; - - if (_bufferPos == _buffer.length) { - _processFilledBuffer(_buffer, 0); - } - } - - _increment(len * 8); - } - - @override - int doFinal(Uint8List out, int outOff) { - _finish(); - - for (var i = 0; i < 8; i++) { - _hash[i].pack(out, outOff + (i * 8), Endian.big); - } - - reset(); - - return digestSize; - } - - void _processFilledBuffer(Uint8List inp, int inpOff) { - for (var i = 0; i < _state.length; i++) { - _block[i].unpack(_buffer, i * 8, Endian.big); - } - - _processBlock(); - - _bufferPos = 0; - _buffer.fillRange(0, _buffer.length, 0); - } - - void _processBlock() { - // compute and apply K^0 - for (var i = 0; i < 8; i++) { - _k[i].set(_hash[i]); - _state[i] - ..set(_block[i]) - ..xor(_k[i]); - } - - // iterate over the rounds - for (var round = 1; round <= _ROUNDS; round++) { - for (var i = 0; i < 8; i++) { - _l[i].set(0); - _l[i].xor(_c0[clip8(_k[(i - 0) & 7].hi32 >> 24)]); - _l[i].xor(_c1[clip8(_k[(i - 1) & 7].hi32 >> 16)]); - _l[i].xor(_c2[clip8(_k[(i - 2) & 7].hi32 >> 8)]); - _l[i].xor(_c3[clip8(_k[(i - 3) & 7].hi32)]); - _l[i].xor(_c4[clip8(_k[(i - 4) & 7].lo32 >> 24)]); - _l[i].xor(_c5[clip8(_k[(i - 5) & 7].lo32 >> 16)]); - _l[i].xor(_c6[clip8(_k[(i - 6) & 7].lo32 >> 8)]); - _l[i].xor(_c7[clip8(_k[(i - 7) & 7].lo32)]); - } - - _k.setRange(0, _k.length, _l); - - _k[0].xor(_rc[round]); - - // apply the round transformation - for (var i = 0; i < 8; i++) { - _l[i].set(_k[i]); - _l[i].xor(_c0[clip8(_state[(i - 0) & 7].hi32 >> 24)]); - _l[i].xor(_c1[clip8(_state[(i - 1) & 7].hi32 >> 16)]); - _l[i].xor(_c2[clip8(_state[(i - 2) & 7].hi32 >> 8)]); - _l[i].xor(_c3[clip8(_state[(i - 3) & 7].hi32)]); - _l[i].xor(_c4[clip8(_state[(i - 4) & 7].lo32 >> 24)]); - _l[i].xor(_c5[clip8(_state[(i - 5) & 7].lo32 >> 16)]); - _l[i].xor(_c6[clip8(_state[(i - 6) & 7].lo32 >> 8)]); - _l[i].xor(_c7[clip8(_state[(i - 7) & 7].lo32)]); - } - - // save the current state - _state.setRange(0, _state.length, _l); - } - - // apply Miuaguchi-Preneel compression - final r = Register64(); - for (var i = 0; i < 8; i++) { - _hash[i].xor(r - ..set(_state[i]) - ..xor(_block[i])); - } - } - - void _increment([int bits = 8]) { - assert(bits <= 0xFFFFFFFF); - - var i = _bitCount.length - 1; - _bitCount[i].sum(bits); - - while (_bitCount[i] == _r64Zero) { - i--; - _bitCount[i].sum(1); - } - } - - void _finish() { - /* - * this makes a copy of the current bit length. at the expense of an - * object creation of 32 bytes rather than providing a _stopCounting - * boolean which was the alternative I could think of. - */ - final bitLength = _copyBitLength(); - - // Add padding - _buffer[_bufferPos++] |= 0x80; - - if (_bufferPos == _buffer.length) { - _processFilledBuffer(_buffer, 0); - } - - if (_bufferPos > 32) { - final padCount = _buffer.length - _bufferPos; - update(_zerosList, 0, padCount); - } else { - final padCount = 32 - _bufferPos; - update(_zerosList, 0, padCount); - } - - // Add the length information to the final 32 bytes of the 64 byte block - _buffer.setRange(32, 32 + bitLength.length, bitLength); - - // Process final block - _processFilledBuffer(_buffer, 0); - } - - Uint8List _copyBitLength() { - final rv = Uint8List(_bitCount.length * 8); - for (var i = 0; i < _bitCount.length; i++) { - _bitCount[i].pack(rv, i * 8, Endian.big); - } - return rv; - } - - @override - int get byteLength => 64; -} - -final _c0 = Register64List.from([ - [0x18186018, 0xc07830d8], - [0x23238c23, 0x05af4626], - [0xc6c63fc6, 0x7ef991b8], - [0xe8e887e8, 0x136fcdfb], - [0x87872687, 0x4ca113cb], - [0xb8b8dab8, 0xa9626d11], - [0x01010401, 0x08050209], - [0x4f4f214f, 0x426e9e0d], - [0x3636d836, 0xadee6c9b], - [0xa6a6a2a6, 0x590451ff], - [0xd2d26fd2, 0xdebdb90c], - [0xf5f5f3f5, 0xfb06f70e], - [0x7979f979, 0xef80f296], - [0x6f6fa16f, 0x5fcede30], - [0x91917e91, 0xfcef3f6d], - [0x52525552, 0xaa07a4f8], - [0x60609d60, 0x27fdc047], - [0xbcbccabc, 0x89766535], - [0x9b9b569b, 0xaccd2b37], - [0x8e8e028e, 0x048c018a], - [0xa3a3b6a3, 0x71155bd2], - [0x0c0c300c, 0x603c186c], - [0x7b7bf17b, 0xff8af684], - [0x3535d435, 0xb5e16a80], - [0x1d1d741d, 0xe8693af5], - [0xe0e0a7e0, 0x5347ddb3], - [0xd7d77bd7, 0xf6acb321], - [0xc2c22fc2, 0x5eed999c], - [0x2e2eb82e, 0x6d965c43], - [0x4b4b314b, 0x627a9629], - [0xfefedffe, 0xa321e15d], - [0x57574157, 0x8216aed5], - [0x15155415, 0xa8412abd], - [0x7777c177, 0x9fb6eee8], - [0x3737dc37, 0xa5eb6e92], - [0xe5e5b3e5, 0x7b56d79e], - [0x9f9f469f, 0x8cd92313], - [0xf0f0e7f0, 0xd317fd23], - [0x4a4a354a, 0x6a7f9420], - [0xdada4fda, 0x9e95a944], - [0x58587d58, 0xfa25b0a2], - [0xc9c903c9, 0x06ca8fcf], - [0x2929a429, 0x558d527c], - [0x0a0a280a, 0x5022145a], - [0xb1b1feb1, 0xe14f7f50], - [0xa0a0baa0, 0x691a5dc9], - [0x6b6bb16b, 0x7fdad614], - [0x85852e85, 0x5cab17d9], - [0xbdbdcebd, 0x8173673c], - [0x5d5d695d, 0xd234ba8f], - [0x10104010, 0x80502090], - [0xf4f4f7f4, 0xf303f507], - [0xcbcb0bcb, 0x16c08bdd], - [0x3e3ef83e, 0xedc67cd3], - [0x05051405, 0x28110a2d], - [0x67678167, 0x1fe6ce78], - [0xe4e4b7e4, 0x7353d597], - [0x27279c27, 0x25bb4e02], - [0x41411941, 0x32588273], - [0x8b8b168b, 0x2c9d0ba7], - [0xa7a7a6a7, 0x510153f6], - [0x7d7de97d, 0xcf94fab2], - [0x95956e95, 0xdcfb3749], - [0xd8d847d8, 0x8e9fad56], - [0xfbfbcbfb, 0x8b30eb70], - [0xeeee9fee, 0x2371c1cd], - [0x7c7ced7c, 0xc791f8bb], - [0x66668566, 0x17e3cc71], - [0xdddd53dd, 0xa68ea77b], - [0x17175c17, 0xb84b2eaf], - [0x47470147, 0x02468e45], - [0x9e9e429e, 0x84dc211a], - [0xcaca0fca, 0x1ec589d4], - [0x2d2db42d, 0x75995a58], - [0xbfbfc6bf, 0x9179632e], - [0x07071c07, 0x381b0e3f], - [0xadad8ead, 0x012347ac], - [0x5a5a755a, 0xea2fb4b0], - [0x83833683, 0x6cb51bef], - [0x3333cc33, 0x85ff66b6], - [0x63639163, 0x3ff2c65c], - [0x02020802, 0x100a0412], - [0xaaaa92aa, 0x39384993], - [0x7171d971, 0xafa8e2de], - [0xc8c807c8, 0x0ecf8dc6], - [0x19196419, 0xc87d32d1], - [0x49493949, 0x7270923b], - [0xd9d943d9, 0x869aaf5f], - [0xf2f2eff2, 0xc31df931], - [0xe3e3abe3, 0x4b48dba8], - [0x5b5b715b, 0xe22ab6b9], - [0x88881a88, 0x34920dbc], - [0x9a9a529a, 0xa4c8293e], - [0x26269826, 0x2dbe4c0b], - [0x3232c832, 0x8dfa64bf], - [0xb0b0fab0, 0xe94a7d59], - [0xe9e983e9, 0x1b6acff2], - [0x0f0f3c0f, 0x78331e77], - [0xd5d573d5, 0xe6a6b733], - [0x80803a80, 0x74ba1df4], - [0xbebec2be, 0x997c6127], - [0xcdcd13cd, 0x26de87eb], - [0x3434d034, 0xbde46889], - [0x48483d48, 0x7a759032], - [0xffffdbff, 0xab24e354], - [0x7a7af57a, 0xf78ff48d], - [0x90907a90, 0xf4ea3d64], - [0x5f5f615f, 0xc23ebe9d], - [0x20208020, 0x1da0403d], - [0x6868bd68, 0x67d5d00f], - [0x1a1a681a, 0xd07234ca], - [0xaeae82ae, 0x192c41b7], - [0xb4b4eab4, 0xc95e757d], - [0x54544d54, 0x9a19a8ce], - [0x93937693, 0xece53b7f], - [0x22228822, 0x0daa442f], - [0x64648d64, 0x07e9c863], - [0xf1f1e3f1, 0xdb12ff2a], - [0x7373d173, 0xbfa2e6cc], - [0x12124812, 0x905a2482], - [0x40401d40, 0x3a5d807a], - [0x08082008, 0x40281048], - [0xc3c32bc3, 0x56e89b95], - [0xecec97ec, 0x337bc5df], - [0xdbdb4bdb, 0x9690ab4d], - [0xa1a1bea1, 0x611f5fc0], - [0x8d8d0e8d, 0x1c830791], - [0x3d3df43d, 0xf5c97ac8], - [0x97976697, 0xccf1335b], - [0x00000000, 0x00000000], - [0xcfcf1bcf, 0x36d483f9], - [0x2b2bac2b, 0x4587566e], - [0x7676c576, 0x97b3ece1], - [0x82823282, 0x64b019e6], - [0xd6d67fd6, 0xfea9b128], - [0x1b1b6c1b, 0xd87736c3], - [0xb5b5eeb5, 0xc15b7774], - [0xafaf86af, 0x112943be], - [0x6a6ab56a, 0x77dfd41d], - [0x50505d50, 0xba0da0ea], - [0x45450945, 0x124c8a57], - [0xf3f3ebf3, 0xcb18fb38], - [0x3030c030, 0x9df060ad], - [0xefef9bef, 0x2b74c3c4], - [0x3f3ffc3f, 0xe5c37eda], - [0x55554955, 0x921caac7], - [0xa2a2b2a2, 0x791059db], - [0xeaea8fea, 0x0365c9e9], - [0x65658965, 0x0fecca6a], - [0xbabad2ba, 0xb9686903], - [0x2f2fbc2f, 0x65935e4a], - [0xc0c027c0, 0x4ee79d8e], - [0xdede5fde, 0xbe81a160], - [0x1c1c701c, 0xe06c38fc], - [0xfdfdd3fd, 0xbb2ee746], - [0x4d4d294d, 0x52649a1f], - [0x92927292, 0xe4e03976], - [0x7575c975, 0x8fbceafa], - [0x06061806, 0x301e0c36], - [0x8a8a128a, 0x249809ae], - [0xb2b2f2b2, 0xf940794b], - [0xe6e6bfe6, 0x6359d185], - [0x0e0e380e, 0x70361c7e], - [0x1f1f7c1f, 0xf8633ee7], - [0x62629562, 0x37f7c455], - [0xd4d477d4, 0xeea3b53a], - [0xa8a89aa8, 0x29324d81], - [0x96966296, 0xc4f43152], - [0xf9f9c3f9, 0x9b3aef62], - [0xc5c533c5, 0x66f697a3], - [0x25259425, 0x35b14a10], - [0x59597959, 0xf220b2ab], - [0x84842a84, 0x54ae15d0], - [0x7272d572, 0xb7a7e4c5], - [0x3939e439, 0xd5dd72ec], - [0x4c4c2d4c, 0x5a619816], - [0x5e5e655e, 0xca3bbc94], - [0x7878fd78, 0xe785f09f], - [0x3838e038, 0xddd870e5], - [0x8c8c0a8c, 0x14860598], - [0xd1d163d1, 0xc6b2bf17], - [0xa5a5aea5, 0x410b57e4], - [0xe2e2afe2, 0x434dd9a1], - [0x61619961, 0x2ff8c24e], - [0xb3b3f6b3, 0xf1457b42], - [0x21218421, 0x15a54234], - [0x9c9c4a9c, 0x94d62508], - [0x1e1e781e, 0xf0663cee], - [0x43431143, 0x22528661], - [0xc7c73bc7, 0x76fc93b1], - [0xfcfcd7fc, 0xb32be54f], - [0x04041004, 0x20140824], - [0x51515951, 0xb208a2e3], - [0x99995e99, 0xbcc72f25], - [0x6d6da96d, 0x4fc4da22], - [0x0d0d340d, 0x68391a65], - [0xfafacffa, 0x8335e979], - [0xdfdf5bdf, 0xb684a369], - [0x7e7ee57e, 0xd79bfca9], - [0x24249024, 0x3db44819], - [0x3b3bec3b, 0xc5d776fe], - [0xabab96ab, 0x313d4b9a], - [0xcece1fce, 0x3ed181f0], - [0x11114411, 0x88552299], - [0x8f8f068f, 0x0c890383], - [0x4e4e254e, 0x4a6b9c04], - [0xb7b7e6b7, 0xd1517366], - [0xebeb8beb, 0x0b60cbe0], - [0x3c3cf03c, 0xfdcc78c1], - [0x81813e81, 0x7cbf1ffd], - [0x94946a94, 0xd4fe3540], - [0xf7f7fbf7, 0xeb0cf31c], - [0xb9b9deb9, 0xa1676f18], - [0x13134c13, 0x985f268b], - [0x2c2cb02c, 0x7d9c5851], - [0xd3d36bd3, 0xd6b8bb05], - [0xe7e7bbe7, 0x6b5cd38c], - [0x6e6ea56e, 0x57cbdc39], - [0xc4c437c4, 0x6ef395aa], - [0x03030c03, 0x180f061b], - [0x56564556, 0x8a13acdc], - [0x44440d44, 0x1a49885e], - [0x7f7fe17f, 0xdf9efea0], - [0xa9a99ea9, 0x21374f88], - [0x2a2aa82a, 0x4d825467], - [0xbbbbd6bb, 0xb16d6b0a], - [0xc1c123c1, 0x46e29f87], - [0x53535153, 0xa202a6f1], - [0xdcdc57dc, 0xae8ba572], - [0x0b0b2c0b, 0x58271653], - [0x9d9d4e9d, 0x9cd32701], - [0x6c6cad6c, 0x47c1d82b], - [0x3131c431, 0x95f562a4], - [0x7474cd74, 0x87b9e8f3], - [0xf6f6fff6, 0xe309f115], - [0x46460546, 0x0a438c4c], - [0xacac8aac, 0x092645a5], - [0x89891e89, 0x3c970fb5], - [0x14145014, 0xa04428b4], - [0xe1e1a3e1, 0x5b42dfba], - [0x16165816, 0xb04e2ca6], - [0x3a3ae83a, 0xcdd274f7], - [0x6969b969, 0x6fd0d206], - [0x09092409, 0x482d1241], - [0x7070dd70, 0xa7ade0d7], - [0xb6b6e2b6, 0xd954716f], - [0xd0d067d0, 0xceb7bd1e], - [0xeded93ed, 0x3b7ec7d6], - [0xcccc17cc, 0x2edb85e2], - [0x42421542, 0x2a578468], - [0x98985a98, 0xb4c22d2c], - [0xa4a4aaa4, 0x490e55ed], - [0x2828a028, 0x5d885075], - [0x5c5c6d5c, 0xda31b886], - [0xf8f8c7f8, 0x933fed6b], - [0x86862286, 0x44a411c2] -]); - -final _c1 = Register64List.from([ - [0xd8181860, 0x18c07830], - [0x2623238c, 0x2305af46], - [0xb8c6c63f, 0xc67ef991], - [0xfbe8e887, 0xe8136fcd], - [0xcb878726, 0x874ca113], - [0x11b8b8da, 0xb8a9626d], - [0x09010104, 0x01080502], - [0x0d4f4f21, 0x4f426e9e], - [0x9b3636d8, 0x36adee6c], - [0xffa6a6a2, 0xa6590451], - [0x0cd2d26f, 0xd2debdb9], - [0x0ef5f5f3, 0xf5fb06f7], - [0x967979f9, 0x79ef80f2], - [0x306f6fa1, 0x6f5fcede], - [0x6d91917e, 0x91fcef3f], - [0xf8525255, 0x52aa07a4], - [0x4760609d, 0x6027fdc0], - [0x35bcbcca, 0xbc897665], - [0x379b9b56, 0x9baccd2b], - [0x8a8e8e02, 0x8e048c01], - [0xd2a3a3b6, 0xa371155b], - [0x6c0c0c30, 0x0c603c18], - [0x847b7bf1, 0x7bff8af6], - [0x803535d4, 0x35b5e16a], - [0xf51d1d74, 0x1de8693a], - [0xb3e0e0a7, 0xe05347dd], - [0x21d7d77b, 0xd7f6acb3], - [0x9cc2c22f, 0xc25eed99], - [0x432e2eb8, 0x2e6d965c], - [0x294b4b31, 0x4b627a96], - [0x5dfefedf, 0xfea321e1], - [0xd5575741, 0x578216ae], - [0xbd151554, 0x15a8412a], - [0xe87777c1, 0x779fb6ee], - [0x923737dc, 0x37a5eb6e], - [0x9ee5e5b3, 0xe57b56d7], - [0x139f9f46, 0x9f8cd923], - [0x23f0f0e7, 0xf0d317fd], - [0x204a4a35, 0x4a6a7f94], - [0x44dada4f, 0xda9e95a9], - [0xa258587d, 0x58fa25b0], - [0xcfc9c903, 0xc906ca8f], - [0x7c2929a4, 0x29558d52], - [0x5a0a0a28, 0x0a502214], - [0x50b1b1fe, 0xb1e14f7f], - [0xc9a0a0ba, 0xa0691a5d], - [0x146b6bb1, 0x6b7fdad6], - [0xd985852e, 0x855cab17], - [0x3cbdbdce, 0xbd817367], - [0x8f5d5d69, 0x5dd234ba], - [0x90101040, 0x10805020], - [0x07f4f4f7, 0xf4f303f5], - [0xddcbcb0b, 0xcb16c08b], - [0xd33e3ef8, 0x3eedc67c], - [0x2d050514, 0x0528110a], - [0x78676781, 0x671fe6ce], - [0x97e4e4b7, 0xe47353d5], - [0x0227279c, 0x2725bb4e], - [0x73414119, 0x41325882], - [0xa78b8b16, 0x8b2c9d0b], - [0xf6a7a7a6, 0xa7510153], - [0xb27d7de9, 0x7dcf94fa], - [0x4995956e, 0x95dcfb37], - [0x56d8d847, 0xd88e9fad], - [0x70fbfbcb, 0xfb8b30eb], - [0xcdeeee9f, 0xee2371c1], - [0xbb7c7ced, 0x7cc791f8], - [0x71666685, 0x6617e3cc], - [0x7bdddd53, 0xdda68ea7], - [0xaf17175c, 0x17b84b2e], - [0x45474701, 0x4702468e], - [0x1a9e9e42, 0x9e84dc21], - [0xd4caca0f, 0xca1ec589], - [0x582d2db4, 0x2d75995a], - [0x2ebfbfc6, 0xbf917963], - [0x3f07071c, 0x07381b0e], - [0xacadad8e, 0xad012347], - [0xb05a5a75, 0x5aea2fb4], - [0xef838336, 0x836cb51b], - [0xb63333cc, 0x3385ff66], - [0x5c636391, 0x633ff2c6], - [0x12020208, 0x02100a04], - [0x93aaaa92, 0xaa393849], - [0xde7171d9, 0x71afa8e2], - [0xc6c8c807, 0xc80ecf8d], - [0xd1191964, 0x19c87d32], - [0x3b494939, 0x49727092], - [0x5fd9d943, 0xd9869aaf], - [0x31f2f2ef, 0xf2c31df9], - [0xa8e3e3ab, 0xe34b48db], - [0xb95b5b71, 0x5be22ab6], - [0xbc88881a, 0x8834920d], - [0x3e9a9a52, 0x9aa4c829], - [0x0b262698, 0x262dbe4c], - [0xbf3232c8, 0x328dfa64], - [0x59b0b0fa, 0xb0e94a7d], - [0xf2e9e983, 0xe91b6acf], - [0x770f0f3c, 0x0f78331e], - [0x33d5d573, 0xd5e6a6b7], - [0xf480803a, 0x8074ba1d], - [0x27bebec2, 0xbe997c61], - [0xebcdcd13, 0xcd26de87], - [0x893434d0, 0x34bde468], - [0x3248483d, 0x487a7590], - [0x54ffffdb, 0xffab24e3], - [0x8d7a7af5, 0x7af78ff4], - [0x6490907a, 0x90f4ea3d], - [0x9d5f5f61, 0x5fc23ebe], - [0x3d202080, 0x201da040], - [0x0f6868bd, 0x6867d5d0], - [0xca1a1a68, 0x1ad07234], - [0xb7aeae82, 0xae192c41], - [0x7db4b4ea, 0xb4c95e75], - [0xce54544d, 0x549a19a8], - [0x7f939376, 0x93ece53b], - [0x2f222288, 0x220daa44], - [0x6364648d, 0x6407e9c8], - [0x2af1f1e3, 0xf1db12ff], - [0xcc7373d1, 0x73bfa2e6], - [0x82121248, 0x12905a24], - [0x7a40401d, 0x403a5d80], - [0x48080820, 0x08402810], - [0x95c3c32b, 0xc356e89b], - [0xdfecec97, 0xec337bc5], - [0x4ddbdb4b, 0xdb9690ab], - [0xc0a1a1be, 0xa1611f5f], - [0x918d8d0e, 0x8d1c8307], - [0xc83d3df4, 0x3df5c97a], - [0x5b979766, 0x97ccf133], - [0x00000000, 0x00000000], - [0xf9cfcf1b, 0xcf36d483], - [0x6e2b2bac, 0x2b458756], - [0xe17676c5, 0x7697b3ec], - [0xe6828232, 0x8264b019], - [0x28d6d67f, 0xd6fea9b1], - [0xc31b1b6c, 0x1bd87736], - [0x74b5b5ee, 0xb5c15b77], - [0xbeafaf86, 0xaf112943], - [0x1d6a6ab5, 0x6a77dfd4], - [0xea50505d, 0x50ba0da0], - [0x57454509, 0x45124c8a], - [0x38f3f3eb, 0xf3cb18fb], - [0xad3030c0, 0x309df060], - [0xc4efef9b, 0xef2b74c3], - [0xda3f3ffc, 0x3fe5c37e], - [0xc7555549, 0x55921caa], - [0xdba2a2b2, 0xa2791059], - [0xe9eaea8f, 0xea0365c9], - [0x6a656589, 0x650fecca], - [0x03babad2, 0xbab96869], - [0x4a2f2fbc, 0x2f65935e], - [0x8ec0c027, 0xc04ee79d], - [0x60dede5f, 0xdebe81a1], - [0xfc1c1c70, 0x1ce06c38], - [0x46fdfdd3, 0xfdbb2ee7], - [0x1f4d4d29, 0x4d52649a], - [0x76929272, 0x92e4e039], - [0xfa7575c9, 0x758fbcea], - [0x36060618, 0x06301e0c], - [0xae8a8a12, 0x8a249809], - [0x4bb2b2f2, 0xb2f94079], - [0x85e6e6bf, 0xe66359d1], - [0x7e0e0e38, 0x0e70361c], - [0xe71f1f7c, 0x1ff8633e], - [0x55626295, 0x6237f7c4], - [0x3ad4d477, 0xd4eea3b5], - [0x81a8a89a, 0xa829324d], - [0x52969662, 0x96c4f431], - [0x62f9f9c3, 0xf99b3aef], - [0xa3c5c533, 0xc566f697], - [0x10252594, 0x2535b14a], - [0xab595979, 0x59f220b2], - [0xd084842a, 0x8454ae15], - [0xc57272d5, 0x72b7a7e4], - [0xec3939e4, 0x39d5dd72], - [0x164c4c2d, 0x4c5a6198], - [0x945e5e65, 0x5eca3bbc], - [0x9f7878fd, 0x78e785f0], - [0xe53838e0, 0x38ddd870], - [0x988c8c0a, 0x8c148605], - [0x17d1d163, 0xd1c6b2bf], - [0xe4a5a5ae, 0xa5410b57], - [0xa1e2e2af, 0xe2434dd9], - [0x4e616199, 0x612ff8c2], - [0x42b3b3f6, 0xb3f1457b], - [0x34212184, 0x2115a542], - [0x089c9c4a, 0x9c94d625], - [0xee1e1e78, 0x1ef0663c], - [0x61434311, 0x43225286], - [0xb1c7c73b, 0xc776fc93], - [0x4ffcfcd7, 0xfcb32be5], - [0x24040410, 0x04201408], - [0xe3515159, 0x51b208a2], - [0x2599995e, 0x99bcc72f], - [0x226d6da9, 0x6d4fc4da], - [0x650d0d34, 0x0d68391a], - [0x79fafacf, 0xfa8335e9], - [0x69dfdf5b, 0xdfb684a3], - [0xa97e7ee5, 0x7ed79bfc], - [0x19242490, 0x243db448], - [0xfe3b3bec, 0x3bc5d776], - [0x9aabab96, 0xab313d4b], - [0xf0cece1f, 0xce3ed181], - [0x99111144, 0x11885522], - [0x838f8f06, 0x8f0c8903], - [0x044e4e25, 0x4e4a6b9c], - [0x66b7b7e6, 0xb7d15173], - [0xe0ebeb8b, 0xeb0b60cb], - [0xc13c3cf0, 0x3cfdcc78], - [0xfd81813e, 0x817cbf1f], - [0x4094946a, 0x94d4fe35], - [0x1cf7f7fb, 0xf7eb0cf3], - [0x18b9b9de, 0xb9a1676f], - [0x8b13134c, 0x13985f26], - [0x512c2cb0, 0x2c7d9c58], - [0x05d3d36b, 0xd3d6b8bb], - [0x8ce7e7bb, 0xe76b5cd3], - [0x396e6ea5, 0x6e57cbdc], - [0xaac4c437, 0xc46ef395], - [0x1b03030c, 0x03180f06], - [0xdc565645, 0x568a13ac], - [0x5e44440d, 0x441a4988], - [0xa07f7fe1, 0x7fdf9efe], - [0x88a9a99e, 0xa921374f], - [0x672a2aa8, 0x2a4d8254], - [0x0abbbbd6, 0xbbb16d6b], - [0x87c1c123, 0xc146e29f], - [0xf1535351, 0x53a202a6], - [0x72dcdc57, 0xdcae8ba5], - [0x530b0b2c, 0x0b582716], - [0x019d9d4e, 0x9d9cd327], - [0x2b6c6cad, 0x6c47c1d8], - [0xa43131c4, 0x3195f562], - [0xf37474cd, 0x7487b9e8], - [0x15f6f6ff, 0xf6e309f1], - [0x4c464605, 0x460a438c], - [0xa5acac8a, 0xac092645], - [0xb589891e, 0x893c970f], - [0xb4141450, 0x14a04428], - [0xbae1e1a3, 0xe15b42df], - [0xa6161658, 0x16b04e2c], - [0xf73a3ae8, 0x3acdd274], - [0x066969b9, 0x696fd0d2], - [0x41090924, 0x09482d12], - [0xd77070dd, 0x70a7ade0], - [0x6fb6b6e2, 0xb6d95471], - [0x1ed0d067, 0xd0ceb7bd], - [0xd6eded93, 0xed3b7ec7], - [0xe2cccc17, 0xcc2edb85], - [0x68424215, 0x422a5784], - [0x2c98985a, 0x98b4c22d], - [0xeda4a4aa, 0xa4490e55], - [0x752828a0, 0x285d8850], - [0x865c5c6d, 0x5cda31b8], - [0x6bf8f8c7, 0xf8933fed], - [0xc2868622, 0x8644a411] -]); - -final _c2 = Register64List.from([ - [0x30d81818, 0x6018c078], - [0x46262323, 0x8c2305af], - [0x91b8c6c6, 0x3fc67ef9], - [0xcdfbe8e8, 0x87e8136f], - [0x13cb8787, 0x26874ca1], - [0x6d11b8b8, 0xdab8a962], - [0x02090101, 0x04010805], - [0x9e0d4f4f, 0x214f426e], - [0x6c9b3636, 0xd836adee], - [0x51ffa6a6, 0xa2a65904], - [0xb90cd2d2, 0x6fd2debd], - [0xf70ef5f5, 0xf3f5fb06], - [0xf2967979, 0xf979ef80], - [0xde306f6f, 0xa16f5fce], - [0x3f6d9191, 0x7e91fcef], - [0xa4f85252, 0x5552aa07], - [0xc0476060, 0x9d6027fd], - [0x6535bcbc, 0xcabc8976], - [0x2b379b9b, 0x569baccd], - [0x018a8e8e, 0x028e048c], - [0x5bd2a3a3, 0xb6a37115], - [0x186c0c0c, 0x300c603c], - [0xf6847b7b, 0xf17bff8a], - [0x6a803535, 0xd435b5e1], - [0x3af51d1d, 0x741de869], - [0xddb3e0e0, 0xa7e05347], - [0xb321d7d7, 0x7bd7f6ac], - [0x999cc2c2, 0x2fc25eed], - [0x5c432e2e, 0xb82e6d96], - [0x96294b4b, 0x314b627a], - [0xe15dfefe, 0xdffea321], - [0xaed55757, 0x41578216], - [0x2abd1515, 0x5415a841], - [0xeee87777, 0xc1779fb6], - [0x6e923737, 0xdc37a5eb], - [0xd79ee5e5, 0xb3e57b56], - [0x23139f9f, 0x469f8cd9], - [0xfd23f0f0, 0xe7f0d317], - [0x94204a4a, 0x354a6a7f], - [0xa944dada, 0x4fda9e95], - [0xb0a25858, 0x7d58fa25], - [0x8fcfc9c9, 0x03c906ca], - [0x527c2929, 0xa429558d], - [0x145a0a0a, 0x280a5022], - [0x7f50b1b1, 0xfeb1e14f], - [0x5dc9a0a0, 0xbaa0691a], - [0xd6146b6b, 0xb16b7fda], - [0x17d98585, 0x2e855cab], - [0x673cbdbd, 0xcebd8173], - [0xba8f5d5d, 0x695dd234], - [0x20901010, 0x40108050], - [0xf507f4f4, 0xf7f4f303], - [0x8bddcbcb, 0x0bcb16c0], - [0x7cd33e3e, 0xf83eedc6], - [0x0a2d0505, 0x14052811], - [0xce786767, 0x81671fe6], - [0xd597e4e4, 0xb7e47353], - [0x4e022727, 0x9c2725bb], - [0x82734141, 0x19413258], - [0x0ba78b8b, 0x168b2c9d], - [0x53f6a7a7, 0xa6a75101], - [0xfab27d7d, 0xe97dcf94], - [0x37499595, 0x6e95dcfb], - [0xad56d8d8, 0x47d88e9f], - [0xeb70fbfb, 0xcbfb8b30], - [0xc1cdeeee, 0x9fee2371], - [0xf8bb7c7c, 0xed7cc791], - [0xcc716666, 0x856617e3], - [0xa77bdddd, 0x53dda68e], - [0x2eaf1717, 0x5c17b84b], - [0x8e454747, 0x01470246], - [0x211a9e9e, 0x429e84dc], - [0x89d4caca, 0x0fca1ec5], - [0x5a582d2d, 0xb42d7599], - [0x632ebfbf, 0xc6bf9179], - [0x0e3f0707, 0x1c07381b], - [0x47acadad, 0x8ead0123], - [0xb4b05a5a, 0x755aea2f], - [0x1bef8383, 0x36836cb5], - [0x66b63333, 0xcc3385ff], - [0xc65c6363, 0x91633ff2], - [0x04120202, 0x0802100a], - [0x4993aaaa, 0x92aa3938], - [0xe2de7171, 0xd971afa8], - [0x8dc6c8c8, 0x07c80ecf], - [0x32d11919, 0x6419c87d], - [0x923b4949, 0x39497270], - [0xaf5fd9d9, 0x43d9869a], - [0xf931f2f2, 0xeff2c31d], - [0xdba8e3e3, 0xabe34b48], - [0xb6b95b5b, 0x715be22a], - [0x0dbc8888, 0x1a883492], - [0x293e9a9a, 0x529aa4c8], - [0x4c0b2626, 0x98262dbe], - [0x64bf3232, 0xc8328dfa], - [0x7d59b0b0, 0xfab0e94a], - [0xcff2e9e9, 0x83e91b6a], - [0x1e770f0f, 0x3c0f7833], - [0xb733d5d5, 0x73d5e6a6], - [0x1df48080, 0x3a8074ba], - [0x6127bebe, 0xc2be997c], - [0x87ebcdcd, 0x13cd26de], - [0x68893434, 0xd034bde4], - [0x90324848, 0x3d487a75], - [0xe354ffff, 0xdbffab24], - [0xf48d7a7a, 0xf57af78f], - [0x3d649090, 0x7a90f4ea], - [0xbe9d5f5f, 0x615fc23e], - [0x403d2020, 0x80201da0], - [0xd00f6868, 0xbd6867d5], - [0x34ca1a1a, 0x681ad072], - [0x41b7aeae, 0x82ae192c], - [0x757db4b4, 0xeab4c95e], - [0xa8ce5454, 0x4d549a19], - [0x3b7f9393, 0x7693ece5], - [0x442f2222, 0x88220daa], - [0xc8636464, 0x8d6407e9], - [0xff2af1f1, 0xe3f1db12], - [0xe6cc7373, 0xd173bfa2], - [0x24821212, 0x4812905a], - [0x807a4040, 0x1d403a5d], - [0x10480808, 0x20084028], - [0x9b95c3c3, 0x2bc356e8], - [0xc5dfecec, 0x97ec337b], - [0xab4ddbdb, 0x4bdb9690], - [0x5fc0a1a1, 0xbea1611f], - [0x07918d8d, 0x0e8d1c83], - [0x7ac83d3d, 0xf43df5c9], - [0x335b9797, 0x6697ccf1], - [0x00000000, 0x00000000], - [0x83f9cfcf, 0x1bcf36d4], - [0x566e2b2b, 0xac2b4587], - [0xece17676, 0xc57697b3], - [0x19e68282, 0x328264b0], - [0xb128d6d6, 0x7fd6fea9], - [0x36c31b1b, 0x6c1bd877], - [0x7774b5b5, 0xeeb5c15b], - [0x43beafaf, 0x86af1129], - [0xd41d6a6a, 0xb56a77df], - [0xa0ea5050, 0x5d50ba0d], - [0x8a574545, 0x0945124c], - [0xfb38f3f3, 0xebf3cb18], - [0x60ad3030, 0xc0309df0], - [0xc3c4efef, 0x9bef2b74], - [0x7eda3f3f, 0xfc3fe5c3], - [0xaac75555, 0x4955921c], - [0x59dba2a2, 0xb2a27910], - [0xc9e9eaea, 0x8fea0365], - [0xca6a6565, 0x89650fec], - [0x6903baba, 0xd2bab968], - [0x5e4a2f2f, 0xbc2f6593], - [0x9d8ec0c0, 0x27c04ee7], - [0xa160dede, 0x5fdebe81], - [0x38fc1c1c, 0x701ce06c], - [0xe746fdfd, 0xd3fdbb2e], - [0x9a1f4d4d, 0x294d5264], - [0x39769292, 0x7292e4e0], - [0xeafa7575, 0xc9758fbc], - [0x0c360606, 0x1806301e], - [0x09ae8a8a, 0x128a2498], - [0x794bb2b2, 0xf2b2f940], - [0xd185e6e6, 0xbfe66359], - [0x1c7e0e0e, 0x380e7036], - [0x3ee71f1f, 0x7c1ff863], - [0xc4556262, 0x956237f7], - [0xb53ad4d4, 0x77d4eea3], - [0x4d81a8a8, 0x9aa82932], - [0x31529696, 0x6296c4f4], - [0xef62f9f9, 0xc3f99b3a], - [0x97a3c5c5, 0x33c566f6], - [0x4a102525, 0x942535b1], - [0xb2ab5959, 0x7959f220], - [0x15d08484, 0x2a8454ae], - [0xe4c57272, 0xd572b7a7], - [0x72ec3939, 0xe439d5dd], - [0x98164c4c, 0x2d4c5a61], - [0xbc945e5e, 0x655eca3b], - [0xf09f7878, 0xfd78e785], - [0x70e53838, 0xe038ddd8], - [0x05988c8c, 0x0a8c1486], - [0xbf17d1d1, 0x63d1c6b2], - [0x57e4a5a5, 0xaea5410b], - [0xd9a1e2e2, 0xafe2434d], - [0xc24e6161, 0x99612ff8], - [0x7b42b3b3, 0xf6b3f145], - [0x42342121, 0x842115a5], - [0x25089c9c, 0x4a9c94d6], - [0x3cee1e1e, 0x781ef066], - [0x86614343, 0x11432252], - [0x93b1c7c7, 0x3bc776fc], - [0xe54ffcfc, 0xd7fcb32b], - [0x08240404, 0x10042014], - [0xa2e35151, 0x5951b208], - [0x2f259999, 0x5e99bcc7], - [0xda226d6d, 0xa96d4fc4], - [0x1a650d0d, 0x340d6839], - [0xe979fafa, 0xcffa8335], - [0xa369dfdf, 0x5bdfb684], - [0xfca97e7e, 0xe57ed79b], - [0x48192424, 0x90243db4], - [0x76fe3b3b, 0xec3bc5d7], - [0x4b9aabab, 0x96ab313d], - [0x81f0cece, 0x1fce3ed1], - [0x22991111, 0x44118855], - [0x03838f8f, 0x068f0c89], - [0x9c044e4e, 0x254e4a6b], - [0x7366b7b7, 0xe6b7d151], - [0xcbe0ebeb, 0x8beb0b60], - [0x78c13c3c, 0xf03cfdcc], - [0x1ffd8181, 0x3e817cbf], - [0x35409494, 0x6a94d4fe], - [0xf31cf7f7, 0xfbf7eb0c], - [0x6f18b9b9, 0xdeb9a167], - [0x268b1313, 0x4c13985f], - [0x58512c2c, 0xb02c7d9c], - [0xbb05d3d3, 0x6bd3d6b8], - [0xd38ce7e7, 0xbbe76b5c], - [0xdc396e6e, 0xa56e57cb], - [0x95aac4c4, 0x37c46ef3], - [0x061b0303, 0x0c03180f], - [0xacdc5656, 0x45568a13], - [0x885e4444, 0x0d441a49], - [0xfea07f7f, 0xe17fdf9e], - [0x4f88a9a9, 0x9ea92137], - [0x54672a2a, 0xa82a4d82], - [0x6b0abbbb, 0xd6bbb16d], - [0x9f87c1c1, 0x23c146e2], - [0xa6f15353, 0x5153a202], - [0xa572dcdc, 0x57dcae8b], - [0x16530b0b, 0x2c0b5827], - [0x27019d9d, 0x4e9d9cd3], - [0xd82b6c6c, 0xad6c47c1], - [0x62a43131, 0xc43195f5], - [0xe8f37474, 0xcd7487b9], - [0xf115f6f6, 0xfff6e309], - [0x8c4c4646, 0x05460a43], - [0x45a5acac, 0x8aac0926], - [0x0fb58989, 0x1e893c97], - [0x28b41414, 0x5014a044], - [0xdfbae1e1, 0xa3e15b42], - [0x2ca61616, 0x5816b04e], - [0x74f73a3a, 0xe83acdd2], - [0xd2066969, 0xb9696fd0], - [0x12410909, 0x2409482d], - [0xe0d77070, 0xdd70a7ad], - [0x716fb6b6, 0xe2b6d954], - [0xbd1ed0d0, 0x67d0ceb7], - [0xc7d6eded, 0x93ed3b7e], - [0x85e2cccc, 0x17cc2edb], - [0x84684242, 0x15422a57], - [0x2d2c9898, 0x5a98b4c2], - [0x55eda4a4, 0xaaa4490e], - [0x50752828, 0xa0285d88], - [0xb8865c5c, 0x6d5cda31], - [0xed6bf8f8, 0xc7f8933f], - [0x11c28686, 0x228644a4] -]); - -final _c3 = Register64List.from([ - [0x7830d818, 0x186018c0], - [0xaf462623, 0x238c2305], - [0xf991b8c6, 0xc63fc67e], - [0x6fcdfbe8, 0xe887e813], - [0xa113cb87, 0x8726874c], - [0x626d11b8, 0xb8dab8a9], - [0x05020901, 0x01040108], - [0x6e9e0d4f, 0x4f214f42], - [0xee6c9b36, 0x36d836ad], - [0x0451ffa6, 0xa6a2a659], - [0xbdb90cd2, 0xd26fd2de], - [0x06f70ef5, 0xf5f3f5fb], - [0x80f29679, 0x79f979ef], - [0xcede306f, 0x6fa16f5f], - [0xef3f6d91, 0x917e91fc], - [0x07a4f852, 0x525552aa], - [0xfdc04760, 0x609d6027], - [0x766535bc, 0xbccabc89], - [0xcd2b379b, 0x9b569bac], - [0x8c018a8e, 0x8e028e04], - [0x155bd2a3, 0xa3b6a371], - [0x3c186c0c, 0x0c300c60], - [0x8af6847b, 0x7bf17bff], - [0xe16a8035, 0x35d435b5], - [0x693af51d, 0x1d741de8], - [0x47ddb3e0, 0xe0a7e053], - [0xacb321d7, 0xd77bd7f6], - [0xed999cc2, 0xc22fc25e], - [0x965c432e, 0x2eb82e6d], - [0x7a96294b, 0x4b314b62], - [0x21e15dfe, 0xfedffea3], - [0x16aed557, 0x57415782], - [0x412abd15, 0x155415a8], - [0xb6eee877, 0x77c1779f], - [0xeb6e9237, 0x37dc37a5], - [0x56d79ee5, 0xe5b3e57b], - [0xd923139f, 0x9f469f8c], - [0x17fd23f0, 0xf0e7f0d3], - [0x7f94204a, 0x4a354a6a], - [0x95a944da, 0xda4fda9e], - [0x25b0a258, 0x587d58fa], - [0xca8fcfc9, 0xc903c906], - [0x8d527c29, 0x29a42955], - [0x22145a0a, 0x0a280a50], - [0x4f7f50b1, 0xb1feb1e1], - [0x1a5dc9a0, 0xa0baa069], - [0xdad6146b, 0x6bb16b7f], - [0xab17d985, 0x852e855c], - [0x73673cbd, 0xbdcebd81], - [0x34ba8f5d, 0x5d695dd2], - [0x50209010, 0x10401080], - [0x03f507f4, 0xf4f7f4f3], - [0xc08bddcb, 0xcb0bcb16], - [0xc67cd33e, 0x3ef83eed], - [0x110a2d05, 0x05140528], - [0xe6ce7867, 0x6781671f], - [0x53d597e4, 0xe4b7e473], - [0xbb4e0227, 0x279c2725], - [0x58827341, 0x41194132], - [0x9d0ba78b, 0x8b168b2c], - [0x0153f6a7, 0xa7a6a751], - [0x94fab27d, 0x7de97dcf], - [0xfb374995, 0x956e95dc], - [0x9fad56d8, 0xd847d88e], - [0x30eb70fb, 0xfbcbfb8b], - [0x71c1cdee, 0xee9fee23], - [0x91f8bb7c, 0x7ced7cc7], - [0xe3cc7166, 0x66856617], - [0x8ea77bdd, 0xdd53dda6], - [0x4b2eaf17, 0x175c17b8], - [0x468e4547, 0x47014702], - [0xdc211a9e, 0x9e429e84], - [0xc589d4ca, 0xca0fca1e], - [0x995a582d, 0x2db42d75], - [0x79632ebf, 0xbfc6bf91], - [0x1b0e3f07, 0x071c0738], - [0x2347acad, 0xad8ead01], - [0x2fb4b05a, 0x5a755aea], - [0xb51bef83, 0x8336836c], - [0xff66b633, 0x33cc3385], - [0xf2c65c63, 0x6391633f], - [0x0a041202, 0x02080210], - [0x384993aa, 0xaa92aa39], - [0xa8e2de71, 0x71d971af], - [0xcf8dc6c8, 0xc807c80e], - [0x7d32d119, 0x196419c8], - [0x70923b49, 0x49394972], - [0x9aaf5fd9, 0xd943d986], - [0x1df931f2, 0xf2eff2c3], - [0x48dba8e3, 0xe3abe34b], - [0x2ab6b95b, 0x5b715be2], - [0x920dbc88, 0x881a8834], - [0xc8293e9a, 0x9a529aa4], - [0xbe4c0b26, 0x2698262d], - [0xfa64bf32, 0x32c8328d], - [0x4a7d59b0, 0xb0fab0e9], - [0x6acff2e9, 0xe983e91b], - [0x331e770f, 0x0f3c0f78], - [0xa6b733d5, 0xd573d5e6], - [0xba1df480, 0x803a8074], - [0x7c6127be, 0xbec2be99], - [0xde87ebcd, 0xcd13cd26], - [0xe4688934, 0x34d034bd], - [0x75903248, 0x483d487a], - [0x24e354ff, 0xffdbffab], - [0x8ff48d7a, 0x7af57af7], - [0xea3d6490, 0x907a90f4], - [0x3ebe9d5f, 0x5f615fc2], - [0xa0403d20, 0x2080201d], - [0xd5d00f68, 0x68bd6867], - [0x7234ca1a, 0x1a681ad0], - [0x2c41b7ae, 0xae82ae19], - [0x5e757db4, 0xb4eab4c9], - [0x19a8ce54, 0x544d549a], - [0xe53b7f93, 0x937693ec], - [0xaa442f22, 0x2288220d], - [0xe9c86364, 0x648d6407], - [0x12ff2af1, 0xf1e3f1db], - [0xa2e6cc73, 0x73d173bf], - [0x5a248212, 0x12481290], - [0x5d807a40, 0x401d403a], - [0x28104808, 0x08200840], - [0xe89b95c3, 0xc32bc356], - [0x7bc5dfec, 0xec97ec33], - [0x90ab4ddb, 0xdb4bdb96], - [0x1f5fc0a1, 0xa1bea161], - [0x8307918d, 0x8d0e8d1c], - [0xc97ac83d, 0x3df43df5], - [0xf1335b97, 0x976697cc], - [0x00000000, 0x00000000], - [0xd483f9cf, 0xcf1bcf36], - [0x87566e2b, 0x2bac2b45], - [0xb3ece176, 0x76c57697], - [0xb019e682, 0x82328264], - [0xa9b128d6, 0xd67fd6fe], - [0x7736c31b, 0x1b6c1bd8], - [0x5b7774b5, 0xb5eeb5c1], - [0x2943beaf, 0xaf86af11], - [0xdfd41d6a, 0x6ab56a77], - [0x0da0ea50, 0x505d50ba], - [0x4c8a5745, 0x45094512], - [0x18fb38f3, 0xf3ebf3cb], - [0xf060ad30, 0x30c0309d], - [0x74c3c4ef, 0xef9bef2b], - [0xc37eda3f, 0x3ffc3fe5], - [0x1caac755, 0x55495592], - [0x1059dba2, 0xa2b2a279], - [0x65c9e9ea, 0xea8fea03], - [0xecca6a65, 0x6589650f], - [0x686903ba, 0xbad2bab9], - [0x935e4a2f, 0x2fbc2f65], - [0xe79d8ec0, 0xc027c04e], - [0x81a160de, 0xde5fdebe], - [0x6c38fc1c, 0x1c701ce0], - [0x2ee746fd, 0xfdd3fdbb], - [0x649a1f4d, 0x4d294d52], - [0xe0397692, 0x927292e4], - [0xbceafa75, 0x75c9758f], - [0x1e0c3606, 0x06180630], - [0x9809ae8a, 0x8a128a24], - [0x40794bb2, 0xb2f2b2f9], - [0x59d185e6, 0xe6bfe663], - [0x361c7e0e, 0x0e380e70], - [0x633ee71f, 0x1f7c1ff8], - [0xf7c45562, 0x62956237], - [0xa3b53ad4, 0xd477d4ee], - [0x324d81a8, 0xa89aa829], - [0xf4315296, 0x966296c4], - [0x3aef62f9, 0xf9c3f99b], - [0xf697a3c5, 0xc533c566], - [0xb14a1025, 0x25942535], - [0x20b2ab59, 0x597959f2], - [0xae15d084, 0x842a8454], - [0xa7e4c572, 0x72d572b7], - [0xdd72ec39, 0x39e439d5], - [0x6198164c, 0x4c2d4c5a], - [0x3bbc945e, 0x5e655eca], - [0x85f09f78, 0x78fd78e7], - [0xd870e538, 0x38e038dd], - [0x8605988c, 0x8c0a8c14], - [0xb2bf17d1, 0xd163d1c6], - [0x0b57e4a5, 0xa5aea541], - [0x4dd9a1e2, 0xe2afe243], - [0xf8c24e61, 0x6199612f], - [0x457b42b3, 0xb3f6b3f1], - [0xa5423421, 0x21842115], - [0xd625089c, 0x9c4a9c94], - [0x663cee1e, 0x1e781ef0], - [0x52866143, 0x43114322], - [0xfc93b1c7, 0xc73bc776], - [0x2be54ffc, 0xfcd7fcb3], - [0x14082404, 0x04100420], - [0x08a2e351, 0x515951b2], - [0xc72f2599, 0x995e99bc], - [0xc4da226d, 0x6da96d4f], - [0x391a650d, 0x0d340d68], - [0x35e979fa, 0xfacffa83], - [0x84a369df, 0xdf5bdfb6], - [0x9bfca97e, 0x7ee57ed7], - [0xb4481924, 0x2490243d], - [0xd776fe3b, 0x3bec3bc5], - [0x3d4b9aab, 0xab96ab31], - [0xd181f0ce, 0xce1fce3e], - [0x55229911, 0x11441188], - [0x8903838f, 0x8f068f0c], - [0x6b9c044e, 0x4e254e4a], - [0x517366b7, 0xb7e6b7d1], - [0x60cbe0eb, 0xeb8beb0b], - [0xcc78c13c, 0x3cf03cfd], - [0xbf1ffd81, 0x813e817c], - [0xfe354094, 0x946a94d4], - [0x0cf31cf7, 0xf7fbf7eb], - [0x676f18b9, 0xb9deb9a1], - [0x5f268b13, 0x134c1398], - [0x9c58512c, 0x2cb02c7d], - [0xb8bb05d3, 0xd36bd3d6], - [0x5cd38ce7, 0xe7bbe76b], - [0xcbdc396e, 0x6ea56e57], - [0xf395aac4, 0xc437c46e], - [0x0f061b03, 0x030c0318], - [0x13acdc56, 0x5645568a], - [0x49885e44, 0x440d441a], - [0x9efea07f, 0x7fe17fdf], - [0x374f88a9, 0xa99ea921], - [0x8254672a, 0x2aa82a4d], - [0x6d6b0abb, 0xbbd6bbb1], - [0xe29f87c1, 0xc123c146], - [0x02a6f153, 0x535153a2], - [0x8ba572dc, 0xdc57dcae], - [0x2716530b, 0x0b2c0b58], - [0xd327019d, 0x9d4e9d9c], - [0xc1d82b6c, 0x6cad6c47], - [0xf562a431, 0x31c43195], - [0xb9e8f374, 0x74cd7487], - [0x09f115f6, 0xf6fff6e3], - [0x438c4c46, 0x4605460a], - [0x2645a5ac, 0xac8aac09], - [0x970fb589, 0x891e893c], - [0x4428b414, 0x145014a0], - [0x42dfbae1, 0xe1a3e15b], - [0x4e2ca616, 0x165816b0], - [0xd274f73a, 0x3ae83acd], - [0xd0d20669, 0x69b9696f], - [0x2d124109, 0x09240948], - [0xade0d770, 0x70dd70a7], - [0x54716fb6, 0xb6e2b6d9], - [0xb7bd1ed0, 0xd067d0ce], - [0x7ec7d6ed, 0xed93ed3b], - [0xdb85e2cc, 0xcc17cc2e], - [0x57846842, 0x4215422a], - [0xc22d2c98, 0x985a98b4], - [0x0e55eda4, 0xa4aaa449], - [0x88507528, 0x28a0285d], - [0x31b8865c, 0x5c6d5cda], - [0x3fed6bf8, 0xf8c7f893], - [0xa411c286, 0x86228644] -]); - -final _c4 = Register64List.from([ - [0xc07830d8, 0x18186018], - [0x05af4626, 0x23238c23], - [0x7ef991b8, 0xc6c63fc6], - [0x136fcdfb, 0xe8e887e8], - [0x4ca113cb, 0x87872687], - [0xa9626d11, 0xb8b8dab8], - [0x08050209, 0x01010401], - [0x426e9e0d, 0x4f4f214f], - [0xadee6c9b, 0x3636d836], - [0x590451ff, 0xa6a6a2a6], - [0xdebdb90c, 0xd2d26fd2], - [0xfb06f70e, 0xf5f5f3f5], - [0xef80f296, 0x7979f979], - [0x5fcede30, 0x6f6fa16f], - [0xfcef3f6d, 0x91917e91], - [0xaa07a4f8, 0x52525552], - [0x27fdc047, 0x60609d60], - [0x89766535, 0xbcbccabc], - [0xaccd2b37, 0x9b9b569b], - [0x048c018a, 0x8e8e028e], - [0x71155bd2, 0xa3a3b6a3], - [0x603c186c, 0x0c0c300c], - [0xff8af684, 0x7b7bf17b], - [0xb5e16a80, 0x3535d435], - [0xe8693af5, 0x1d1d741d], - [0x5347ddb3, 0xe0e0a7e0], - [0xf6acb321, 0xd7d77bd7], - [0x5eed999c, 0xc2c22fc2], - [0x6d965c43, 0x2e2eb82e], - [0x627a9629, 0x4b4b314b], - [0xa321e15d, 0xfefedffe], - [0x8216aed5, 0x57574157], - [0xa8412abd, 0x15155415], - [0x9fb6eee8, 0x7777c177], - [0xa5eb6e92, 0x3737dc37], - [0x7b56d79e, 0xe5e5b3e5], - [0x8cd92313, 0x9f9f469f], - [0xd317fd23, 0xf0f0e7f0], - [0x6a7f9420, 0x4a4a354a], - [0x9e95a944, 0xdada4fda], - [0xfa25b0a2, 0x58587d58], - [0x06ca8fcf, 0xc9c903c9], - [0x558d527c, 0x2929a429], - [0x5022145a, 0x0a0a280a], - [0xe14f7f50, 0xb1b1feb1], - [0x691a5dc9, 0xa0a0baa0], - [0x7fdad614, 0x6b6bb16b], - [0x5cab17d9, 0x85852e85], - [0x8173673c, 0xbdbdcebd], - [0xd234ba8f, 0x5d5d695d], - [0x80502090, 0x10104010], - [0xf303f507, 0xf4f4f7f4], - [0x16c08bdd, 0xcbcb0bcb], - [0xedc67cd3, 0x3e3ef83e], - [0x28110a2d, 0x05051405], - [0x1fe6ce78, 0x67678167], - [0x7353d597, 0xe4e4b7e4], - [0x25bb4e02, 0x27279c27], - [0x32588273, 0x41411941], - [0x2c9d0ba7, 0x8b8b168b], - [0x510153f6, 0xa7a7a6a7], - [0xcf94fab2, 0x7d7de97d], - [0xdcfb3749, 0x95956e95], - [0x8e9fad56, 0xd8d847d8], - [0x8b30eb70, 0xfbfbcbfb], - [0x2371c1cd, 0xeeee9fee], - [0xc791f8bb, 0x7c7ced7c], - [0x17e3cc71, 0x66668566], - [0xa68ea77b, 0xdddd53dd], - [0xb84b2eaf, 0x17175c17], - [0x02468e45, 0x47470147], - [0x84dc211a, 0x9e9e429e], - [0x1ec589d4, 0xcaca0fca], - [0x75995a58, 0x2d2db42d], - [0x9179632e, 0xbfbfc6bf], - [0x381b0e3f, 0x07071c07], - [0x012347ac, 0xadad8ead], - [0xea2fb4b0, 0x5a5a755a], - [0x6cb51bef, 0x83833683], - [0x85ff66b6, 0x3333cc33], - [0x3ff2c65c, 0x63639163], - [0x100a0412, 0x02020802], - [0x39384993, 0xaaaa92aa], - [0xafa8e2de, 0x7171d971], - [0x0ecf8dc6, 0xc8c807c8], - [0xc87d32d1, 0x19196419], - [0x7270923b, 0x49493949], - [0x869aaf5f, 0xd9d943d9], - [0xc31df931, 0xf2f2eff2], - [0x4b48dba8, 0xe3e3abe3], - [0xe22ab6b9, 0x5b5b715b], - [0x34920dbc, 0x88881a88], - [0xa4c8293e, 0x9a9a529a], - [0x2dbe4c0b, 0x26269826], - [0x8dfa64bf, 0x3232c832], - [0xe94a7d59, 0xb0b0fab0], - [0x1b6acff2, 0xe9e983e9], - [0x78331e77, 0x0f0f3c0f], - [0xe6a6b733, 0xd5d573d5], - [0x74ba1df4, 0x80803a80], - [0x997c6127, 0xbebec2be], - [0x26de87eb, 0xcdcd13cd], - [0xbde46889, 0x3434d034], - [0x7a759032, 0x48483d48], - [0xab24e354, 0xffffdbff], - [0xf78ff48d, 0x7a7af57a], - [0xf4ea3d64, 0x90907a90], - [0xc23ebe9d, 0x5f5f615f], - [0x1da0403d, 0x20208020], - [0x67d5d00f, 0x6868bd68], - [0xd07234ca, 0x1a1a681a], - [0x192c41b7, 0xaeae82ae], - [0xc95e757d, 0xb4b4eab4], - [0x9a19a8ce, 0x54544d54], - [0xece53b7f, 0x93937693], - [0x0daa442f, 0x22228822], - [0x07e9c863, 0x64648d64], - [0xdb12ff2a, 0xf1f1e3f1], - [0xbfa2e6cc, 0x7373d173], - [0x905a2482, 0x12124812], - [0x3a5d807a, 0x40401d40], - [0x40281048, 0x08082008], - [0x56e89b95, 0xc3c32bc3], - [0x337bc5df, 0xecec97ec], - [0x9690ab4d, 0xdbdb4bdb], - [0x611f5fc0, 0xa1a1bea1], - [0x1c830791, 0x8d8d0e8d], - [0xf5c97ac8, 0x3d3df43d], - [0xccf1335b, 0x97976697], - [0x00000000, 0x00000000], - [0x36d483f9, 0xcfcf1bcf], - [0x4587566e, 0x2b2bac2b], - [0x97b3ece1, 0x7676c576], - [0x64b019e6, 0x82823282], - [0xfea9b128, 0xd6d67fd6], - [0xd87736c3, 0x1b1b6c1b], - [0xc15b7774, 0xb5b5eeb5], - [0x112943be, 0xafaf86af], - [0x77dfd41d, 0x6a6ab56a], - [0xba0da0ea, 0x50505d50], - [0x124c8a57, 0x45450945], - [0xcb18fb38, 0xf3f3ebf3], - [0x9df060ad, 0x3030c030], - [0x2b74c3c4, 0xefef9bef], - [0xe5c37eda, 0x3f3ffc3f], - [0x921caac7, 0x55554955], - [0x791059db, 0xa2a2b2a2], - [0x0365c9e9, 0xeaea8fea], - [0x0fecca6a, 0x65658965], - [0xb9686903, 0xbabad2ba], - [0x65935e4a, 0x2f2fbc2f], - [0x4ee79d8e, 0xc0c027c0], - [0xbe81a160, 0xdede5fde], - [0xe06c38fc, 0x1c1c701c], - [0xbb2ee746, 0xfdfdd3fd], - [0x52649a1f, 0x4d4d294d], - [0xe4e03976, 0x92927292], - [0x8fbceafa, 0x7575c975], - [0x301e0c36, 0x06061806], - [0x249809ae, 0x8a8a128a], - [0xf940794b, 0xb2b2f2b2], - [0x6359d185, 0xe6e6bfe6], - [0x70361c7e, 0x0e0e380e], - [0xf8633ee7, 0x1f1f7c1f], - [0x37f7c455, 0x62629562], - [0xeea3b53a, 0xd4d477d4], - [0x29324d81, 0xa8a89aa8], - [0xc4f43152, 0x96966296], - [0x9b3aef62, 0xf9f9c3f9], - [0x66f697a3, 0xc5c533c5], - [0x35b14a10, 0x25259425], - [0xf220b2ab, 0x59597959], - [0x54ae15d0, 0x84842a84], - [0xb7a7e4c5, 0x7272d572], - [0xd5dd72ec, 0x3939e439], - [0x5a619816, 0x4c4c2d4c], - [0xca3bbc94, 0x5e5e655e], - [0xe785f09f, 0x7878fd78], - [0xddd870e5, 0x3838e038], - [0x14860598, 0x8c8c0a8c], - [0xc6b2bf17, 0xd1d163d1], - [0x410b57e4, 0xa5a5aea5], - [0x434dd9a1, 0xe2e2afe2], - [0x2ff8c24e, 0x61619961], - [0xf1457b42, 0xb3b3f6b3], - [0x15a54234, 0x21218421], - [0x94d62508, 0x9c9c4a9c], - [0xf0663cee, 0x1e1e781e], - [0x22528661, 0x43431143], - [0x76fc93b1, 0xc7c73bc7], - [0xb32be54f, 0xfcfcd7fc], - [0x20140824, 0x04041004], - [0xb208a2e3, 0x51515951], - [0xbcc72f25, 0x99995e99], - [0x4fc4da22, 0x6d6da96d], - [0x68391a65, 0x0d0d340d], - [0x8335e979, 0xfafacffa], - [0xb684a369, 0xdfdf5bdf], - [0xd79bfca9, 0x7e7ee57e], - [0x3db44819, 0x24249024], - [0xc5d776fe, 0x3b3bec3b], - [0x313d4b9a, 0xabab96ab], - [0x3ed181f0, 0xcece1fce], - [0x88552299, 0x11114411], - [0x0c890383, 0x8f8f068f], - [0x4a6b9c04, 0x4e4e254e], - [0xd1517366, 0xb7b7e6b7], - [0x0b60cbe0, 0xebeb8beb], - [0xfdcc78c1, 0x3c3cf03c], - [0x7cbf1ffd, 0x81813e81], - [0xd4fe3540, 0x94946a94], - [0xeb0cf31c, 0xf7f7fbf7], - [0xa1676f18, 0xb9b9deb9], - [0x985f268b, 0x13134c13], - [0x7d9c5851, 0x2c2cb02c], - [0xd6b8bb05, 0xd3d36bd3], - [0x6b5cd38c, 0xe7e7bbe7], - [0x57cbdc39, 0x6e6ea56e], - [0x6ef395aa, 0xc4c437c4], - [0x180f061b, 0x03030c03], - [0x8a13acdc, 0x56564556], - [0x1a49885e, 0x44440d44], - [0xdf9efea0, 0x7f7fe17f], - [0x21374f88, 0xa9a99ea9], - [0x4d825467, 0x2a2aa82a], - [0xb16d6b0a, 0xbbbbd6bb], - [0x46e29f87, 0xc1c123c1], - [0xa202a6f1, 0x53535153], - [0xae8ba572, 0xdcdc57dc], - [0x58271653, 0x0b0b2c0b], - [0x9cd32701, 0x9d9d4e9d], - [0x47c1d82b, 0x6c6cad6c], - [0x95f562a4, 0x3131c431], - [0x87b9e8f3, 0x7474cd74], - [0xe309f115, 0xf6f6fff6], - [0x0a438c4c, 0x46460546], - [0x092645a5, 0xacac8aac], - [0x3c970fb5, 0x89891e89], - [0xa04428b4, 0x14145014], - [0x5b42dfba, 0xe1e1a3e1], - [0xb04e2ca6, 0x16165816], - [0xcdd274f7, 0x3a3ae83a], - [0x6fd0d206, 0x6969b969], - [0x482d1241, 0x09092409], - [0xa7ade0d7, 0x7070dd70], - [0xd954716f, 0xb6b6e2b6], - [0xceb7bd1e, 0xd0d067d0], - [0x3b7ec7d6, 0xeded93ed], - [0x2edb85e2, 0xcccc17cc], - [0x2a578468, 0x42421542], - [0xb4c22d2c, 0x98985a98], - [0x490e55ed, 0xa4a4aaa4], - [0x5d885075, 0x2828a028], - [0xda31b886, 0x5c5c6d5c], - [0x933fed6b, 0xf8f8c7f8], - [0x44a411c2, 0x86862286] -]); - -final _c5 = Register64List.from([ - [0x18c07830, 0xd8181860], - [0x2305af46, 0x2623238c], - [0xc67ef991, 0xb8c6c63f], - [0xe8136fcd, 0xfbe8e887], - [0x874ca113, 0xcb878726], - [0xb8a9626d, 0x11b8b8da], - [0x01080502, 0x09010104], - [0x4f426e9e, 0x0d4f4f21], - [0x36adee6c, 0x9b3636d8], - [0xa6590451, 0xffa6a6a2], - [0xd2debdb9, 0x0cd2d26f], - [0xf5fb06f7, 0x0ef5f5f3], - [0x79ef80f2, 0x967979f9], - [0x6f5fcede, 0x306f6fa1], - [0x91fcef3f, 0x6d91917e], - [0x52aa07a4, 0xf8525255], - [0x6027fdc0, 0x4760609d], - [0xbc897665, 0x35bcbcca], - [0x9baccd2b, 0x379b9b56], - [0x8e048c01, 0x8a8e8e02], - [0xa371155b, 0xd2a3a3b6], - [0x0c603c18, 0x6c0c0c30], - [0x7bff8af6, 0x847b7bf1], - [0x35b5e16a, 0x803535d4], - [0x1de8693a, 0xf51d1d74], - [0xe05347dd, 0xb3e0e0a7], - [0xd7f6acb3, 0x21d7d77b], - [0xc25eed99, 0x9cc2c22f], - [0x2e6d965c, 0x432e2eb8], - [0x4b627a96, 0x294b4b31], - [0xfea321e1, 0x5dfefedf], - [0x578216ae, 0xd5575741], - [0x15a8412a, 0xbd151554], - [0x779fb6ee, 0xe87777c1], - [0x37a5eb6e, 0x923737dc], - [0xe57b56d7, 0x9ee5e5b3], - [0x9f8cd923, 0x139f9f46], - [0xf0d317fd, 0x23f0f0e7], - [0x4a6a7f94, 0x204a4a35], - [0xda9e95a9, 0x44dada4f], - [0x58fa25b0, 0xa258587d], - [0xc906ca8f, 0xcfc9c903], - [0x29558d52, 0x7c2929a4], - [0x0a502214, 0x5a0a0a28], - [0xb1e14f7f, 0x50b1b1fe], - [0xa0691a5d, 0xc9a0a0ba], - [0x6b7fdad6, 0x146b6bb1], - [0x855cab17, 0xd985852e], - [0xbd817367, 0x3cbdbdce], - [0x5dd234ba, 0x8f5d5d69], - [0x10805020, 0x90101040], - [0xf4f303f5, 0x07f4f4f7], - [0xcb16c08b, 0xddcbcb0b], - [0x3eedc67c, 0xd33e3ef8], - [0x0528110a, 0x2d050514], - [0x671fe6ce, 0x78676781], - [0xe47353d5, 0x97e4e4b7], - [0x2725bb4e, 0x0227279c], - [0x41325882, 0x73414119], - [0x8b2c9d0b, 0xa78b8b16], - [0xa7510153, 0xf6a7a7a6], - [0x7dcf94fa, 0xb27d7de9], - [0x95dcfb37, 0x4995956e], - [0xd88e9fad, 0x56d8d847], - [0xfb8b30eb, 0x70fbfbcb], - [0xee2371c1, 0xcdeeee9f], - [0x7cc791f8, 0xbb7c7ced], - [0x6617e3cc, 0x71666685], - [0xdda68ea7, 0x7bdddd53], - [0x17b84b2e, 0xaf17175c], - [0x4702468e, 0x45474701], - [0x9e84dc21, 0x1a9e9e42], - [0xca1ec589, 0xd4caca0f], - [0x2d75995a, 0x582d2db4], - [0xbf917963, 0x2ebfbfc6], - [0x07381b0e, 0x3f07071c], - [0xad012347, 0xacadad8e], - [0x5aea2fb4, 0xb05a5a75], - [0x836cb51b, 0xef838336], - [0x3385ff66, 0xb63333cc], - [0x633ff2c6, 0x5c636391], - [0x02100a04, 0x12020208], - [0xaa393849, 0x93aaaa92], - [0x71afa8e2, 0xde7171d9], - [0xc80ecf8d, 0xc6c8c807], - [0x19c87d32, 0xd1191964], - [0x49727092, 0x3b494939], - [0xd9869aaf, 0x5fd9d943], - [0xf2c31df9, 0x31f2f2ef], - [0xe34b48db, 0xa8e3e3ab], - [0x5be22ab6, 0xb95b5b71], - [0x8834920d, 0xbc88881a], - [0x9aa4c829, 0x3e9a9a52], - [0x262dbe4c, 0x0b262698], - [0x328dfa64, 0xbf3232c8], - [0xb0e94a7d, 0x59b0b0fa], - [0xe91b6acf, 0xf2e9e983], - [0x0f78331e, 0x770f0f3c], - [0xd5e6a6b7, 0x33d5d573], - [0x8074ba1d, 0xf480803a], - [0xbe997c61, 0x27bebec2], - [0xcd26de87, 0xebcdcd13], - [0x34bde468, 0x893434d0], - [0x487a7590, 0x3248483d], - [0xffab24e3, 0x54ffffdb], - [0x7af78ff4, 0x8d7a7af5], - [0x90f4ea3d, 0x6490907a], - [0x5fc23ebe, 0x9d5f5f61], - [0x201da040, 0x3d202080], - [0x6867d5d0, 0x0f6868bd], - [0x1ad07234, 0xca1a1a68], - [0xae192c41, 0xb7aeae82], - [0xb4c95e75, 0x7db4b4ea], - [0x549a19a8, 0xce54544d], - [0x93ece53b, 0x7f939376], - [0x220daa44, 0x2f222288], - [0x6407e9c8, 0x6364648d], - [0xf1db12ff, 0x2af1f1e3], - [0x73bfa2e6, 0xcc7373d1], - [0x12905a24, 0x82121248], - [0x403a5d80, 0x7a40401d], - [0x08402810, 0x48080820], - [0xc356e89b, 0x95c3c32b], - [0xec337bc5, 0xdfecec97], - [0xdb9690ab, 0x4ddbdb4b], - [0xa1611f5f, 0xc0a1a1be], - [0x8d1c8307, 0x918d8d0e], - [0x3df5c97a, 0xc83d3df4], - [0x97ccf133, 0x5b979766], - [0x00000000, 0x00000000], - [0xcf36d483, 0xf9cfcf1b], - [0x2b458756, 0x6e2b2bac], - [0x7697b3ec, 0xe17676c5], - [0x8264b019, 0xe6828232], - [0xd6fea9b1, 0x28d6d67f], - [0x1bd87736, 0xc31b1b6c], - [0xb5c15b77, 0x74b5b5ee], - [0xaf112943, 0xbeafaf86], - [0x6a77dfd4, 0x1d6a6ab5], - [0x50ba0da0, 0xea50505d], - [0x45124c8a, 0x57454509], - [0xf3cb18fb, 0x38f3f3eb], - [0x309df060, 0xad3030c0], - [0xef2b74c3, 0xc4efef9b], - [0x3fe5c37e, 0xda3f3ffc], - [0x55921caa, 0xc7555549], - [0xa2791059, 0xdba2a2b2], - [0xea0365c9, 0xe9eaea8f], - [0x650fecca, 0x6a656589], - [0xbab96869, 0x03babad2], - [0x2f65935e, 0x4a2f2fbc], - [0xc04ee79d, 0x8ec0c027], - [0xdebe81a1, 0x60dede5f], - [0x1ce06c38, 0xfc1c1c70], - [0xfdbb2ee7, 0x46fdfdd3], - [0x4d52649a, 0x1f4d4d29], - [0x92e4e039, 0x76929272], - [0x758fbcea, 0xfa7575c9], - [0x06301e0c, 0x36060618], - [0x8a249809, 0xae8a8a12], - [0xb2f94079, 0x4bb2b2f2], - [0xe66359d1, 0x85e6e6bf], - [0x0e70361c, 0x7e0e0e38], - [0x1ff8633e, 0xe71f1f7c], - [0x6237f7c4, 0x55626295], - [0xd4eea3b5, 0x3ad4d477], - [0xa829324d, 0x81a8a89a], - [0x96c4f431, 0x52969662], - [0xf99b3aef, 0x62f9f9c3], - [0xc566f697, 0xa3c5c533], - [0x2535b14a, 0x10252594], - [0x59f220b2, 0xab595979], - [0x8454ae15, 0xd084842a], - [0x72b7a7e4, 0xc57272d5], - [0x39d5dd72, 0xec3939e4], - [0x4c5a6198, 0x164c4c2d], - [0x5eca3bbc, 0x945e5e65], - [0x78e785f0, 0x9f7878fd], - [0x38ddd870, 0xe53838e0], - [0x8c148605, 0x988c8c0a], - [0xd1c6b2bf, 0x17d1d163], - [0xa5410b57, 0xe4a5a5ae], - [0xe2434dd9, 0xa1e2e2af], - [0x612ff8c2, 0x4e616199], - [0xb3f1457b, 0x42b3b3f6], - [0x2115a542, 0x34212184], - [0x9c94d625, 0x089c9c4a], - [0x1ef0663c, 0xee1e1e78], - [0x43225286, 0x61434311], - [0xc776fc93, 0xb1c7c73b], - [0xfcb32be5, 0x4ffcfcd7], - [0x04201408, 0x24040410], - [0x51b208a2, 0xe3515159], - [0x99bcc72f, 0x2599995e], - [0x6d4fc4da, 0x226d6da9], - [0x0d68391a, 0x650d0d34], - [0xfa8335e9, 0x79fafacf], - [0xdfb684a3, 0x69dfdf5b], - [0x7ed79bfc, 0xa97e7ee5], - [0x243db448, 0x19242490], - [0x3bc5d776, 0xfe3b3bec], - [0xab313d4b, 0x9aabab96], - [0xce3ed181, 0xf0cece1f], - [0x11885522, 0x99111144], - [0x8f0c8903, 0x838f8f06], - [0x4e4a6b9c, 0x044e4e25], - [0xb7d15173, 0x66b7b7e6], - [0xeb0b60cb, 0xe0ebeb8b], - [0x3cfdcc78, 0xc13c3cf0], - [0x817cbf1f, 0xfd81813e], - [0x94d4fe35, 0x4094946a], - [0xf7eb0cf3, 0x1cf7f7fb], - [0xb9a1676f, 0x18b9b9de], - [0x13985f26, 0x8b13134c], - [0x2c7d9c58, 0x512c2cb0], - [0xd3d6b8bb, 0x05d3d36b], - [0xe76b5cd3, 0x8ce7e7bb], - [0x6e57cbdc, 0x396e6ea5], - [0xc46ef395, 0xaac4c437], - [0x03180f06, 0x1b03030c], - [0x568a13ac, 0xdc565645], - [0x441a4988, 0x5e44440d], - [0x7fdf9efe, 0xa07f7fe1], - [0xa921374f, 0x88a9a99e], - [0x2a4d8254, 0x672a2aa8], - [0xbbb16d6b, 0x0abbbbd6], - [0xc146e29f, 0x87c1c123], - [0x53a202a6, 0xf1535351], - [0xdcae8ba5, 0x72dcdc57], - [0x0b582716, 0x530b0b2c], - [0x9d9cd327, 0x019d9d4e], - [0x6c47c1d8, 0x2b6c6cad], - [0x3195f562, 0xa43131c4], - [0x7487b9e8, 0xf37474cd], - [0xf6e309f1, 0x15f6f6ff], - [0x460a438c, 0x4c464605], - [0xac092645, 0xa5acac8a], - [0x893c970f, 0xb589891e], - [0x14a04428, 0xb4141450], - [0xe15b42df, 0xbae1e1a3], - [0x16b04e2c, 0xa6161658], - [0x3acdd274, 0xf73a3ae8], - [0x696fd0d2, 0x066969b9], - [0x09482d12, 0x41090924], - [0x70a7ade0, 0xd77070dd], - [0xb6d95471, 0x6fb6b6e2], - [0xd0ceb7bd, 0x1ed0d067], - [0xed3b7ec7, 0xd6eded93], - [0xcc2edb85, 0xe2cccc17], - [0x422a5784, 0x68424215], - [0x98b4c22d, 0x2c98985a], - [0xa4490e55, 0xeda4a4aa], - [0x285d8850, 0x752828a0], - [0x5cda31b8, 0x865c5c6d], - [0xf8933fed, 0x6bf8f8c7], - [0x8644a411, 0xc2868622] -]); - -final _c6 = Register64List.from([ - [0x6018c078, 0x30d81818], - [0x8c2305af, 0x46262323], - [0x3fc67ef9, 0x91b8c6c6], - [0x87e8136f, 0xcdfbe8e8], - [0x26874ca1, 0x13cb8787], - [0xdab8a962, 0x6d11b8b8], - [0x04010805, 0x02090101], - [0x214f426e, 0x9e0d4f4f], - [0xd836adee, 0x6c9b3636], - [0xa2a65904, 0x51ffa6a6], - [0x6fd2debd, 0xb90cd2d2], - [0xf3f5fb06, 0xf70ef5f5], - [0xf979ef80, 0xf2967979], - [0xa16f5fce, 0xde306f6f], - [0x7e91fcef, 0x3f6d9191], - [0x5552aa07, 0xa4f85252], - [0x9d6027fd, 0xc0476060], - [0xcabc8976, 0x6535bcbc], - [0x569baccd, 0x2b379b9b], - [0x028e048c, 0x018a8e8e], - [0xb6a37115, 0x5bd2a3a3], - [0x300c603c, 0x186c0c0c], - [0xf17bff8a, 0xf6847b7b], - [0xd435b5e1, 0x6a803535], - [0x741de869, 0x3af51d1d], - [0xa7e05347, 0xddb3e0e0], - [0x7bd7f6ac, 0xb321d7d7], - [0x2fc25eed, 0x999cc2c2], - [0xb82e6d96, 0x5c432e2e], - [0x314b627a, 0x96294b4b], - [0xdffea321, 0xe15dfefe], - [0x41578216, 0xaed55757], - [0x5415a841, 0x2abd1515], - [0xc1779fb6, 0xeee87777], - [0xdc37a5eb, 0x6e923737], - [0xb3e57b56, 0xd79ee5e5], - [0x469f8cd9, 0x23139f9f], - [0xe7f0d317, 0xfd23f0f0], - [0x354a6a7f, 0x94204a4a], - [0x4fda9e95, 0xa944dada], - [0x7d58fa25, 0xb0a25858], - [0x03c906ca, 0x8fcfc9c9], - [0xa429558d, 0x527c2929], - [0x280a5022, 0x145a0a0a], - [0xfeb1e14f, 0x7f50b1b1], - [0xbaa0691a, 0x5dc9a0a0], - [0xb16b7fda, 0xd6146b6b], - [0x2e855cab, 0x17d98585], - [0xcebd8173, 0x673cbdbd], - [0x695dd234, 0xba8f5d5d], - [0x40108050, 0x20901010], - [0xf7f4f303, 0xf507f4f4], - [0x0bcb16c0, 0x8bddcbcb], - [0xf83eedc6, 0x7cd33e3e], - [0x14052811, 0x0a2d0505], - [0x81671fe6, 0xce786767], - [0xb7e47353, 0xd597e4e4], - [0x9c2725bb, 0x4e022727], - [0x19413258, 0x82734141], - [0x168b2c9d, 0x0ba78b8b], - [0xa6a75101, 0x53f6a7a7], - [0xe97dcf94, 0xfab27d7d], - [0x6e95dcfb, 0x37499595], - [0x47d88e9f, 0xad56d8d8], - [0xcbfb8b30, 0xeb70fbfb], - [0x9fee2371, 0xc1cdeeee], - [0xed7cc791, 0xf8bb7c7c], - [0x856617e3, 0xcc716666], - [0x53dda68e, 0xa77bdddd], - [0x5c17b84b, 0x2eaf1717], - [0x01470246, 0x8e454747], - [0x429e84dc, 0x211a9e9e], - [0x0fca1ec5, 0x89d4caca], - [0xb42d7599, 0x5a582d2d], - [0xc6bf9179, 0x632ebfbf], - [0x1c07381b, 0x0e3f0707], - [0x8ead0123, 0x47acadad], - [0x755aea2f, 0xb4b05a5a], - [0x36836cb5, 0x1bef8383], - [0xcc3385ff, 0x66b63333], - [0x91633ff2, 0xc65c6363], - [0x0802100a, 0x04120202], - [0x92aa3938, 0x4993aaaa], - [0xd971afa8, 0xe2de7171], - [0x07c80ecf, 0x8dc6c8c8], - [0x6419c87d, 0x32d11919], - [0x39497270, 0x923b4949], - [0x43d9869a, 0xaf5fd9d9], - [0xeff2c31d, 0xf931f2f2], - [0xabe34b48, 0xdba8e3e3], - [0x715be22a, 0xb6b95b5b], - [0x1a883492, 0x0dbc8888], - [0x529aa4c8, 0x293e9a9a], - [0x98262dbe, 0x4c0b2626], - [0xc8328dfa, 0x64bf3232], - [0xfab0e94a, 0x7d59b0b0], - [0x83e91b6a, 0xcff2e9e9], - [0x3c0f7833, 0x1e770f0f], - [0x73d5e6a6, 0xb733d5d5], - [0x3a8074ba, 0x1df48080], - [0xc2be997c, 0x6127bebe], - [0x13cd26de, 0x87ebcdcd], - [0xd034bde4, 0x68893434], - [0x3d487a75, 0x90324848], - [0xdbffab24, 0xe354ffff], - [0xf57af78f, 0xf48d7a7a], - [0x7a90f4ea, 0x3d649090], - [0x615fc23e, 0xbe9d5f5f], - [0x80201da0, 0x403d2020], - [0xbd6867d5, 0xd00f6868], - [0x681ad072, 0x34ca1a1a], - [0x82ae192c, 0x41b7aeae], - [0xeab4c95e, 0x757db4b4], - [0x4d549a19, 0xa8ce5454], - [0x7693ece5, 0x3b7f9393], - [0x88220daa, 0x442f2222], - [0x8d6407e9, 0xc8636464], - [0xe3f1db12, 0xff2af1f1], - [0xd173bfa2, 0xe6cc7373], - [0x4812905a, 0x24821212], - [0x1d403a5d, 0x807a4040], - [0x20084028, 0x10480808], - [0x2bc356e8, 0x9b95c3c3], - [0x97ec337b, 0xc5dfecec], - [0x4bdb9690, 0xab4ddbdb], - [0xbea1611f, 0x5fc0a1a1], - [0x0e8d1c83, 0x07918d8d], - [0xf43df5c9, 0x7ac83d3d], - [0x6697ccf1, 0x335b9797], - [0x00000000, 0x00000000], - [0x1bcf36d4, 0x83f9cfcf], - [0xac2b4587, 0x566e2b2b], - [0xc57697b3, 0xece17676], - [0x328264b0, 0x19e68282], - [0x7fd6fea9, 0xb128d6d6], - [0x6c1bd877, 0x36c31b1b], - [0xeeb5c15b, 0x7774b5b5], - [0x86af1129, 0x43beafaf], - [0xb56a77df, 0xd41d6a6a], - [0x5d50ba0d, 0xa0ea5050], - [0x0945124c, 0x8a574545], - [0xebf3cb18, 0xfb38f3f3], - [0xc0309df0, 0x60ad3030], - [0x9bef2b74, 0xc3c4efef], - [0xfc3fe5c3, 0x7eda3f3f], - [0x4955921c, 0xaac75555], - [0xb2a27910, 0x59dba2a2], - [0x8fea0365, 0xc9e9eaea], - [0x89650fec, 0xca6a6565], - [0xd2bab968, 0x6903baba], - [0xbc2f6593, 0x5e4a2f2f], - [0x27c04ee7, 0x9d8ec0c0], - [0x5fdebe81, 0xa160dede], - [0x701ce06c, 0x38fc1c1c], - [0xd3fdbb2e, 0xe746fdfd], - [0x294d5264, 0x9a1f4d4d], - [0x7292e4e0, 0x39769292], - [0xc9758fbc, 0xeafa7575], - [0x1806301e, 0x0c360606], - [0x128a2498, 0x09ae8a8a], - [0xf2b2f940, 0x794bb2b2], - [0xbfe66359, 0xd185e6e6], - [0x380e7036, 0x1c7e0e0e], - [0x7c1ff863, 0x3ee71f1f], - [0x956237f7, 0xc4556262], - [0x77d4eea3, 0xb53ad4d4], - [0x9aa82932, 0x4d81a8a8], - [0x6296c4f4, 0x31529696], - [0xc3f99b3a, 0xef62f9f9], - [0x33c566f6, 0x97a3c5c5], - [0x942535b1, 0x4a102525], - [0x7959f220, 0xb2ab5959], - [0x2a8454ae, 0x15d08484], - [0xd572b7a7, 0xe4c57272], - [0xe439d5dd, 0x72ec3939], - [0x2d4c5a61, 0x98164c4c], - [0x655eca3b, 0xbc945e5e], - [0xfd78e785, 0xf09f7878], - [0xe038ddd8, 0x70e53838], - [0x0a8c1486, 0x05988c8c], - [0x63d1c6b2, 0xbf17d1d1], - [0xaea5410b, 0x57e4a5a5], - [0xafe2434d, 0xd9a1e2e2], - [0x99612ff8, 0xc24e6161], - [0xf6b3f145, 0x7b42b3b3], - [0x842115a5, 0x42342121], - [0x4a9c94d6, 0x25089c9c], - [0x781ef066, 0x3cee1e1e], - [0x11432252, 0x86614343], - [0x3bc776fc, 0x93b1c7c7], - [0xd7fcb32b, 0xe54ffcfc], - [0x10042014, 0x08240404], - [0x5951b208, 0xa2e35151], - [0x5e99bcc7, 0x2f259999], - [0xa96d4fc4, 0xda226d6d], - [0x340d6839, 0x1a650d0d], - [0xcffa8335, 0xe979fafa], - [0x5bdfb684, 0xa369dfdf], - [0xe57ed79b, 0xfca97e7e], - [0x90243db4, 0x48192424], - [0xec3bc5d7, 0x76fe3b3b], - [0x96ab313d, 0x4b9aabab], - [0x1fce3ed1, 0x81f0cece], - [0x44118855, 0x22991111], - [0x068f0c89, 0x03838f8f], - [0x254e4a6b, 0x9c044e4e], - [0xe6b7d151, 0x7366b7b7], - [0x8beb0b60, 0xcbe0ebeb], - [0xf03cfdcc, 0x78c13c3c], - [0x3e817cbf, 0x1ffd8181], - [0x6a94d4fe, 0x35409494], - [0xfbf7eb0c, 0xf31cf7f7], - [0xdeb9a167, 0x6f18b9b9], - [0x4c13985f, 0x268b1313], - [0xb02c7d9c, 0x58512c2c], - [0x6bd3d6b8, 0xbb05d3d3], - [0xbbe76b5c, 0xd38ce7e7], - [0xa56e57cb, 0xdc396e6e], - [0x37c46ef3, 0x95aac4c4], - [0x0c03180f, 0x061b0303], - [0x45568a13, 0xacdc5656], - [0x0d441a49, 0x885e4444], - [0xe17fdf9e, 0xfea07f7f], - [0x9ea92137, 0x4f88a9a9], - [0xa82a4d82, 0x54672a2a], - [0xd6bbb16d, 0x6b0abbbb], - [0x23c146e2, 0x9f87c1c1], - [0x5153a202, 0xa6f15353], - [0x57dcae8b, 0xa572dcdc], - [0x2c0b5827, 0x16530b0b], - [0x4e9d9cd3, 0x27019d9d], - [0xad6c47c1, 0xd82b6c6c], - [0xc43195f5, 0x62a43131], - [0xcd7487b9, 0xe8f37474], - [0xfff6e309, 0xf115f6f6], - [0x05460a43, 0x8c4c4646], - [0x8aac0926, 0x45a5acac], - [0x1e893c97, 0x0fb58989], - [0x5014a044, 0x28b41414], - [0xa3e15b42, 0xdfbae1e1], - [0x5816b04e, 0x2ca61616], - [0xe83acdd2, 0x74f73a3a], - [0xb9696fd0, 0xd2066969], - [0x2409482d, 0x12410909], - [0xdd70a7ad, 0xe0d77070], - [0xe2b6d954, 0x716fb6b6], - [0x67d0ceb7, 0xbd1ed0d0], - [0x93ed3b7e, 0xc7d6eded], - [0x17cc2edb, 0x85e2cccc], - [0x15422a57, 0x84684242], - [0x5a98b4c2, 0x2d2c9898], - [0xaaa4490e, 0x55eda4a4], - [0xa0285d88, 0x50752828], - [0x6d5cda31, 0xb8865c5c], - [0xc7f8933f, 0xed6bf8f8], - [0x228644a4, 0x11c28686] -]); - -final _c7 = Register64List.from([ - [0x186018c0, 0x7830d818], - [0x238c2305, 0xaf462623], - [0xc63fc67e, 0xf991b8c6], - [0xe887e813, 0x6fcdfbe8], - [0x8726874c, 0xa113cb87], - [0xb8dab8a9, 0x626d11b8], - [0x01040108, 0x05020901], - [0x4f214f42, 0x6e9e0d4f], - [0x36d836ad, 0xee6c9b36], - [0xa6a2a659, 0x0451ffa6], - [0xd26fd2de, 0xbdb90cd2], - [0xf5f3f5fb, 0x06f70ef5], - [0x79f979ef, 0x80f29679], - [0x6fa16f5f, 0xcede306f], - [0x917e91fc, 0xef3f6d91], - [0x525552aa, 0x07a4f852], - [0x609d6027, 0xfdc04760], - [0xbccabc89, 0x766535bc], - [0x9b569bac, 0xcd2b379b], - [0x8e028e04, 0x8c018a8e], - [0xa3b6a371, 0x155bd2a3], - [0x0c300c60, 0x3c186c0c], - [0x7bf17bff, 0x8af6847b], - [0x35d435b5, 0xe16a8035], - [0x1d741de8, 0x693af51d], - [0xe0a7e053, 0x47ddb3e0], - [0xd77bd7f6, 0xacb321d7], - [0xc22fc25e, 0xed999cc2], - [0x2eb82e6d, 0x965c432e], - [0x4b314b62, 0x7a96294b], - [0xfedffea3, 0x21e15dfe], - [0x57415782, 0x16aed557], - [0x155415a8, 0x412abd15], - [0x77c1779f, 0xb6eee877], - [0x37dc37a5, 0xeb6e9237], - [0xe5b3e57b, 0x56d79ee5], - [0x9f469f8c, 0xd923139f], - [0xf0e7f0d3, 0x17fd23f0], - [0x4a354a6a, 0x7f94204a], - [0xda4fda9e, 0x95a944da], - [0x587d58fa, 0x25b0a258], - [0xc903c906, 0xca8fcfc9], - [0x29a42955, 0x8d527c29], - [0x0a280a50, 0x22145a0a], - [0xb1feb1e1, 0x4f7f50b1], - [0xa0baa069, 0x1a5dc9a0], - [0x6bb16b7f, 0xdad6146b], - [0x852e855c, 0xab17d985], - [0xbdcebd81, 0x73673cbd], - [0x5d695dd2, 0x34ba8f5d], - [0x10401080, 0x50209010], - [0xf4f7f4f3, 0x03f507f4], - [0xcb0bcb16, 0xc08bddcb], - [0x3ef83eed, 0xc67cd33e], - [0x05140528, 0x110a2d05], - [0x6781671f, 0xe6ce7867], - [0xe4b7e473, 0x53d597e4], - [0x279c2725, 0xbb4e0227], - [0x41194132, 0x58827341], - [0x8b168b2c, 0x9d0ba78b], - [0xa7a6a751, 0x0153f6a7], - [0x7de97dcf, 0x94fab27d], - [0x956e95dc, 0xfb374995], - [0xd847d88e, 0x9fad56d8], - [0xfbcbfb8b, 0x30eb70fb], - [0xee9fee23, 0x71c1cdee], - [0x7ced7cc7, 0x91f8bb7c], - [0x66856617, 0xe3cc7166], - [0xdd53dda6, 0x8ea77bdd], - [0x175c17b8, 0x4b2eaf17], - [0x47014702, 0x468e4547], - [0x9e429e84, 0xdc211a9e], - [0xca0fca1e, 0xc589d4ca], - [0x2db42d75, 0x995a582d], - [0xbfc6bf91, 0x79632ebf], - [0x071c0738, 0x1b0e3f07], - [0xad8ead01, 0x2347acad], - [0x5a755aea, 0x2fb4b05a], - [0x8336836c, 0xb51bef83], - [0x33cc3385, 0xff66b633], - [0x6391633f, 0xf2c65c63], - [0x02080210, 0x0a041202], - [0xaa92aa39, 0x384993aa], - [0x71d971af, 0xa8e2de71], - [0xc807c80e, 0xcf8dc6c8], - [0x196419c8, 0x7d32d119], - [0x49394972, 0x70923b49], - [0xd943d986, 0x9aaf5fd9], - [0xf2eff2c3, 0x1df931f2], - [0xe3abe34b, 0x48dba8e3], - [0x5b715be2, 0x2ab6b95b], - [0x881a8834, 0x920dbc88], - [0x9a529aa4, 0xc8293e9a], - [0x2698262d, 0xbe4c0b26], - [0x32c8328d, 0xfa64bf32], - [0xb0fab0e9, 0x4a7d59b0], - [0xe983e91b, 0x6acff2e9], - [0x0f3c0f78, 0x331e770f], - [0xd573d5e6, 0xa6b733d5], - [0x803a8074, 0xba1df480], - [0xbec2be99, 0x7c6127be], - [0xcd13cd26, 0xde87ebcd], - [0x34d034bd, 0xe4688934], - [0x483d487a, 0x75903248], - [0xffdbffab, 0x24e354ff], - [0x7af57af7, 0x8ff48d7a], - [0x907a90f4, 0xea3d6490], - [0x5f615fc2, 0x3ebe9d5f], - [0x2080201d, 0xa0403d20], - [0x68bd6867, 0xd5d00f68], - [0x1a681ad0, 0x7234ca1a], - [0xae82ae19, 0x2c41b7ae], - [0xb4eab4c9, 0x5e757db4], - [0x544d549a, 0x19a8ce54], - [0x937693ec, 0xe53b7f93], - [0x2288220d, 0xaa442f22], - [0x648d6407, 0xe9c86364], - [0xf1e3f1db, 0x12ff2af1], - [0x73d173bf, 0xa2e6cc73], - [0x12481290, 0x5a248212], - [0x401d403a, 0x5d807a40], - [0x08200840, 0x28104808], - [0xc32bc356, 0xe89b95c3], - [0xec97ec33, 0x7bc5dfec], - [0xdb4bdb96, 0x90ab4ddb], - [0xa1bea161, 0x1f5fc0a1], - [0x8d0e8d1c, 0x8307918d], - [0x3df43df5, 0xc97ac83d], - [0x976697cc, 0xf1335b97], - [0x00000000, 0x00000000], - [0xcf1bcf36, 0xd483f9cf], - [0x2bac2b45, 0x87566e2b], - [0x76c57697, 0xb3ece176], - [0x82328264, 0xb019e682], - [0xd67fd6fe, 0xa9b128d6], - [0x1b6c1bd8, 0x7736c31b], - [0xb5eeb5c1, 0x5b7774b5], - [0xaf86af11, 0x2943beaf], - [0x6ab56a77, 0xdfd41d6a], - [0x505d50ba, 0x0da0ea50], - [0x45094512, 0x4c8a5745], - [0xf3ebf3cb, 0x18fb38f3], - [0x30c0309d, 0xf060ad30], - [0xef9bef2b, 0x74c3c4ef], - [0x3ffc3fe5, 0xc37eda3f], - [0x55495592, 0x1caac755], - [0xa2b2a279, 0x1059dba2], - [0xea8fea03, 0x65c9e9ea], - [0x6589650f, 0xecca6a65], - [0xbad2bab9, 0x686903ba], - [0x2fbc2f65, 0x935e4a2f], - [0xc027c04e, 0xe79d8ec0], - [0xde5fdebe, 0x81a160de], - [0x1c701ce0, 0x6c38fc1c], - [0xfdd3fdbb, 0x2ee746fd], - [0x4d294d52, 0x649a1f4d], - [0x927292e4, 0xe0397692], - [0x75c9758f, 0xbceafa75], - [0x06180630, 0x1e0c3606], - [0x8a128a24, 0x9809ae8a], - [0xb2f2b2f9, 0x40794bb2], - [0xe6bfe663, 0x59d185e6], - [0x0e380e70, 0x361c7e0e], - [0x1f7c1ff8, 0x633ee71f], - [0x62956237, 0xf7c45562], - [0xd477d4ee, 0xa3b53ad4], - [0xa89aa829, 0x324d81a8], - [0x966296c4, 0xf4315296], - [0xf9c3f99b, 0x3aef62f9], - [0xc533c566, 0xf697a3c5], - [0x25942535, 0xb14a1025], - [0x597959f2, 0x20b2ab59], - [0x842a8454, 0xae15d084], - [0x72d572b7, 0xa7e4c572], - [0x39e439d5, 0xdd72ec39], - [0x4c2d4c5a, 0x6198164c], - [0x5e655eca, 0x3bbc945e], - [0x78fd78e7, 0x85f09f78], - [0x38e038dd, 0xd870e538], - [0x8c0a8c14, 0x8605988c], - [0xd163d1c6, 0xb2bf17d1], - [0xa5aea541, 0x0b57e4a5], - [0xe2afe243, 0x4dd9a1e2], - [0x6199612f, 0xf8c24e61], - [0xb3f6b3f1, 0x457b42b3], - [0x21842115, 0xa5423421], - [0x9c4a9c94, 0xd625089c], - [0x1e781ef0, 0x663cee1e], - [0x43114322, 0x52866143], - [0xc73bc776, 0xfc93b1c7], - [0xfcd7fcb3, 0x2be54ffc], - [0x04100420, 0x14082404], - [0x515951b2, 0x08a2e351], - [0x995e99bc, 0xc72f2599], - [0x6da96d4f, 0xc4da226d], - [0x0d340d68, 0x391a650d], - [0xfacffa83, 0x35e979fa], - [0xdf5bdfb6, 0x84a369df], - [0x7ee57ed7, 0x9bfca97e], - [0x2490243d, 0xb4481924], - [0x3bec3bc5, 0xd776fe3b], - [0xab96ab31, 0x3d4b9aab], - [0xce1fce3e, 0xd181f0ce], - [0x11441188, 0x55229911], - [0x8f068f0c, 0x8903838f], - [0x4e254e4a, 0x6b9c044e], - [0xb7e6b7d1, 0x517366b7], - [0xeb8beb0b, 0x60cbe0eb], - [0x3cf03cfd, 0xcc78c13c], - [0x813e817c, 0xbf1ffd81], - [0x946a94d4, 0xfe354094], - [0xf7fbf7eb, 0x0cf31cf7], - [0xb9deb9a1, 0x676f18b9], - [0x134c1398, 0x5f268b13], - [0x2cb02c7d, 0x9c58512c], - [0xd36bd3d6, 0xb8bb05d3], - [0xe7bbe76b, 0x5cd38ce7], - [0x6ea56e57, 0xcbdc396e], - [0xc437c46e, 0xf395aac4], - [0x030c0318, 0x0f061b03], - [0x5645568a, 0x13acdc56], - [0x440d441a, 0x49885e44], - [0x7fe17fdf, 0x9efea07f], - [0xa99ea921, 0x374f88a9], - [0x2aa82a4d, 0x8254672a], - [0xbbd6bbb1, 0x6d6b0abb], - [0xc123c146, 0xe29f87c1], - [0x535153a2, 0x02a6f153], - [0xdc57dcae, 0x8ba572dc], - [0x0b2c0b58, 0x2716530b], - [0x9d4e9d9c, 0xd327019d], - [0x6cad6c47, 0xc1d82b6c], - [0x31c43195, 0xf562a431], - [0x74cd7487, 0xb9e8f374], - [0xf6fff6e3, 0x09f115f6], - [0x4605460a, 0x438c4c46], - [0xac8aac09, 0x2645a5ac], - [0x891e893c, 0x970fb589], - [0x145014a0, 0x4428b414], - [0xe1a3e15b, 0x42dfbae1], - [0x165816b0, 0x4e2ca616], - [0x3ae83acd, 0xd274f73a], - [0x69b9696f, 0xd0d20669], - [0x09240948, 0x2d124109], - [0x70dd70a7, 0xade0d770], - [0xb6e2b6d9, 0x54716fb6], - [0xd067d0ce, 0xb7bd1ed0], - [0xed93ed3b, 0x7ec7d6ed], - [0xcc17cc2e, 0xdb85e2cc], - [0x4215422a, 0x57846842], - [0x985a98b4, 0xc22d2c98], - [0xa4aaa449, 0x0e55eda4], - [0x28a0285d, 0x88507528], - [0x5c6d5cda, 0x31b8865c], - [0xf8c7f893, 0x3fed6bf8], - [0x86228644, 0xa411c286] -]); - -final _rc = Register64List.from([ - [0x00000000, 0x00000000], - [0x1823c6e8, 0x87b8014f], - [0x36a6d2f5, 0x796f9152], - [0x60bc9b8e, 0xa30c7b35], - [0x1de0d7c2, 0x2e4bfe57], - [0x157737e5, 0x9ff04ada], - [0x58c9290a, 0xb1a06b85], - [0xbd5d10f4, 0xcb3e0567], - [0xe427418b, 0xa77d95d8], - [0xfbee7c66, 0xdd17479e], - [0xca2dbf07, 0xad5a8333] -]); diff --git a/pointycastle/lib/digests/xof_utils.dart b/pointycastle/lib/digests/xof_utils.dart deleted file mode 100644 index 7939622..0000000 --- a/pointycastle/lib/digests/xof_utils.dart +++ /dev/null @@ -1,37 +0,0 @@ -library impl.digest.utils; - -import 'dart:typed_data'; - -class XofUtils { - static Uint8List leftEncode(int strLen) { - var n = 1; - var v = strLen; - while ((v >>= 8) != 0) { - n++; - } - var b = Uint8List(n + 1); - b[0] = n; - for (var i = 1; i <= n; i++) { - b[i] = strLen >> (8 * (n - i)); - } - return b; - } - - static Uint8List rightEncode(int strLen) { - var n = 1; - var v = strLen; - while ((v >>= 8) != 0) { - n++; - } - - var b = Uint8List(n + 1); - - b[n] = n; - - for (var i = 0; i < n; i++) { - b[i] = strLen >> (8 * (n - i - 1)); - } - - return b; - } -} diff --git a/pointycastle/lib/ecc/api.dart b/pointycastle/lib/ecc/api.dart deleted file mode 100644 index 425ce64..0000000 --- a/pointycastle/lib/ecc/api.dart +++ /dev/null @@ -1,236 +0,0 @@ -// See file LICENSE for more information. - -library api.ecc; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -export 'ecdh.dart'; - -/// Standard ECC curve description -abstract class ECDomainParameters { - /// Get this domain's standard name. - String get domainName; - - ECCurve get curve; - - List? get seed; - - ECPoint get G; - - BigInt get n; - - /// Create a curve description from its standard name - factory ECDomainParameters(String domainName) => - registry.create(domainName); -} - -/// Type for coordinates of an [ECPoint] -abstract class ECFieldElement { - BigInt? toBigInteger(); - - String get fieldName; - - int get fieldSize; - - int get byteLength; - - ECFieldElement operator +(ECFieldElement b); - - ECFieldElement operator -(ECFieldElement b); - - ECFieldElement operator *(ECFieldElement b); - - ECFieldElement operator /(ECFieldElement b); - - ECFieldElement operator -(); - - ECFieldElement invert(); - - ECFieldElement square(); - - ECFieldElement? sqrt(); -} - -/// An elliptic curve point -abstract class ECPoint { - ECCurve get curve; - - ECFieldElement? get x; - - ECFieldElement? get y; - - bool get isCompressed; - - bool get isInfinity; - - Uint8List getEncoded([bool compressed = true]); - - ECPoint? operator +(ECPoint? b); - - ECPoint? operator -(ECPoint b); - - ECPoint operator -(); - - ECPoint? twice(); - - /// Multiply this point by the given number [k]. - ECPoint? operator *(BigInt? k); -} - -/// An elliptic curve -abstract class ECCurve { - ECFieldElement? get a; - - ECFieldElement? get b; - - int get fieldSize; - - ECPoint? get infinity; - - /// Create an [ECFieldElement] on this curve from its big integer value. - ECFieldElement fromBigInteger(BigInt x); - - /// Create an [ECPoint] on its curve from its coordinates - ECPoint createPoint(BigInt x, BigInt y, [bool withCompression = false]); - - ECPoint decompressPoint(int yTilde, BigInt x1); - - /// Decode a point on this curve from its ASN.1 encoding. The different encodings are taken account of, including point - /// compression for Fp (X9.62 s 4.2.1 pg 17). - ECPoint? decodePoint(List encoded); -} - -/// Base class for asymmetric keys in ECC -abstract class ECAsymmetricKey implements AsymmetricKey { - /// The domain parameters of this key - final ECDomainParameters? parameters; - - /// Create an asymmetric key for the given domain parameters - ECAsymmetricKey(this.parameters); -} - -/// Private keys in ECC -class ECPrivateKey extends ECAsymmetricKey implements PrivateKey { - /// ECC's d private parameter - final BigInt? d; - - /// Create an ECC private key for the given d and domain parameters. - ECPrivateKey(this.d, ECDomainParameters? parameters) : super(parameters); - @override - bool operator ==(Object other) { - if (other is! ECPrivateKey) return false; - return (other.parameters == parameters) && (other.d == d); - } - - @override - int get hashCode { - return parameters.hashCode + d.hashCode; - } -} - -/// Public keys in ECC -class ECPublicKey extends ECAsymmetricKey implements PublicKey { - /// ECC's Q public parameter - final ECPoint? Q; - - /// Create an ECC public key for the given Q and domain parameters. - ECPublicKey(this.Q, ECDomainParameters? parameters) : super(parameters); - @override - bool operator ==(Object other) { - if (other is! ECPublicKey) return false; - return (other.parameters == parameters) && (other.Q == Q); - } - - @override - int get hashCode { - return parameters.hashCode + Q.hashCode; - } -} - -/// A [Signature] created with ECC. -class ECSignature implements Signature { - final BigInt r; - final BigInt s; - - ECSignature(this.r, this.s); - - /// Returns true if s is in lower-s form, false otherwise. - bool isNormalized(ECDomainParameters curveParams) { - return !(s.compareTo(curveParams.n >> 1) > 0); - } - - /// - /// 'normalize' this signature by converting its s to lower-s form if necessary - /// This is required to validate this signature with some libraries such as libsecp256k1 - /// which enforce lower-s form for all signatures to combat ecdsa signature malleability - /// - /// Returns this if the signature was already normalized, or a copy if it is changed. - /// - ECSignature normalize(ECDomainParameters curveParams) { - if (isNormalized(curveParams)) { - return this; - } - return ECSignature(r, curveParams.n - s); - } - - @override - String toString() => '(${r.toString()},${s.toString()})'; - @override - bool operator ==(Object other) { - if (other is! ECSignature) return false; - return (other.r == r) && (other.s == s); - } - - @override - int get hashCode { - return r.hashCode + s.hashCode; - } -} - -/// A pair of [ECPoint]s. -class ECPair { - final ECPoint x; - final ECPoint y; - - const ECPair(this.x, this.y); - - @override - bool operator ==(Object other) { - if (other is! ECPair) return false; - return (other.x == x) && (other.y == y); - } - - @override - int get hashCode => x.hashCode + y.hashCode * 37; -} - -/// The encryptor using Elliptic Curve -abstract class ECEncryptor { - ECPair encrypt(ECPoint point); - - /// Initialize the encryptor. - void init(CipherParameters params); -} - -/// The decryptor using Elliptic Curve -abstract class ECDecryptor { - ECPoint decrypt(ECPair pair); - - /// Initialize the decryptor. - void init(CipherParameters params); -} - -abstract class ECDHAgreement { - /// initialise the agreement engine. - void init(ECPrivateKey param); - - /// return the field size for the agreement algorithm in bytes. - int getFieldSize(); - - /// given a public key from a given party calculate the next - /// message in the agreement sequence. - BigInt calculateAgreement(ECPublicKey pubKey); -} diff --git a/pointycastle/lib/ecc/curves/brainpoolp160r1.dart b/pointycastle/lib/ecc/curves/brainpoolp160r1.dart deleted file mode 100644 index 16a2452..0000000 --- a/pointycastle/lib/ecc/curves/brainpoolp160r1.dart +++ /dev/null @@ -1,33 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.brainpoolp160r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_brainpoolp160r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'brainpoolp160r1', () => ECCurve_brainpoolp160r1()); - - factory ECCurve_brainpoolp160r1() => constructFpStandardCurve( - 'brainpoolp160r1', ECCurve_brainpoolp160r1._make, - q: BigInt.parse('e95e4a5f737059dc60dfc7ad95b3d8139515620f', radix: 16), - a: BigInt.parse('340e7be2a280eb74e2be61bada745d97e8f7c300', radix: 16), - b: BigInt.parse('1e589a8595423412134faa2dbdec95c8d8675e58', radix: 16), - g: BigInt.parse( - '04bed5af16ea3f6a4f62938c4631eb5af7bdbcdbc31667cb477a1a8ec338f94741669c976316da6321', - radix: 16), - n: BigInt.parse('e95e4a5f737059dc60df5991d45029409e60fc09', radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_brainpoolp160r1; - - static ECCurve_brainpoolp160r1 _make(String domainName, ECCurve curve, - ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_brainpoolp160r1._super(domainName, curve, G, n, h, seed); - - ECCurve_brainpoolp160r1._super(super.domainName, super.curve, super.G, - super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/brainpoolp160t1.dart b/pointycastle/lib/ecc/curves/brainpoolp160t1.dart deleted file mode 100644 index f4f363c..0000000 --- a/pointycastle/lib/ecc/curves/brainpoolp160t1.dart +++ /dev/null @@ -1,33 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.brainpoolp160t1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_brainpoolp160t1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'brainpoolp160t1', () => ECCurve_brainpoolp160t1()); - - factory ECCurve_brainpoolp160t1() => constructFpStandardCurve( - 'brainpoolp160t1', ECCurve_brainpoolp160t1._make, - q: BigInt.parse('e95e4a5f737059dc60dfc7ad95b3d8139515620f', radix: 16), - a: BigInt.parse('e95e4a5f737059dc60dfc7ad95b3d8139515620c', radix: 16), - b: BigInt.parse('7a556b6dae535b7b51ed2c4d7daa7a0b5c55f380', radix: 16), - g: BigInt.parse( - '04b199b13b9b34efc1397e64baeb05acc265ff2378add6718b7c7c1961f0991b842443772152c9e0ad', - radix: 16), - n: BigInt.parse('e95e4a5f737059dc60df5991d45029409e60fc09', radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_brainpoolp160t1; - - static ECCurve_brainpoolp160t1 _make(String domainName, ECCurve curve, - ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_brainpoolp160t1._super(domainName, curve, G, n, h, seed); - - ECCurve_brainpoolp160t1._super(super.domainName, super.curve, super.G, - super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/brainpoolp192r1.dart b/pointycastle/lib/ecc/curves/brainpoolp192r1.dart deleted file mode 100644 index 2b1232e..0000000 --- a/pointycastle/lib/ecc/curves/brainpoolp192r1.dart +++ /dev/null @@ -1,37 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.brainpoolp192r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_brainpoolp192r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'brainpoolp192r1', () => ECCurve_brainpoolp192r1()); - - factory ECCurve_brainpoolp192r1() => constructFpStandardCurve( - 'brainpoolp192r1', ECCurve_brainpoolp192r1._make, - q: BigInt.parse('c302f41d932a36cda7a3463093d18db78fce476de1a86297', - radix: 16), - a: BigInt.parse('6a91174076b1e0e19c39c031fe8685c1cae040e5c69a28ef', - radix: 16), - b: BigInt.parse('469a28ef7c28cca3dc721d044f4496bcca7ef4146fbf25c9', - radix: 16), - g: BigInt.parse( - '04c0a0647eaab6a48753b033c56cb0f0900a2f5c4853375fd614b690866abd5bb88b5f4828c1490002e6773fa2fa299b8f', - radix: 16), - n: BigInt.parse('c302f41d932a36cda7a3462f9e9e916b5be8f1029ac4acc1', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_brainpoolp192r1; - - static ECCurve_brainpoolp192r1 _make(String domainName, ECCurve curve, - ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_brainpoolp192r1._super(domainName, curve, G, n, h, seed); - - ECCurve_brainpoolp192r1._super(super.domainName, super.curve, super.G, - super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/brainpoolp192t1.dart b/pointycastle/lib/ecc/curves/brainpoolp192t1.dart deleted file mode 100644 index 3c98ef3..0000000 --- a/pointycastle/lib/ecc/curves/brainpoolp192t1.dart +++ /dev/null @@ -1,37 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.brainpoolp192t1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_brainpoolp192t1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'brainpoolp192t1', () => ECCurve_brainpoolp192t1()); - - factory ECCurve_brainpoolp192t1() => constructFpStandardCurve( - 'brainpoolp192t1', ECCurve_brainpoolp192t1._make, - q: BigInt.parse('c302f41d932a36cda7a3463093d18db78fce476de1a86297', - radix: 16), - a: BigInt.parse('c302f41d932a36cda7a3463093d18db78fce476de1a86294', - radix: 16), - b: BigInt.parse('13d56ffaec78681e68f9deb43b35bec2fb68542e27897b79', - radix: 16), - g: BigInt.parse( - '043ae9e58c82f63c30282e1fe7bbf43fa72c446af6f4618129097e2c5667c2223a902ab5ca449d0084b7e5b3de7ccc01c9', - radix: 16), - n: BigInt.parse('c302f41d932a36cda7a3462f9e9e916b5be8f1029ac4acc1', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_brainpoolp192t1; - - static ECCurve_brainpoolp192t1 _make(String domainName, ECCurve curve, - ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_brainpoolp192t1._super(domainName, curve, G, n, h, seed); - - ECCurve_brainpoolp192t1._super(super.domainName, super.curve, super.G, - super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/brainpoolp224r1.dart b/pointycastle/lib/ecc/curves/brainpoolp224r1.dart deleted file mode 100644 index b529e04..0000000 --- a/pointycastle/lib/ecc/curves/brainpoolp224r1.dart +++ /dev/null @@ -1,41 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.brainpoolp224r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_brainpoolp224r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'brainpoolp224r1', () => ECCurve_brainpoolp224r1()); - - factory ECCurve_brainpoolp224r1() => constructFpStandardCurve( - 'brainpoolp224r1', ECCurve_brainpoolp224r1._make, - q: BigInt.parse( - 'd7c134aa264366862a18302575d1d787b09f075797da89f57ec8c0ff', - radix: 16), - a: BigInt.parse( - '68a5e62ca9ce6c1c299803a6c1530b514e182ad8b0042a59cad29f43', - radix: 16), - b: BigInt.parse( - '2580f63ccfe44138870713b1a92369e33e2135d266dbb372386c400b', - radix: 16), - g: BigInt.parse( - '040d9029ad2c7e5cf4340823b2a87dc68c9e4ce3174c1e6efdee12c07d58aa56f772c0726f24c6b89e4ecdac24354b9e99caa3f6d3761402cd', - radix: 16), - n: BigInt.parse( - 'd7c134aa264366862a18302575d0fb98d116bc4b6ddebca3a5a7939f', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_brainpoolp224r1; - - static ECCurve_brainpoolp224r1 _make(String domainName, ECCurve curve, - ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_brainpoolp224r1._super(domainName, curve, G, n, h, seed); - - ECCurve_brainpoolp224r1._super(super.domainName, super.curve, super.G, - super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/brainpoolp224t1.dart b/pointycastle/lib/ecc/curves/brainpoolp224t1.dart deleted file mode 100644 index efc0fd8..0000000 --- a/pointycastle/lib/ecc/curves/brainpoolp224t1.dart +++ /dev/null @@ -1,41 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.brainpoolp224t1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_brainpoolp224t1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'brainpoolp224t1', () => ECCurve_brainpoolp224t1()); - - factory ECCurve_brainpoolp224t1() => constructFpStandardCurve( - 'brainpoolp224t1', ECCurve_brainpoolp224t1._make, - q: BigInt.parse( - 'd7c134aa264366862a18302575d1d787b09f075797da89f57ec8c0ff', - radix: 16), - a: BigInt.parse( - 'd7c134aa264366862a18302575d1d787b09f075797da89f57ec8c0fc', - radix: 16), - b: BigInt.parse( - '4b337d934104cd7bef271bf60ced1ed20da14c08b3bb64f18a60888d', - radix: 16), - g: BigInt.parse( - '046ab1e344ce25ff3896424e7ffe14762ecb49f8928ac0c76029b4d5800374e9f5143e568cd23f3f4d7c0d4b1e41c8cc0d1c6abd5f1a46db4c', - radix: 16), - n: BigInt.parse( - 'd7c134aa264366862a18302575d0fb98d116bc4b6ddebca3a5a7939f', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_brainpoolp224t1; - - static ECCurve_brainpoolp224t1 _make(String domainName, ECCurve curve, - ECPoint G, BigInt n, BigInt? h, List? seed) => - ECCurve_brainpoolp224t1._super(domainName, curve, G, n, h, seed); - - ECCurve_brainpoolp224t1._super( - super.domainName, super.curve, super.G, super.n, super.h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/brainpoolp256r1.dart b/pointycastle/lib/ecc/curves/brainpoolp256r1.dart deleted file mode 100644 index ed0f89b..0000000 --- a/pointycastle/lib/ecc/curves/brainpoolp256r1.dart +++ /dev/null @@ -1,41 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.brainpoolp256r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_brainpoolp256r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'brainpoolp256r1', () => ECCurve_brainpoolp256r1()); - - factory ECCurve_brainpoolp256r1() => constructFpStandardCurve( - 'brainpoolp256r1', ECCurve_brainpoolp256r1._make, - q: BigInt.parse( - 'a9fb57dba1eea9bc3e660a909d838d726e3bf623d52620282013481d1f6e5377', - radix: 16), - a: BigInt.parse( - '7d5a0975fc2c3057eef67530417affe7fb8055c126dc5c6ce94a4b44f330b5d9', - radix: 16), - b: BigInt.parse( - '26dc5c6ce94a4b44f330b5d9bbd77cbf958416295cf7e1ce6bccdc18ff8c07b6', - radix: 16), - g: BigInt.parse( - '048bd2aeb9cb7e57cb2c4b482ffc81b7afb9de27e1e3bd23c23a4453bd9ace3262547ef835c3dac4fd97f8461a14611dc9c27745132ded8e545c1d54c72f046997', - radix: 16), - n: BigInt.parse( - 'a9fb57dba1eea9bc3e660a909d838d718c397aa3b561a6f7901e0e82974856a7', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_brainpoolp256r1; - - static ECCurve_brainpoolp256r1 _make(String domainName, ECCurve curve, - ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_brainpoolp256r1._super(domainName, curve, G, n, h, seed); - - ECCurve_brainpoolp256r1._super(super.domainName, super.curve, super.G, - super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/brainpoolp256t1.dart b/pointycastle/lib/ecc/curves/brainpoolp256t1.dart deleted file mode 100644 index 690fe10..0000000 --- a/pointycastle/lib/ecc/curves/brainpoolp256t1.dart +++ /dev/null @@ -1,41 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.brainpoolp256t1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_brainpoolp256t1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'brainpoolp256t1', () => ECCurve_brainpoolp256t1()); - - factory ECCurve_brainpoolp256t1() => constructFpStandardCurve( - 'brainpoolp256t1', ECCurve_brainpoolp256t1._make, - q: BigInt.parse( - 'a9fb57dba1eea9bc3e660a909d838d726e3bf623d52620282013481d1f6e5377', - radix: 16), - a: BigInt.parse( - 'a9fb57dba1eea9bc3e660a909d838d726e3bf623d52620282013481d1f6e5374', - radix: 16), - b: BigInt.parse( - '662c61c430d84ea4fe66a7733d0b76b7bf93ebc4af2f49256ae58101fee92b04', - radix: 16), - g: BigInt.parse( - '04a3e8eb3cc1cfe7b7732213b23a656149afa142c47aafbc2b79a191562e1305f42d996c823439c56d7f7b22e14644417e69bcb6de39d027001dabe8f35b25c9be', - radix: 16), - n: BigInt.parse( - 'a9fb57dba1eea9bc3e660a909d838d718c397aa3b561a6f7901e0e82974856a7', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_brainpoolp256t1; - - static ECCurve_brainpoolp256t1 _make(String domainName, ECCurve curve, - ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_brainpoolp256t1._super(domainName, curve, G, n, h, seed); - - ECCurve_brainpoolp256t1._super(super.domainName, super.curve, super.G, - super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/brainpoolp320r1.dart b/pointycastle/lib/ecc/curves/brainpoolp320r1.dart deleted file mode 100644 index 9618df0..0000000 --- a/pointycastle/lib/ecc/curves/brainpoolp320r1.dart +++ /dev/null @@ -1,41 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.brainpoolp320r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_brainpoolp320r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'brainpoolp320r1', () => ECCurve_brainpoolp320r1()); - - factory ECCurve_brainpoolp320r1() => constructFpStandardCurve( - 'brainpoolp320r1', ECCurve_brainpoolp320r1._make, - q: BigInt.parse( - 'd35e472036bc4fb7e13c785ed201e065f98fcfa6f6f40def4f92b9ec7893ec28fcd412b1f1b32e27', - radix: 16), - a: BigInt.parse( - '3ee30b568fbab0f883ccebd46d3f3bb8a2a73513f5eb79da66190eb085ffa9f492f375a97d860eb4', - radix: 16), - b: BigInt.parse( - '520883949dfdbc42d3ad198640688a6fe13f41349554b49acc31dccd884539816f5eb4ac8fb1f1a6', - radix: 16), - g: BigInt.parse( - '0443bd7e9afb53d8b85289bcc48ee5bfe6f20137d10a087eb6e7871e2a10a599c710af8d0d39e2061114fdd05545ec1cc8ab4093247f77275e0743ffed117182eaa9c77877aaac6ac7d35245d1692e8ee1', - radix: 16), - n: BigInt.parse( - 'd35e472036bc4fb7e13c785ed201e065f98fcfa5b68f12a32d482ec7ee8658e98691555b44c59311', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_brainpoolp320r1; - - static ECCurve_brainpoolp320r1 _make(String domainName, ECCurve curve, - ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_brainpoolp320r1._super(domainName, curve, G, n, h, seed); - - ECCurve_brainpoolp320r1._super(super.domainName, super.curve, super.G, - super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/brainpoolp320t1.dart b/pointycastle/lib/ecc/curves/brainpoolp320t1.dart deleted file mode 100644 index 289d43d..0000000 --- a/pointycastle/lib/ecc/curves/brainpoolp320t1.dart +++ /dev/null @@ -1,41 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.brainpoolp320t1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_brainpoolp320t1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'brainpoolp320t1', () => ECCurve_brainpoolp320t1()); - - factory ECCurve_brainpoolp320t1() => constructFpStandardCurve( - 'brainpoolp320t1', ECCurve_brainpoolp320t1._make, - q: BigInt.parse( - 'd35e472036bc4fb7e13c785ed201e065f98fcfa6f6f40def4f92b9ec7893ec28fcd412b1f1b32e27', - radix: 16), - a: BigInt.parse( - 'd35e472036bc4fb7e13c785ed201e065f98fcfa6f6f40def4f92b9ec7893ec28fcd412b1f1b32e24', - radix: 16), - b: BigInt.parse( - 'a7f561e038eb1ed560b3d147db782013064c19f27ed27c6780aaf77fb8a547ceb5b4fef422340353', - radix: 16), - g: BigInt.parse( - '04925be9fb01afc6fb4d3e7d4990010f813408ab106c4f09cb7ee07868cc136fff3357f624a21bed5263ba3a7a27483ebf6671dbef7abb30ebee084e58a0b077ad42a5a0989d1ee71b1b9bc0455fb0d2c3', - radix: 16), - n: BigInt.parse( - 'd35e472036bc4fb7e13c785ed201e065f98fcfa5b68f12a32d482ec7ee8658e98691555b44c59311', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_brainpoolp320t1; - - static ECCurve_brainpoolp320t1 _make(String domainName, ECCurve curve, - ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_brainpoolp320t1._super(domainName, curve, G, n, h, seed); - - ECCurve_brainpoolp320t1._super(super.domainName, super.curve, super.G, - super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/brainpoolp384r1.dart b/pointycastle/lib/ecc/curves/brainpoolp384r1.dart deleted file mode 100644 index ae2749a..0000000 --- a/pointycastle/lib/ecc/curves/brainpoolp384r1.dart +++ /dev/null @@ -1,41 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.brainpoolp384r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_brainpoolp384r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'brainpoolp384r1', () => ECCurve_brainpoolp384r1()); - - factory ECCurve_brainpoolp384r1() => constructFpStandardCurve( - 'brainpoolp384r1', ECCurve_brainpoolp384r1._make, - q: BigInt.parse( - '8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b412b1da197fb71123acd3a729901d1a71874700133107ec53', - radix: 16), - a: BigInt.parse( - '7bc382c63d8c150c3c72080ace05afa0c2bea28e4fb22787139165efba91f90f8aa5814a503ad4eb04a8c7dd22ce2826', - radix: 16), - b: BigInt.parse( - '4a8c7dd22ce28268b39b55416f0447c2fb77de107dcd2a62e880ea53eeb62d57cb4390295dbc9943ab78696fa504c11', - radix: 16), - g: BigInt.parse( - '041d1c64f068cf45ffa2a63a81b7c13f6b8847a3e77ef14fe3db7fcafe0cbd10e8e826e03436d646aaef87b2e247d4af1e8abe1d7520f9c2a45cb1eb8e95cfd55262b70b29feec5864e19c054ff99129280e4646217791811142820341263c5315', - radix: 16), - n: BigInt.parse( - '8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b31f166e6cac0425a7cf3ab6af6b7fc3103b883202e9046565', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_brainpoolp384r1; - - static ECCurve_brainpoolp384r1 _make(String domainName, ECCurve curve, - ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_brainpoolp384r1._super(domainName, curve, G, n, h, seed); - - ECCurve_brainpoolp384r1._super(super.domainName, super.curve, super.G, - super.n, BigInt super.h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/brainpoolp384t1.dart b/pointycastle/lib/ecc/curves/brainpoolp384t1.dart deleted file mode 100644 index a0479de..0000000 --- a/pointycastle/lib/ecc/curves/brainpoolp384t1.dart +++ /dev/null @@ -1,41 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.brainpoolp384t1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_brainpoolp384t1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'brainpoolp384t1', () => ECCurve_brainpoolp384t1()); - - factory ECCurve_brainpoolp384t1() => constructFpStandardCurve( - 'brainpoolp384t1', ECCurve_brainpoolp384t1._make, - q: BigInt.parse( - '8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b412b1da197fb71123acd3a729901d1a71874700133107ec53', - radix: 16), - a: BigInt.parse( - '8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b412b1da197fb71123acd3a729901d1a71874700133107ec50', - radix: 16), - b: BigInt.parse( - '7f519eada7bda81bd826dba647910f8c4b9346ed8ccdc64e4b1abd11756dce1d2074aa263b88805ced70355a33b471ee', - radix: 16), - g: BigInt.parse( - '0418de98b02db9a306f2afcd7235f72a819b80ab12ebd653172476fecd462aabffc4ff191b946a5f54d8d0aa2f418808cc25ab056962d30651a114afd2755ad336747f93475b7a1fca3b88f2b6a208ccfe469408584dc2b2912675bf5b9e582928', - radix: 16), - n: BigInt.parse( - '8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b31f166e6cac0425a7cf3ab6af6b7fc3103b883202e9046565', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_brainpoolp384t1; - - static ECCurve_brainpoolp384t1 _make(String domainName, ECCurve curve, - ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_brainpoolp384t1._super(domainName, curve, G, n, h, seed); - - ECCurve_brainpoolp384t1._super(super.domainName, super.curve, super.G, - super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/brainpoolp512r1.dart b/pointycastle/lib/ecc/curves/brainpoolp512r1.dart deleted file mode 100644 index b9ac142..0000000 --- a/pointycastle/lib/ecc/curves/brainpoolp512r1.dart +++ /dev/null @@ -1,41 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.brainpoolp512r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_brainpoolp512r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'brainpoolp512r1', () => ECCurve_brainpoolp512r1()); - - factory ECCurve_brainpoolp512r1() => constructFpStandardCurve( - 'brainpoolp512r1', ECCurve_brainpoolp512r1._make, - q: BigInt.parse( - 'aadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca703308717d4d9b009bc66842aecda12ae6a380e62881ff2f2d82c68528aa6056583a48f3', - radix: 16), - a: BigInt.parse( - '7830a3318b603b89e2327145ac234cc594cbdd8d3df91610a83441caea9863bc2ded5d5aa8253aa10a2ef1c98b9ac8b57f1117a72bf2c7b9e7c1ac4d77fc94ca', - radix: 16), - b: BigInt.parse( - '3df91610a83441caea9863bc2ded5d5aa8253aa10a2ef1c98b9ac8b57f1117a72bf2c7b9e7c1ac4d77fc94cadc083e67984050b75ebae5dd2809bd638016f723', - radix: 16), - g: BigInt.parse( - '0481aee4bdd82ed9645a21322e9c4c6a9385ed9f70b5d916c1b43b62eef4d0098eff3b1f78e2d0d48d50d1687b93b97d5f7c6d5047406a5e688b352209bcb9f8227dde385d566332ecc0eabfa9cf7822fdf209f70024a57b1aa000c55b881f8111b2dcde494a5f485e5bca4bd88a2763aed1ca2b2fa8f0540678cd1e0f3ad80892', - radix: 16), - n: BigInt.parse( - 'aadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca70330870553e5c414ca92619418661197fac10471db1d381085ddaddb58796829ca90069', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_brainpoolp512r1; - - static ECCurve_brainpoolp512r1 _make(String domainName, ECCurve curve, - ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_brainpoolp512r1._super(domainName, curve, G, n, h, seed); - - ECCurve_brainpoolp512r1._super(super.domainName, super.curve, super.G, - super.n, BigInt super.h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/brainpoolp512t1.dart b/pointycastle/lib/ecc/curves/brainpoolp512t1.dart deleted file mode 100644 index 461dc62..0000000 --- a/pointycastle/lib/ecc/curves/brainpoolp512t1.dart +++ /dev/null @@ -1,41 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.brainpoolp512t1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_brainpoolp512t1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'brainpoolp512t1', () => ECCurve_brainpoolp512t1()); - - factory ECCurve_brainpoolp512t1() => constructFpStandardCurve( - 'brainpoolp512t1', ECCurve_brainpoolp512t1._make, - q: BigInt.parse( - 'aadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca703308717d4d9b009bc66842aecda12ae6a380e62881ff2f2d82c68528aa6056583a48f3', - radix: 16), - a: BigInt.parse( - 'aadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca703308717d4d9b009bc66842aecda12ae6a380e62881ff2f2d82c68528aa6056583a48f0', - radix: 16), - b: BigInt.parse( - '7cbbbcf9441cfab76e1890e46884eae321f70c0bcb4981527897504bec3e36a62bcdfa2304976540f6450085f2dae145c22553b465763689180ea2571867423e', - radix: 16), - g: BigInt.parse( - '04640ece5c12788717b9c1ba06cbc2a6feba85842458c56dde9db1758d39c0313d82ba51735cdb3ea499aa77a7d6943a64f7a3f25fe26f06b51baa2696fa9035da5b534bd595f5af0fa2c892376c84ace1bb4e3019b71634c01131159cae03cee9d9932184beef216bd71df2dadf86a627306ecff96dbb8bace198b61e00f8b332', - radix: 16), - n: BigInt.parse( - 'aadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca70330870553e5c414ca92619418661197fac10471db1d381085ddaddb58796829ca90069', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_brainpoolp512t1; - - static ECCurve_brainpoolp512t1 _make(String domainName, ECCurve curve, - ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_brainpoolp512t1._super(domainName, curve, G, n, h, seed); - - ECCurve_brainpoolp512t1._super(super.domainName, super.curve, super.G, - super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_a.dart b/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_a.dart deleted file mode 100644 index 37d1113..0000000 --- a/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_a.dart +++ /dev/null @@ -1,42 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.gostr3410_2001_cryptopro_a; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_gostr3410_2001_cryptopro_a extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, - 'GostR3410-2001-CryptoPro-A', - () => ECCurve_gostr3410_2001_cryptopro_a()); - - factory ECCurve_gostr3410_2001_cryptopro_a() => constructFpStandardCurve( - 'GostR3410-2001-CryptoPro-A', ECCurve_gostr3410_2001_cryptopro_a._make, - q: BigInt.parse( - 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd97', - radix: 16), - a: BigInt.parse( - 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd94', - radix: 16), - b: BigInt.parse('a6', radix: 16), - g: BigInt.parse( - '0400000000000000000000000000000000000000000000000000000000000000018d91e471e0989cda27df505a453f2b7635294f2ddf23e3b122acc99c9e9f1e14', - radix: 16), - n: BigInt.parse( - 'ffffffffffffffffffffffffffffffff6c611070995ad10045841b09b761b893', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_gostr3410_2001_cryptopro_a; - - static ECCurve_gostr3410_2001_cryptopro_a _make(String domainName, - ECCurve curve, ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_gostr3410_2001_cryptopro_a._super( - domainName, curve, G, n, h, seed); - - ECCurve_gostr3410_2001_cryptopro_a._super(super.domainName, super.curve, - super.G, super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_b.dart b/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_b.dart deleted file mode 100644 index 74f2fb4..0000000 --- a/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_b.dart +++ /dev/null @@ -1,44 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.gostr3410_2001_cryptopro_b; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_gostr3410_2001_cryptopro_b extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, - 'GostR3410-2001-CryptoPro-B', - () => ECCurve_gostr3410_2001_cryptopro_b()); - - factory ECCurve_gostr3410_2001_cryptopro_b() => constructFpStandardCurve( - 'GostR3410-2001-CryptoPro-B', ECCurve_gostr3410_2001_cryptopro_b._make, - q: BigInt.parse( - '8000000000000000000000000000000000000000000000000000000000000c99', - radix: 16), - a: BigInt.parse( - '8000000000000000000000000000000000000000000000000000000000000c96', - radix: 16), - b: BigInt.parse( - '3e1af419a269a5f866a7d3c25c3df80ae979259373ff2b182f49d4ce7e1bbc8b', - radix: 16), - g: BigInt.parse( - '0400000000000000000000000000000000000000000000000000000000000000013fa8124359f96680b83d1c3eb2c070e5c545c9858d03ecfb744bf8d717717efc', - radix: 16), - n: BigInt.parse( - '800000000000000000000000000000015f700cfff1a624e5e497161bcc8a198f', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_gostr3410_2001_cryptopro_b; - - static ECCurve_gostr3410_2001_cryptopro_b _make(String domainName, - ECCurve curve, ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_gostr3410_2001_cryptopro_b._super( - domainName, curve, G, n, h, seed); - - ECCurve_gostr3410_2001_cryptopro_b._super(super.domainName, super.curve, - super.G, super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_c.dart b/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_c.dart deleted file mode 100644 index 18e3b73..0000000 --- a/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_c.dart +++ /dev/null @@ -1,42 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.gostr3410_2001_cryptopro_c; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_gostr3410_2001_cryptopro_c extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, - 'GostR3410-2001-CryptoPro-C', - () => ECCurve_gostr3410_2001_cryptopro_c()); - - factory ECCurve_gostr3410_2001_cryptopro_c() => constructFpStandardCurve( - 'GostR3410-2001-CryptoPro-C', ECCurve_gostr3410_2001_cryptopro_c._make, - q: BigInt.parse( - '9b9f605f5a858107ab1ec85e6b41c8aacf846e86789051d37998f7b9022d759b', - radix: 16), - a: BigInt.parse( - '9b9f605f5a858107ab1ec85e6b41c8aacf846e86789051d37998f7b9022d7598', - radix: 16), - b: BigInt.parse('805a', radix: 16), - g: BigInt.parse( - '04000000000000000000000000000000000000000000000000000000000000000041ece55743711a8c3cbf3783cd08c0ee4d4dc440d4641a8f366e550dfdb3bb67', - radix: 16), - n: BigInt.parse( - '9b9f605f5a858107ab1ec85e6b41c8aa582ca3511eddfb74f02f3a6598980bb9', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_gostr3410_2001_cryptopro_c; - - static ECCurve_gostr3410_2001_cryptopro_c _make(String domainName, - ECCurve curve, ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_gostr3410_2001_cryptopro_c._super( - domainName, curve, G, n, h, seed); - - ECCurve_gostr3410_2001_cryptopro_c._super(super.domainName, super.curve, - super.G, super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_xcha.dart b/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_xcha.dart deleted file mode 100644 index 0fc1c2f..0000000 --- a/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_xcha.dart +++ /dev/null @@ -1,43 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.gostr3410_2001_cryptopro_xcha; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_gostr3410_2001_cryptopro_xcha extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, - 'GostR3410-2001-CryptoPro-XchA', - () => ECCurve_gostr3410_2001_cryptopro_xcha()); - - factory ECCurve_gostr3410_2001_cryptopro_xcha() => constructFpStandardCurve( - 'GostR3410-2001-CryptoPro-XchA', - ECCurve_gostr3410_2001_cryptopro_xcha._make, - q: BigInt.parse( - 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd97', - radix: 16), - a: BigInt.parse( - 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd94', - radix: 16), - b: BigInt.parse('a6', radix: 16), - g: BigInt.parse( - '0400000000000000000000000000000000000000000000000000000000000000018d91e471e0989cda27df505a453f2b7635294f2ddf23e3b122acc99c9e9f1e14', - radix: 16), - n: BigInt.parse( - 'ffffffffffffffffffffffffffffffff6c611070995ad10045841b09b761b893', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_gostr3410_2001_cryptopro_xcha; - - static ECCurve_gostr3410_2001_cryptopro_xcha _make(String domainName, - ECCurve curve, ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_gostr3410_2001_cryptopro_xcha._super( - domainName, curve, G, n, h, seed); - - ECCurve_gostr3410_2001_cryptopro_xcha._super(super.domainName, super.curve, - super.G, super.n, BigInt super.h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_xchb.dart b/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_xchb.dart deleted file mode 100644 index 545cb7a..0000000 --- a/pointycastle/lib/ecc/curves/gostr3410_2001_cryptopro_xchb.dart +++ /dev/null @@ -1,43 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.gostr3410_2001_cryptopro_xchb; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_gostr3410_2001_cryptopro_xchb extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, - 'GostR3410-2001-CryptoPro-XchB', - () => ECCurve_gostr3410_2001_cryptopro_xchb()); - - factory ECCurve_gostr3410_2001_cryptopro_xchb() => constructFpStandardCurve( - 'GostR3410-2001-CryptoPro-XchB', - ECCurve_gostr3410_2001_cryptopro_xchb._make, - q: BigInt.parse( - '9b9f605f5a858107ab1ec85e6b41c8aacf846e86789051d37998f7b9022d759b', - radix: 16), - a: BigInt.parse( - '9b9f605f5a858107ab1ec85e6b41c8aacf846e86789051d37998f7b9022d7598', - radix: 16), - b: BigInt.parse('805a', radix: 16), - g: BigInt.parse( - '04000000000000000000000000000000000000000000000000000000000000000041ece55743711a8c3cbf3783cd08c0ee4d4dc440d4641a8f366e550dfdb3bb67', - radix: 16), - n: BigInt.parse( - '9b9f605f5a858107ab1ec85e6b41c8aa582ca3511eddfb74f02f3a6598980bb9', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_gostr3410_2001_cryptopro_xchb; - - static ECCurve_gostr3410_2001_cryptopro_xchb _make(String domainName, - ECCurve curve, ECPoint G, BigInt n, BigInt h, List? seed) => - ECCurve_gostr3410_2001_cryptopro_xchb._super( - domainName, curve, G, n, h, seed); - - ECCurve_gostr3410_2001_cryptopro_xchb._super(super.domainName, super.curve, - super.G, super.n, BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/prime192v1.dart b/pointycastle/lib/ecc/curves/prime192v1.dart deleted file mode 100644 index f175fd8..0000000 --- a/pointycastle/lib/ecc/curves/prime192v1.dart +++ /dev/null @@ -1,37 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.prime192v1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_prime192v1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'prime192v1', () => ECCurve_prime192v1()); - - factory ECCurve_prime192v1() => - constructFpStandardCurve('prime192v1', ECCurve_prime192v1._make, - q: BigInt.parse('fffffffffffffffffffffffffffffffeffffffffffffffff', - radix: 16), - a: BigInt.parse('fffffffffffffffffffffffffffffffefffffffffffffffc', - radix: 16), - b: BigInt.parse('64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1', - radix: 16), - g: BigInt.parse('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012', - radix: 16), - n: BigInt.parse('ffffffffffffffffffffffff99def836146bc9b1b4d22831', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('3045ae6fc8422f64ed579528d38120eae12196d5', - radix: 16)) as ECCurve_prime192v1; - - static ECCurve_prime192v1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_prime192v1._super(domainName, curve, G, n, h, seed); - - ECCurve_prime192v1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/prime192v2.dart b/pointycastle/lib/ecc/curves/prime192v2.dart deleted file mode 100644 index 6fed7c3..0000000 --- a/pointycastle/lib/ecc/curves/prime192v2.dart +++ /dev/null @@ -1,37 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.prime192v2; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_prime192v2 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'prime192v2', () => ECCurve_prime192v2()); - - factory ECCurve_prime192v2() => - constructFpStandardCurve('prime192v2', ECCurve_prime192v2._make, - q: BigInt.parse('fffffffffffffffffffffffffffffffeffffffffffffffff', - radix: 16), - a: BigInt.parse('fffffffffffffffffffffffffffffffefffffffffffffffc', - radix: 16), - b: BigInt.parse('cc22d6dfb95c6b25e49c0d6364a4e5980c393aa21668d953', - radix: 16), - g: BigInt.parse('03eea2bae7e1497842f2de7769cfe9c989c072ad696f48034a', - radix: 16), - n: BigInt.parse('fffffffffffffffffffffffe5fb1a724dc80418648d8dd31', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('31a92ee2029fd10d901b113e990710f0d21ac6b6', - radix: 16)) as ECCurve_prime192v2; - - static ECCurve_prime192v2 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_prime192v2._super(domainName, curve, G, n, h, seed); - - ECCurve_prime192v2._super(super.domainName, super.curve, super.G, super.n, - BigInt super.h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/prime192v3.dart b/pointycastle/lib/ecc/curves/prime192v3.dart deleted file mode 100644 index 3222932..0000000 --- a/pointycastle/lib/ecc/curves/prime192v3.dart +++ /dev/null @@ -1,37 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.prime192v3; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_prime192v3 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'prime192v3', () => ECCurve_prime192v3()); - - factory ECCurve_prime192v3() => - constructFpStandardCurve('prime192v3', ECCurve_prime192v3._make, - q: BigInt.parse('fffffffffffffffffffffffffffffffeffffffffffffffff', - radix: 16), - a: BigInt.parse('fffffffffffffffffffffffffffffffefffffffffffffffc', - radix: 16), - b: BigInt.parse('22123dc2395a05caa7423daeccc94760a7d462256bd56916', - radix: 16), - g: BigInt.parse('027d29778100c65a1da1783716588dce2b8b4aee8e228f1896', - radix: 16), - n: BigInt.parse('ffffffffffffffffffffffff7a62d031c83f4294f640ec13', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('c469684435deb378c4b65ca9591e2a5763059a2e', - radix: 16)) as ECCurve_prime192v3; - - static ECCurve_prime192v3 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_prime192v3._super(domainName, curve, G, n, h, seed); - - ECCurve_prime192v3._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/prime239v1.dart b/pointycastle/lib/ecc/curves/prime239v1.dart deleted file mode 100644 index 2c034e9..0000000 --- a/pointycastle/lib/ecc/curves/prime239v1.dart +++ /dev/null @@ -1,42 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.prime239v1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_prime239v1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'prime239v1', () => ECCurve_prime239v1()); - - factory ECCurve_prime239v1() => - constructFpStandardCurve('prime239v1', ECCurve_prime239v1._make, - q: BigInt.parse( - '7fffffffffffffffffffffff7fffffffffff8000000000007fffffffffff', - radix: 16), - a: BigInt.parse( - '7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc', - radix: 16), - b: BigInt.parse( - '6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a', - radix: 16), - g: BigInt.parse( - '020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf', - radix: 16), - n: BigInt.parse( - '7fffffffffffffffffffffff7fffff9e5e9a9f5d9071fbd1522688909d0b', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('e43bb460f0b80cc0c0b075798e948060f8321b7d', - radix: 16)) as ECCurve_prime239v1; - - static ECCurve_prime239v1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_prime239v1._super(domainName, curve, G, n, h, seed); - - ECCurve_prime239v1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/prime239v2.dart b/pointycastle/lib/ecc/curves/prime239v2.dart deleted file mode 100644 index 1d681b5..0000000 --- a/pointycastle/lib/ecc/curves/prime239v2.dart +++ /dev/null @@ -1,42 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.prime239v2; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_prime239v2 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'prime239v2', () => ECCurve_prime239v2()); - - factory ECCurve_prime239v2() => - constructFpStandardCurve('prime239v2', ECCurve_prime239v2._make, - q: BigInt.parse( - '7fffffffffffffffffffffff7fffffffffff8000000000007fffffffffff', - radix: 16), - a: BigInt.parse( - '7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc', - radix: 16), - b: BigInt.parse( - '617fab6832576cbbfed50d99f0249c3fee58b94ba0038c7ae84c8c832f2c', - radix: 16), - g: BigInt.parse( - '0238af09d98727705120c921bb5e9e26296a3cdcf2f35757a0eafd87b830e7', - radix: 16), - n: BigInt.parse( - '7fffffffffffffffffffffff800000cfa7e8594377d414c03821bc582063', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('e8b4011604095303ca3b8099982be09fcb9ae616', - radix: 16)) as ECCurve_prime239v2; - - static ECCurve_prime239v2 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_prime239v2._super(domainName, curve, G, n, h, seed); - - ECCurve_prime239v2._super(super.domainName, super.curve, super.G, super.n, - BigInt super.h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/prime239v3.dart b/pointycastle/lib/ecc/curves/prime239v3.dart deleted file mode 100644 index 4d01113..0000000 --- a/pointycastle/lib/ecc/curves/prime239v3.dart +++ /dev/null @@ -1,42 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.prime239v3; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_prime239v3 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'prime239v3', () => ECCurve_prime239v3()); - - factory ECCurve_prime239v3() => - constructFpStandardCurve('prime239v3', ECCurve_prime239v3._make, - q: BigInt.parse( - '7fffffffffffffffffffffff7fffffffffff8000000000007fffffffffff', - radix: 16), - a: BigInt.parse( - '7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc', - radix: 16), - b: BigInt.parse( - '255705fa2a306654b1f4cb03d6a750a30c250102d4988717d9ba15ab6d3e', - radix: 16), - g: BigInt.parse( - '036768ae8e18bb92cfcf005c949aa2c6d94853d0e660bbf854b1c9505fe95a', - radix: 16), - n: BigInt.parse( - '7fffffffffffffffffffffff7fffff975deb41b3a6057c3c432146526551', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('7d7374168ffe3471b60a857686a19475d3bfa2ff', - radix: 16)) as ECCurve_prime239v3; - - static ECCurve_prime239v3 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_prime239v3._super(domainName, curve, G, n, h, seed); - - ECCurve_prime239v3._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/prime256v1.dart b/pointycastle/lib/ecc/curves/prime256v1.dart deleted file mode 100644 index bc32d19..0000000 --- a/pointycastle/lib/ecc/curves/prime256v1.dart +++ /dev/null @@ -1,41 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.prime256v1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_prime256v1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'prime256v1', () => ECCurve_prime256v1()); - - factory ECCurve_prime256v1() => constructFpStandardCurve( - 'prime256v1', ECCurve_prime256v1._make, - q: BigInt.parse('ffffffff00000001000000000000000000000000ffffffffffffffffffffffff', - radix: 16), - a: BigInt.parse( - 'ffffffff00000001000000000000000000000000fffffffffffffffffffffffc', - radix: 16), - b: BigInt.parse( - '5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b', - radix: 16), - g: BigInt.parse( - '036b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296', - radix: 16), - n: BigInt.parse( - 'ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('c49d360886e704936a6678e1139d26b7819f7e90', - radix: 16)) as ECCurve_prime256v1; - - static ECCurve_prime256v1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_prime256v1._super(domainName, curve, G, n, h, seed); - - ECCurve_prime256v1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp112r1.dart b/pointycastle/lib/ecc/curves/secp112r1.dart deleted file mode 100644 index 91031ed..0000000 --- a/pointycastle/lib/ecc/curves/secp112r1.dart +++ /dev/null @@ -1,34 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp112r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp112r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp112r1', () => ECCurve_secp112r1()); - - factory ECCurve_secp112r1() => - constructFpStandardCurve('secp112r1', ECCurve_secp112r1._make, - q: BigInt.parse('db7c2abf62e35e668076bead208b', radix: 16), - a: BigInt.parse('db7c2abf62e35e668076bead2088', radix: 16), - b: BigInt.parse('659ef8ba043916eede8911702b22', radix: 16), - g: BigInt.parse( - '0409487239995a5ee76b55f9c2f098a89ce5af8724c0a23e0e0ff77500', - radix: 16), - n: BigInt.parse('db7c2abf62e35e7628dfac6561c5', radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('00f50b028e4d696e676875615175290472783fb1', - radix: 16)) as ECCurve_secp112r1; - - static ECCurve_secp112r1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_secp112r1._super(domainName, curve, G, n, h, seed); - - ECCurve_secp112r1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp112r2.dart b/pointycastle/lib/ecc/curves/secp112r2.dart deleted file mode 100644 index ae47526..0000000 --- a/pointycastle/lib/ecc/curves/secp112r2.dart +++ /dev/null @@ -1,34 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp112r2; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp112r2 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp112r2', () => ECCurve_secp112r2()); - - factory ECCurve_secp112r2() => - constructFpStandardCurve('secp112r2', ECCurve_secp112r2._make, - q: BigInt.parse('db7c2abf62e35e668076bead208b', radix: 16), - a: BigInt.parse('6127c24c05f38a0aaaf65c0ef02c', radix: 16), - b: BigInt.parse('51def1815db5ed74fcc34c85d709', radix: 16), - g: BigInt.parse( - '044ba30ab5e892b4e1649dd0928643adcd46f5882e3747def36e956e97', - radix: 16), - n: BigInt.parse('36df0aafd8b8d7597ca10520d04b', radix: 16), - h: BigInt.parse('4', radix: 16), - seed: BigInt.parse('002757a1114d696e6768756151755316c05e0bd4', - radix: 16)) as ECCurve_secp112r2; - - static ECCurve_secp112r2 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_secp112r2._super(domainName, curve, G, n, h, seed); - - ECCurve_secp112r2._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp128r1.dart b/pointycastle/lib/ecc/curves/secp128r1.dart deleted file mode 100644 index 132f496..0000000 --- a/pointycastle/lib/ecc/curves/secp128r1.dart +++ /dev/null @@ -1,34 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp128r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp128r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp128r1', () => ECCurve_secp128r1()); - - factory ECCurve_secp128r1() => constructFpStandardCurve( - 'secp128r1', ECCurve_secp128r1._make, - q: BigInt.parse('fffffffdffffffffffffffffffffffff', radix: 16), - a: BigInt.parse('fffffffdfffffffffffffffffffffffc', radix: 16), - b: BigInt.parse('e87579c11079f43dd824993c2cee5ed3', radix: 16), - g: BigInt.parse( - '04161ff7528b899b2d0c28607ca52c5b86cf5ac8395bafeb13c02da292dded7a83', - radix: 16), - n: BigInt.parse('fffffffe0000000075a30d1b9038a115', radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('000e0d4d696e6768756151750cc03a4473d03679', - radix: 16)) as ECCurve_secp128r1; - - static ECCurve_secp128r1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_secp128r1._super(domainName, curve, G, n, h, seed); - - ECCurve_secp128r1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp128r2.dart b/pointycastle/lib/ecc/curves/secp128r2.dart deleted file mode 100644 index 88508f6..0000000 --- a/pointycastle/lib/ecc/curves/secp128r2.dart +++ /dev/null @@ -1,34 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp128r2; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp128r2 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp128r2', () => ECCurve_secp128r2()); - - factory ECCurve_secp128r2() => constructFpStandardCurve( - 'secp128r2', ECCurve_secp128r2._make, - q: BigInt.parse('fffffffdffffffffffffffffffffffff', radix: 16), - a: BigInt.parse('d6031998d1b3bbfebf59cc9bbff9aee1', radix: 16), - b: BigInt.parse('5eeefca380d02919dc2c6558bb6d8a5d', radix: 16), - g: BigInt.parse( - '047b6aa5d85e572983e6fb32a7cdebc14027b6916a894d3aee7106fe805fc34b44', - radix: 16), - n: BigInt.parse('3fffffff7fffffffbe0024720613b5a3', radix: 16), - h: BigInt.parse('4', radix: 16), - seed: BigInt.parse('004d696e67687561517512d8f03431fce63b88f4', - radix: 16)) as ECCurve_secp128r2; - - static ECCurve_secp128r2 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_secp128r2._super(domainName, curve, G, n, h, seed); - - ECCurve_secp128r2._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp160k1.dart b/pointycastle/lib/ecc/curves/secp160k1.dart deleted file mode 100644 index 889a3bc..0000000 --- a/pointycastle/lib/ecc/curves/secp160k1.dart +++ /dev/null @@ -1,33 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp160k1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp160k1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp160k1', () => ECCurve_secp160k1()); - - factory ECCurve_secp160k1() => constructFpStandardCurve( - 'secp160k1', ECCurve_secp160k1._make, - q: BigInt.parse('fffffffffffffffffffffffffffffffeffffac73', radix: 16), - a: BigInt.parse('0', radix: 16), - b: BigInt.parse('7', radix: 16), - g: BigInt.parse( - '043b4c382ce37aa192a4019e763036f4f5dd4d7ebb938cf935318fdced6bc28286531733c3f03c4fee', - radix: 16), - n: BigInt.parse('100000000000000000001b8fa16dfab9aca16b6b3', radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_secp160k1; - - static ECCurve_secp160k1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List? seed) => - ECCurve_secp160k1._super(domainName, curve, G, n, h, seed); - - ECCurve_secp160k1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp160r1.dart b/pointycastle/lib/ecc/curves/secp160r1.dart deleted file mode 100644 index 6692d23..0000000 --- a/pointycastle/lib/ecc/curves/secp160r1.dart +++ /dev/null @@ -1,34 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp160r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp160r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp160r1', () => ECCurve_secp160r1()); - - factory ECCurve_secp160r1() => constructFpStandardCurve( - 'secp160r1', ECCurve_secp160r1._make, - q: BigInt.parse('ffffffffffffffffffffffffffffffff7fffffff', radix: 16), - a: BigInt.parse('ffffffffffffffffffffffffffffffff7ffffffc', radix: 16), - b: BigInt.parse('1c97befc54bd7a8b65acf89f81d4d4adc565fa45', radix: 16), - g: BigInt.parse( - '044a96b5688ef573284664698968c38bb913cbfc8223a628553168947d59dcc912042351377ac5fb32', - radix: 16), - n: BigInt.parse('100000000000000000001f4c8f927aed3ca752257', radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('1053cde42c14d696e67687561517533bf3f83345', - radix: 16)) as ECCurve_secp160r1; - - static ECCurve_secp160r1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_secp160r1._super(domainName, curve, G, n, h, seed); - - ECCurve_secp160r1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp160r2.dart b/pointycastle/lib/ecc/curves/secp160r2.dart deleted file mode 100644 index a43e3dc..0000000 --- a/pointycastle/lib/ecc/curves/secp160r2.dart +++ /dev/null @@ -1,34 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp160r2; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp160r2 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp160r2', () => ECCurve_secp160r2()); - - factory ECCurve_secp160r2() => constructFpStandardCurve( - 'secp160r2', ECCurve_secp160r2._make, - q: BigInt.parse('fffffffffffffffffffffffffffffffeffffac73', radix: 16), - a: BigInt.parse('fffffffffffffffffffffffffffffffeffffac70', radix: 16), - b: BigInt.parse('b4e134d3fb59eb8bab57274904664d5af50388ba', radix: 16), - g: BigInt.parse( - '0452dcb034293a117e1f4ff11b30f7199d3144ce6dfeaffef2e331f296e071fa0df9982cfea7d43f2e', - radix: 16), - n: BigInt.parse('100000000000000000000351ee786a818f3a1a16b', radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('b99b99b099b323e02709a4d696e6768756151751', - radix: 16)) as ECCurve_secp160r2; - - static ECCurve_secp160r2 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_secp160r2._super(domainName, curve, G, n, h, seed); - - ECCurve_secp160r2._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp192k1.dart b/pointycastle/lib/ecc/curves/secp192k1.dart deleted file mode 100644 index 34ebf1a..0000000 --- a/pointycastle/lib/ecc/curves/secp192k1.dart +++ /dev/null @@ -1,35 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp192k1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp192k1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp192k1', () => ECCurve_secp192k1()); - - factory ECCurve_secp192k1() => constructFpStandardCurve( - 'secp192k1', ECCurve_secp192k1._make, - q: BigInt.parse('fffffffffffffffffffffffffffffffffffffffeffffee37', - radix: 16), - a: BigInt.parse('0', radix: 16), - b: BigInt.parse('3', radix: 16), - g: BigInt.parse( - '04db4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d', - radix: 16), - n: BigInt.parse('fffffffffffffffffffffffe26f2fc170f69466a74defd8d', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_secp192k1; - - static ECCurve_secp192k1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List? seed) => - ECCurve_secp192k1._super(domainName, curve, G, n, h, seed); - - ECCurve_secp192k1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp192r1.dart b/pointycastle/lib/ecc/curves/secp192r1.dart deleted file mode 100644 index b1cdee2..0000000 --- a/pointycastle/lib/ecc/curves/secp192r1.dart +++ /dev/null @@ -1,38 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp192r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp192r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp192r1', () => ECCurve_secp192r1()); - - factory ECCurve_secp192r1() => constructFpStandardCurve( - 'secp192r1', ECCurve_secp192r1._make, - q: BigInt.parse('fffffffffffffffffffffffffffffffeffffffffffffffff', - radix: 16), - a: BigInt.parse('fffffffffffffffffffffffffffffffefffffffffffffffc', - radix: 16), - b: BigInt.parse('64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1', - radix: 16), - g: BigInt.parse( - '04188da80eb03090f67cbf20eb43a18800f4ff0afd82ff101207192b95ffc8da78631011ed6b24cdd573f977a11e794811', - radix: 16), - n: BigInt.parse('ffffffffffffffffffffffff99def836146bc9b1b4d22831', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('3045ae6fc8422f64ed579528d38120eae12196d5', - radix: 16)) as ECCurve_secp192r1; - - static ECCurve_secp192r1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_secp192r1._super(domainName, curve, G, n, h, seed); - - ECCurve_secp192r1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp224k1.dart b/pointycastle/lib/ecc/curves/secp224k1.dart deleted file mode 100644 index 32e87a5..0000000 --- a/pointycastle/lib/ecc/curves/secp224k1.dart +++ /dev/null @@ -1,37 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp224k1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp224k1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp224k1', () => ECCurve_secp224k1()); - - factory ECCurve_secp224k1() => constructFpStandardCurve( - 'secp224k1', ECCurve_secp224k1._make, - q: BigInt.parse( - 'fffffffffffffffffffffffffffffffffffffffffffffffeffffe56d', - radix: 16), - a: BigInt.parse('0', radix: 16), - b: BigInt.parse('5', radix: 16), - g: BigInt.parse( - '04a1455b334df099df30fc28a169a467e9e47075a90f7e650eb6b7a45c7e089fed7fba344282cafbd6f7e319f7c0b0bd59e2ca4bdb556d61a5', - radix: 16), - n: BigInt.parse( - '10000000000000000000000000001dce8d2ec6184caf0a971769fb1f7', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_secp224k1; - - static ECCurve_secp224k1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List? seed) => - ECCurve_secp224k1._super(domainName, curve, G, n, h, seed); - - ECCurve_secp224k1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp224r1.dart b/pointycastle/lib/ecc/curves/secp224r1.dart deleted file mode 100644 index 9323ece..0000000 --- a/pointycastle/lib/ecc/curves/secp224r1.dart +++ /dev/null @@ -1,42 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp224r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp224r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp224r1', () => ECCurve_secp224r1()); - - factory ECCurve_secp224r1() => constructFpStandardCurve( - 'secp224r1', ECCurve_secp224r1._make, - q: BigInt.parse( - 'ffffffffffffffffffffffffffffffff000000000000000000000001', - radix: 16), - a: BigInt.parse( - 'fffffffffffffffffffffffffffffffefffffffffffffffffffffffe', - radix: 16), - b: BigInt.parse( - 'b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4', - radix: 16), - g: BigInt.parse( - '04b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34', - radix: 16), - n: BigInt.parse( - 'ffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('bd71344799d5c7fcdc45b59fa3b9ab8f6a948bc5', - radix: 16)) as ECCurve_secp224r1; - - static ECCurve_secp224r1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_secp224r1._super(domainName, curve, G, n, h, seed); - - ECCurve_secp224r1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp256k1.dart b/pointycastle/lib/ecc/curves/secp256k1.dart deleted file mode 100644 index 39952bf..0000000 --- a/pointycastle/lib/ecc/curves/secp256k1.dart +++ /dev/null @@ -1,37 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp256k1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp256k1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp256k1', () => ECCurve_secp256k1()); - - factory ECCurve_secp256k1() => constructFpStandardCurve( - 'secp256k1', ECCurve_secp256k1._make, - q: BigInt.parse( - 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f', - radix: 16), - a: BigInt.parse('0', radix: 16), - b: BigInt.parse('7', radix: 16), - g: BigInt.parse( - '0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8', - radix: 16), - n: BigInt.parse( - 'fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: null) as ECCurve_secp256k1; - - static ECCurve_secp256k1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List? seed) => - ECCurve_secp256k1._super(domainName, curve, G, n, h, seed); - - ECCurve_secp256k1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp256r1.dart b/pointycastle/lib/ecc/curves/secp256r1.dart deleted file mode 100644 index d17eabf..0000000 --- a/pointycastle/lib/ecc/curves/secp256r1.dart +++ /dev/null @@ -1,41 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp256r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp256r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp256r1', () => ECCurve_secp256r1()); - - factory ECCurve_secp256r1() => constructFpStandardCurve( - 'secp256r1', ECCurve_secp256r1._make, - q: BigInt.parse('ffffffff00000001000000000000000000000000ffffffffffffffffffffffff', - radix: 16), - a: BigInt.parse( - 'ffffffff00000001000000000000000000000000fffffffffffffffffffffffc', - radix: 16), - b: BigInt.parse( - '5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b', - radix: 16), - g: BigInt.parse( - '046b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c2964fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5', - radix: 16), - n: BigInt.parse( - 'ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('c49d360886e704936a6678e1139d26b7819f7e90', - radix: 16)) as ECCurve_secp256r1; - - static ECCurve_secp256r1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_secp256r1._super(domainName, curve, G, n, h, seed); - - ECCurve_secp256r1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp384r1.dart b/pointycastle/lib/ecc/curves/secp384r1.dart deleted file mode 100644 index c6c48c6..0000000 --- a/pointycastle/lib/ecc/curves/secp384r1.dart +++ /dev/null @@ -1,41 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp384r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp384r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp384r1', () => ECCurve_secp384r1()); - - factory ECCurve_secp384r1() => constructFpStandardCurve( - 'secp384r1', ECCurve_secp384r1._make, - q: BigInt.parse('fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff', - radix: 16), - a: BigInt.parse( - 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc', - radix: 16), - b: BigInt.parse( - 'b3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef', - radix: 16), - g: BigInt.parse( - '04aa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab73617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f', - radix: 16), - n: BigInt.parse( - 'ffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('a335926aa319a27a1d00896a6773a4827acdac73', - radix: 16)) as ECCurve_secp384r1; - - static ECCurve_secp384r1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_secp384r1._super(domainName, curve, G, n, h, seed); - - ECCurve_secp384r1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/curves/secp521r1.dart b/pointycastle/lib/ecc/curves/secp521r1.dart deleted file mode 100644 index be2da27..0000000 --- a/pointycastle/lib/ecc/curves/secp521r1.dart +++ /dev/null @@ -1,41 +0,0 @@ -// See file LICENSE for more information. - -library impl.ec_domain_parameters.secp521r1; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// ignore: camel_case_types -class ECCurve_secp521r1 extends ECDomainParametersImpl { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - ECDomainParameters, 'secp521r1', () => ECCurve_secp521r1()); - - factory ECCurve_secp521r1() => constructFpStandardCurve( - 'secp521r1', ECCurve_secp521r1._make, - q: BigInt.parse('1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', - radix: 16), - a: BigInt.parse( - '1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc', - radix: 16), - b: BigInt.parse( - '51953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00', - radix: 16), - g: BigInt.parse( - '0400c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650', - radix: 16), - n: BigInt.parse( - '1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409', - radix: 16), - h: BigInt.parse('1', radix: 16), - seed: BigInt.parse('d09e8800291cb85396cc6717393284aaa0da64ba', - radix: 16)) as ECCurve_secp521r1; - - static ECCurve_secp521r1 _make(String domainName, ECCurve curve, ECPoint G, - BigInt n, BigInt h, List seed) => - ECCurve_secp521r1._super(domainName, curve, G, n, h, seed); - - ECCurve_secp521r1._super(super.domainName, super.curve, super.G, super.n, - BigInt super._h, List super.seed); -} diff --git a/pointycastle/lib/ecc/ecc_base.dart b/pointycastle/lib/ecc/ecc_base.dart deleted file mode 100644 index c11d34d..0000000 --- a/pointycastle/lib/ecc/ecc_base.dart +++ /dev/null @@ -1,280 +0,0 @@ -// See file LICENSE for more information. - -library impl.ecc.ecc_base; -//TODO I think this stuff might be moved to src/impl - -import 'dart:typed_data'; - -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/src/utils.dart' as utils; - -/// Implementation of [ECDomainParameters] -class ECDomainParametersImpl implements ECDomainParameters { - @override - final String domainName; - @override - final ECCurve curve; - @override - final List? seed; - @override - final ECPoint G; - @override - final BigInt n; - BigInt? _h; - - ECDomainParametersImpl(this.domainName, this.curve, this.G, this.n, - [this._h, this.seed]) { - _h ??= BigInt.one; - } - - BigInt? get h => _h; -} - -/// Base implementation for [ECFieldElement] -abstract class ECFieldElementBase implements ECFieldElement { - @override - BigInt? toBigInteger(); - - @override - String get fieldName; - - @override - int get fieldSize; - - @override - int get byteLength => (fieldSize + 7) ~/ 8; - - @override - ECFieldElementBase operator +(covariant ECFieldElementBase b); - - @override - ECFieldElementBase operator -(covariant ECFieldElementBase b); - - @override - ECFieldElementBase operator *(covariant ECFieldElementBase b); - - @override - ECFieldElementBase operator /(covariant ECFieldElementBase b); - - @override - ECFieldElementBase operator -(); - - @override - ECFieldElementBase invert(); - - @override - ECFieldElementBase square(); - - @override - ECFieldElementBase? sqrt(); - - @override - String toString() => toBigInteger().toString(); -} - -/// Base implementation for [ECPoint] -abstract class ECPointBase implements ECPoint { - @override - final ECCurveBase curve; - @override - final ECFieldElementBase? x; - @override - final ECFieldElementBase? y; - @override - final bool isCompressed; - final ECMultiplier _multiplier; - - PreCompInfo? _preCompInfo; - - ECPointBase(this.curve, this.x, this.y, this.isCompressed, - [this._multiplier = _fpNafMultiplier]); - - @override - bool get isInfinity => x == null && y == null; - - set preCompInfo(PreCompInfo preCompInfo) { - _preCompInfo = preCompInfo; - } - - @override - bool operator ==(Object other) { - if (other is ECPointBase) { - if (isInfinity) { - return other.isInfinity; - } - return x == other.x && y == other.y; - } - return false; - } - - @override - String toString() => '($x,$y)'; - - @override - int get hashCode { - if (isInfinity) { - return 0; - } - return x.hashCode ^ y.hashCode; - } - - @override - Uint8List getEncoded([bool compressed = true]); - - @override - ECPointBase? operator +(covariant ECPointBase? b); - - @override - ECPointBase? operator -(covariant ECPointBase b); - - @override - ECPointBase operator -(); - - @override - ECPointBase? twice(); - - /// Multiplies this ECPoint by the given number. - /// @param k The multiplicator. - /// @return k * this. - @override - ECPointBase? operator *(BigInt? k) { - if (k!.sign < 0) { - throw ArgumentError('The multiplicator cannot be negative'); - } - - if (isInfinity) { - return this; - } - - if (k.sign == 0) { - return curve.infinity; - } - - return _multiplier(this, k, _preCompInfo); - } -} - -/// Base implementation for [ECCurve] -abstract class ECCurveBase implements ECCurve { - ECFieldElementBase? _a; - ECFieldElementBase? _b; - - ECCurveBase(BigInt? a, BigInt? b) { - _a = fromBigInteger(a); - _b = fromBigInteger(b); - } - - @override - ECFieldElementBase? get a => _a; - - @override - ECFieldElementBase? get b => _b; - - @override - int get fieldSize; - - @override - ECPointBase? get infinity; - - @override - ECFieldElementBase fromBigInteger(BigInt? x); - - @override - ECPointBase createPoint(BigInt x, BigInt y, [bool withCompression = false]); - - @override - ECPointBase decompressPoint(int yTilde, BigInt x1); - - /// Decode a point on this curve from its ASN.1 encoding. The different - /// encodings are taken account of, including point compression for - /// Fp (X9.62 s 4.2.1 pg 17). - /// @return The decoded point. - @override - ECPointBase? decodePoint(List encoded) { - ECPointBase? p; - var expectedLength = (fieldSize + 7) ~/ 8; - - switch (encoded[0]) { - case 0x00: // infinity - if (encoded.length != 1) { - throw ArgumentError('Incorrect length for infinity encoding'); - } - - p = infinity; - break; - - case 0x02: // compressed - case 0x03: // compressed - if (encoded.length != (expectedLength + 1)) { - throw ArgumentError('Incorrect length for compressed encoding'); - } - - var yTilde = encoded[0] & 1; - var x1 = _fromArray(encoded, 1, expectedLength); - - p = decompressPoint(yTilde, x1); - break; - - case 0x04: // uncompressed - case 0x06: // hybrid - case 0x07: // hybrid - if (encoded.length != (2 * expectedLength + 1)) { - throw ArgumentError( - 'Incorrect length for uncompressed/hybrid encoding'); - } - - var x1 = _fromArray(encoded, 1, expectedLength); - var y1 = _fromArray(encoded, 1 + expectedLength, expectedLength); - - p = createPoint(x1, y1, false); - break; - - default: - throw ArgumentError( - 'Invalid point encoding 0x${encoded[0].toRadixString(16)}'); - } - - return p; - } - - BigInt _fromArray(List buf, int off, int length) { - return utils.decodeBigIntWithSign(1, buf.sublist(off, off + length)); - } -} - -/// Interface for classes storing precomputation data for multiplication algorithms. -abstract class PreCompInfo {} - -/// Interface for functions encapsulating a point multiplication algorithm for [ECPointBase]. Multiplies [p] by [k], i.e. [p] is -/// added [k] times to itself. -typedef ECMultiplier = ECPointBase? Function( - ECPointBase p, BigInt? k, PreCompInfo? preCompInfo); - -bool _testBit(BigInt i, int n) { - return i & (BigInt.one << n) != BigInt.zero; -} - -/// Function implementing the NAF (Non-Adjacent Form) multiplication algorithm. -ECPointBase? _fpNafMultiplier( - ECPointBase p, BigInt? k, PreCompInfo? preCompInfo) { - // TODO Probably should try to add this - // BigInt e = k.mod(n); // n == order of p - var e = k; - var h = e! * BigInt.from(3); - - var neg = -p; - ECPointBase? R = p; - - for (var i = h.bitLength - 2; i > 0; --i) { - R = R!.twice(); - - var hBit = _testBit(h, i); - var eBit = _testBit(e, i); - - if (hBit != eBit) { - R = R! + (hBit ? p : neg); - } - } - - return R; -} diff --git a/pointycastle/lib/ecc/ecc_fp.dart b/pointycastle/lib/ecc/ecc_fp.dart deleted file mode 100644 index 30c7fa5..0000000 --- a/pointycastle/lib/ecc/ecc_fp.dart +++ /dev/null @@ -1,587 +0,0 @@ -// See file LICENSE for more information. - -library impl.ecc.ecc_fp; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart' - hide ECCurveBase, ECFieldElementBase, ECPointBase; -import 'package:pointycastle/ecc/ecc_base.dart' as ecc; -import 'package:pointycastle/src/utils.dart' as utils; - -/// return index of lowest 1-bit in x, x < 2^31 */ -int _lbit(BigInt x) { - // Implementation borrowed from bignum.BigIntegerDartvm. - if (x == BigInt.zero) return -1; - var r = 0; - while ((x & BigInt.from(0xffffffff)) == BigInt.zero) { - x >>= 32; - r += 32; - } - if ((x & BigInt.from(0xffff)) == BigInt.zero) { - x >>= 16; - r += 16; - } - if ((x & BigInt.from(0xff)) == BigInt.zero) { - x >>= 8; - r += 8; - } - if ((x & BigInt.from(0xf)) == BigInt.zero) { - x >>= 4; - r += 4; - } - if ((x & BigInt.from(3)) == BigInt.zero) { - x >>= 2; - r += 2; - } - if ((x & BigInt.one) == BigInt.zero) ++r; - return r; -} - -bool _testBit(BigInt i, int n) { - return i & (BigInt.one << n) != BigInt.zero; -} - -class ECFieldElement extends ecc.ECFieldElementBase { - final BigInt? q; - final BigInt? x; - - ECFieldElement(this.q, this.x) { - if (x! >= q!) { - throw ArgumentError('Value x must be smaller than q'); - } - } - - @override - String get fieldName => 'Fp'; - @override - int get fieldSize => q!.bitLength; - - @override - BigInt? toBigInteger() => x; - - @override - ECFieldElement operator +(ECFieldElement b) => - ECFieldElement(q, (x! + b.toBigInteger()!) % q!); - @override - ECFieldElement operator -(ECFieldElement b) => - ECFieldElement(q, (x! - b.toBigInteger()!) % q!); - @override - ECFieldElement operator *(ECFieldElement b) => - ECFieldElement(q, (x! * b.toBigInteger()!) % q!); - @override - ECFieldElement operator /(ECFieldElement b) => - ECFieldElement(q, (x! * b.toBigInteger()!.modInverse(q!)) % q!); - - @override - ECFieldElement operator -() => ECFieldElement(q, -x! % q!); - - @override - ECFieldElement invert() => ECFieldElement(q, x!.modInverse(q!)); - @override - ECFieldElement square() => ECFieldElement(q, x!.modPow(BigInt.two, q!)); - - // D.1.4 91 - /// return a sqrt root - the routine verifies that the calculation - /// returns the right value - if none exists it returns null. - @override - ECFieldElement? sqrt() { - if (!_testBit(q!, 0)) { - throw UnimplementedError('Not implemented yet'); - } - - // p % 4 == 3 - if (_testBit(q!, 1)) { - // z = g^(u+1) + p, p = 4u + 3 - var z = ECFieldElement(q, x!.modPow((q! >> 2) + BigInt.one, q!)); - return z.square() == this ? z : null; - } - - // p % 4 == 1 - var qMinusOne = q! - BigInt.one; - - var legendreExponent = qMinusOne >> 1; - if (x!.modPow(legendreExponent, q!) != BigInt.one) { - return null; - } - - var u = qMinusOne >> 2; - var k = (u << 1) + BigInt.one; - - var Q = x!; - var fourQ = (Q >> 2) % q!; - - BigInt U, V; - var rand = SecureRandom(); - do { - BigInt? P; - do { - P = rand.nextBigInteger(q!.bitLength); - } while ((P >= q!) || - (((P * P) - fourQ).modPow(legendreExponent, q!) != qMinusOne)); - - var result = _lucasSequence(q!, P, Q, k); - U = result[0]; - V = result[1]; - - if (((V * V) % q!) == fourQ) { - // Integer division by 2, mod q - if (_testBit(V, 0)) { - V = V + q!; - } - - V = V >> 1; - - //assert V.multiply(V).mod(q).equals(x); - - return ECFieldElement(q, V); - } - } while ((U == BigInt.one) || (U == qMinusOne)); - - return null; - } - - List _lucasSequence(BigInt p, BigInt P, BigInt Q, BigInt k) { - var n = k.bitLength; - var s = _lbit(k); - - var uh = BigInt.one; - var vl = BigInt.two; - var vh = P; - var ql = BigInt.one; - var qh = BigInt.one; - - for (var j = n - 1; j >= (s + 1); j--) { - ql = (ql * qh) % p; - - if (_testBit(k, j)) { - qh = (ql * Q) % p; - uh = (uh * vh) % p; - vl = ((vh * vl) - (P * ql)) % p; - vh = ((vh * vh) - (qh << 1)) % p; - } else { - qh = ql; - uh = ((uh * vl) - ql) % p; - vh = ((vh * vl) - (P * ql)) % p; - vl = ((vl * vl) - (ql << 1)) % p; - } - } - - ql = (ql * qh) % p; - qh = (ql * Q) % p; - uh = ((uh * vl) - ql) % p; - vl = ((vh * vl) - (P * ql)) % p; - ql = (ql * qh) % p; - - for (var j = 1; j <= s; j++) { - uh = (uh * vl) % p; - vl = ((vl * vl) - (ql << 1)) % p; - ql = (ql * ql) % p; - } - - return [uh, vl]; - } - - @override - bool operator ==(Object other) { - if (other is ECFieldElement) { - return (q == other.q) && (x == other.x); - } - return false; - } - - @override - int get hashCode => q.hashCode ^ x.hashCode; -} - -/// Elliptic curve points over Fp -class ECPoint extends ecc.ECPointBase { - /// Create a point that encodes with or without point compression. - /// - /// @param curve the curve to use - /// @param x affine x co-ordinate - /// @param y affine y co-ordinate - /// @param withCompression if true encode with point compression - ECPoint(ECCurve curve, ECFieldElement? x, ECFieldElement? y, - [bool withCompression = false]) - : super(curve, x, y, withCompression, _wNafMultiplier) { - if ((x != null && y == null) || (x == null && y != null)) { - throw ArgumentError('Exactly one of the field elements is null'); - } - } - - /// return the field element encoded with point compression. (S 4.3.6) - @override - Uint8List getEncoded([bool compressed = true]) { - if (isInfinity) { - return Uint8List.fromList([1]); - } - - var qLength = x!.byteLength; - if (compressed) { - int pc; - - if (_testBit(y!.toBigInteger()!, 0)) { - pc = 0x03; - } else { - pc = 0x02; - } - - var X = _x9IntegerToBytes(x!.toBigInteger(), qLength); - var po = Uint8List(X.length + 1); - - po[0] = pc.toInt(); - po.setAll(1, X); - - return po; - } else { - var X = _x9IntegerToBytes(x!.toBigInteger(), qLength); - var Y = _x9IntegerToBytes(y!.toBigInteger(), qLength); - var po = Uint8List(X.length + Y.length + 1); - - po[0] = 0x04; - po.setAll(1, X); - po.setAll(X.length + 1, Y); - - return po; - } - } - - // B.3 pg 62 - @override - ECPoint? operator +(ECPoint? b) { - if (isInfinity) { - return b; - } - - if (b!.isInfinity) { - return this; - } - - // Check if b = this or b = -this - if (x == b.x) { - if (y == b.y) { - // this = b, i.e. this must be doubled - return twice(); - } - - // this = -b, i.e. the result is the point at infinity - return curve.infinity as ECPoint?; - } - - var gamma = (b.y! - y!) / (b.x! - x!); - - var x3 = (gamma.square() - x!) - b.x!; - var y3 = (gamma * (x! - x3)) - y!; - - return ECPoint(curve as ECCurve, x3 as ECFieldElement?, - y3 as ECFieldElement?, isCompressed); - } - - // B.3 pg 62 - @override - ECPoint? twice() { - if (isInfinity) { - // Twice identity element (point at infinity) is identity - return this; - } - - if (y!.toBigInteger() == BigInt.zero) { - // if y1 == 0, then (x1, y1) == (x1, -y1) - // and hence this = -this and thus 2(x1, y1) == infinity - return curve.infinity as ECPoint?; - } - - var two = curve.fromBigInteger(BigInt.two); - var three = curve.fromBigInteger(BigInt.from(3)); - var gamma = ((x!.square() * three) + curve.a!) / (y! * two); - - var x3 = gamma.square() - (x! * two); - var y3 = (gamma * (x! - x3)) - y!; - - return ECPoint(curve as ECCurve, x3 as ECFieldElement?, - y3 as ECFieldElement?, isCompressed); - } - - // D.3.2 pg 102 (see Note:) - @override - ECPoint? operator -(ECPoint b) { - if (b.isInfinity) { - return this; - } - - // Add -b - return this + (-b); - } - - @override - ECPoint operator -() { - return ECPoint(curve as ECCurve, x as ECFieldElement?, - -y! as ECFieldElement?, isCompressed); - } -} - -/// Elliptic curve over Fp -class ECCurve extends ecc.ECCurveBase { - final BigInt? q; - ECPoint? _infinity; - - ECCurve(this.q, BigInt? a, BigInt? b) : super(a, b) { - _infinity = ECPoint(this, null, null); - } - - @override - int get fieldSize => q!.bitLength; - @override - ECPoint? get infinity => _infinity; - - @override - ECFieldElement fromBigInteger(BigInt? x) => ECFieldElement(q, x); - @override - ECPoint createPoint(BigInt x, BigInt y, [bool withCompression = false]) => - ECPoint(this, fromBigInteger(x), fromBigInteger(y), withCompression); - - @override - ECPoint decompressPoint(int yTilde, BigInt x1) { - var x = fromBigInteger(x1); - var alpha = (x * ((x * x) + (a as ECFieldElement))) + (b as ECFieldElement); - var beta = alpha.sqrt(); - - // - // if we can't find a sqrt we haven't got a point on the - // curve - run! - // - if (beta == null) { - throw ArgumentError('Invalid point compression'); - } - - var betaValue = beta.toBigInteger()!; - var bit0 = _testBit(betaValue, 0) ? 1 : 0; - - if (bit0 != yTilde) { - // Use the other root - beta = fromBigInteger(q! - betaValue); - } - - return ECPoint(this, x, beta, true); - } - - @override - bool operator ==(Object other) { - if (other is ECCurve) { - return q == other.q && a == other.a && b == other.b; - } - return false; - } - - @override - int get hashCode => a.hashCode ^ b.hashCode ^ q.hashCode; -} - -/// Class holding precomputation data for the WNAF (Window Non-Adjacent Form) -/// algorithm. -class _WNafPreCompInfo implements PreCompInfo { - /// Array holding the precomputed [ECPoint]s used for the Window NAF multiplication. - List? preComp; - - /// Holds an [ECPoint] representing twice(this). Used for the Window NAF multiplication. - ECPoint? twiceP; -} - -/// Function implementing the WNAF (Window Non-Adjacent Form) multiplication algorithm. Multiplies [p]] by an integer [k] using -/// the Window NAF method. -ecc.ECPointBase? _wNafMultiplier( - ecc.ECPointBase p, BigInt? k, PreCompInfo? preCompInfo) { - // Ignore empty PreCompInfo or PreCompInfo of incorrect type - _WNafPreCompInfo wnafPreCompInfo; - if (preCompInfo is! _WNafPreCompInfo) { - wnafPreCompInfo = _WNafPreCompInfo(); - } else { - wnafPreCompInfo = preCompInfo; - } - - // floor(log2(k)) - var m = k!.bitLength; - - // width of the Window NAF - int width; - - // Required length of precomputation array - int reqPreCompLen; - - // Determine optimal width and corresponding length of precomputation - // array based on literature values - if (m < 13) { - width = 2; - reqPreCompLen = 1; - } else { - if (m < 41) { - width = 3; - reqPreCompLen = 2; - } else { - if (m < 121) { - width = 4; - reqPreCompLen = 4; - } else { - if (m < 337) { - width = 5; - reqPreCompLen = 8; - } else { - if (m < 897) { - width = 6; - reqPreCompLen = 16; - } else { - if (m < 2305) { - width = 7; - reqPreCompLen = 32; - } else { - width = 8; - reqPreCompLen = 127; - } - } - } - } - } - } - - // The length of the precomputation array - var preCompLen = 1; - - List? preComp = wnafPreCompInfo.preComp; - var twiceP = wnafPreCompInfo.twiceP; - - // Check if the precomputed ECPoints already exist - if (preComp == null) { - // Precomputation must be performed from scratch, create an empty - // precomputation array of desired length - preComp = List.filled(1, p as ECPoint); - } else { - // Take the already precomputed ECPoints to start with - preCompLen = preComp.length; - } - - twiceP ??= p.twice() as ECPoint?; - - if (preCompLen < reqPreCompLen) { - // Precomputation array must be made bigger, copy existing preComp - // array into the larger preComp array - var oldPreComp = preComp as List; - preComp = List.filled(reqPreCompLen, null, growable: false); - preComp.setAll(0, oldPreComp); - - for (var i = preCompLen; i < reqPreCompLen; i++) { - // Compute the ECPoints for the precomputation array. - // The values 1, 3, 5, ..., 2^(width-1)-1 times p are - // computed - preComp[i] = twiceP! + (preComp[i - 1]); - } - } - - // Compute the Window NAF of the desired width - var wnaf = _windowNaf(width, k); - var l = wnaf.length; - - // Apply the Window NAF to p using the precomputed ECPoint values. - var q = p.curve.infinity; - for (var i = l - 1; i >= 0; i--) { - q = q!.twice(); - - if (wnaf[i] != 0) { - if (wnaf[i]! > 0) { - q = q! + preComp[(wnaf[i]! - 1) ~/ 2]; - } else { - // wnaf[i] < 0 - q = q! - preComp[(-wnaf[i]! - 1) ~/ 2]!; - } - } - } - - // Set PreCompInfo in ECPoint, such that it is available for next - // multiplication. - wnafPreCompInfo.preComp = preComp.map((e) => e as ECPoint).toList(); - wnafPreCompInfo.twiceP = twiceP; - p.preCompInfo = wnafPreCompInfo; - return q; -} - -/// Computes the Window NAF (non-adjacent Form) of an integer. -/// @param width The width w of the Window NAF. The width is -/// defined as the minimal number w, such that for any -/// w consecutive digits in the resulting representation, at -/// most one is non-zero. -/// @param k The integer of which the Window NAF is computed. -/// @return The Window NAF of the given width, such that the following holds: -/// k = ∑i=0l-1 ki2i -/// , where the ki denote the elements of the -/// returned byte[]. -List _windowNaf(int width, BigInt k) { - // The window NAF is at most 1 element longer than the binary - // representation of the integer k. byte can be used instead of short or - // int unless the window width is larger than 8. For larger width use - // short or int. However, a width of more than 8 is not efficient for - // m = log2(q) smaller than 2305 Bits. Note: Values for m larger than - // 1000 Bits are currently not used in practice. - var wnaf = List.filled(k.bitLength + 1, null, growable: false); - - // 2^width as short and BigInt - var pow2wB = 1 << width; - var pow2wBI = BigInt.from(pow2wB); - - var i = 0; - - // The actual length of the WNAF - var length = 0; - - // while k >= 1 - while (k.sign > 0) { - // if k is odd - if (_testBit(k, 0)) { - // k mod 2^width - var remainder = k % pow2wBI; - - // if remainder > 2^(width - 1) - 1 - if (_testBit(remainder, width - 1)) { - wnaf[i] = remainder.toInt() - pow2wB; - } else { - wnaf[i] = remainder.toInt(); - } - - // convert to 'Java byte' - wnaf[i] = wnaf[i]! % 0x100; - if ((wnaf[i]! & 0x80) != 0) { - wnaf[i] = wnaf[i]! - 256; - } - - // wnaf[i] is now in [-2^(width-1), 2^(width-1)-1] - - k = k - BigInt.from(wnaf[i]!); - length = i; - } else { - wnaf[i] = 0; - } - - // k = k/2 - k = k >> 1; - i++; - } - - length++; - - // Reduce the WNAF array to its actual length - var wnafShort = List.filled(length, null, growable: false); - wnafShort.setAll(0, wnaf.sublist(0, length)); - return wnafShort; -} - -Uint8List _x9IntegerToBytes(BigInt? s, int qLength) { - var bytes = Uint8List.fromList(utils.encodeBigInt(s)); - - if (qLength < bytes.length) { - return bytes.sublist(bytes.length - qLength); - } else if (qLength > bytes.length) { - return Uint8List(qLength)..setAll(qLength - bytes.length, bytes); - } - - return bytes; -} diff --git a/pointycastle/lib/ecc/ecdh.dart b/pointycastle/lib/ecc/ecdh.dart deleted file mode 100644 index cbd1c7e..0000000 --- a/pointycastle/lib/ecc/ecdh.dart +++ /dev/null @@ -1,70 +0,0 @@ -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/src/platform_check/platform_check.dart'; - -/// P1363 7.2.1 ECSVDP-DH -/// -/// ECSVDP-DH is Elliptic Curve Secret Value Derivation Primitive, -/// Diffie-Hellman version. It is based on the work of [DH76], [Mil86], -/// and [Kob87]. This primitive derives a shared secret value from one -/// party's private key and another party's public key, where both have -/// the same set of EC domain parameters. If two parties correctly -/// execute this primitive, they will produce the same output. This -/// primitive can be invoked by a scheme to derive a shared secret key; -/// specifically, it may be used with the schemes ECKAS-DH1 and -/// DL/ECKAS-DH2. It assumes that the input keys are valid (see also -/// Section 7.2.2). -class ECDHBasicAgreement implements ECDHAgreement { - late ECPrivateKey key; - - @override - void init(ECPrivateKey key) { - this.key = key; - } - - @override - int getFieldSize() { - return (key.parameters!.curve.fieldSize + 7) ~/ 8; - } - - @override - BigInt calculateAgreement(ECPublicKey pubKey) { - var params = key.parameters; - if (pubKey.parameters?.curve != params?.curve) { - throw PlatformException('ECDH public key has wrong domain parameters'); - } - - var d = key.d!; - - // Always perform calculations on the exact curve specified by our private key's parameters - var Q = cleanPoint(params!.curve, pubKey.Q!); - if (Q == null || Q.isInfinity) { - throw PlatformException('Infinity is not a valid public key for ECDH'); - } - - var h = (params as ECDomainParametersImpl).h!; - - if (!(h.compareTo(BigInt.one) == 0)) { - d = (h.modInverse(params.n) * d) % params.n; - Q = Q * h; - } - - var P = (Q! * d)!; - - if (P.isInfinity) { - throw PlatformException( - 'Infinity is not a valid agreement value for ECDH'); - } - - return P.x!.toBigInteger()!; - } -} - -ECPoint? cleanPoint(ECCurve c, ECPoint p) { - var cp = p.curve; - if (c != cp) { - throw PlatformException('Point must be on the same curve'); - } - - return c.decodePoint(p.getEncoded(false)); -} diff --git a/pointycastle/lib/export.dart b/pointycastle/lib/export.dart deleted file mode 100644 index 9933d4a..0000000 --- a/pointycastle/lib/export.dart +++ /dev/null @@ -1,154 +0,0 @@ -// See file LICENSE for more information. - -/// This library exports all implementation classes from the entire PointyCastle -/// project. -library export; - -export 'package:pointycastle/api.dart'; -export 'package:pointycastle/impl.dart'; - -// cipher implementations -export 'package:pointycastle/adapters/stream_cipher_as_block_cipher.dart'; - -// asymmetric -export 'package:pointycastle/asymmetric/pkcs1.dart'; -export 'package:pointycastle/asymmetric/rsa.dart'; -export 'package:pointycastle/asymmetric/oaep.dart'; - -// block -export 'package:pointycastle/block/aes_fast.dart'; -export 'package:pointycastle/block/aes.dart'; -export 'package:pointycastle/block/desede_engine.dart'; -export 'package:pointycastle/block/rc2_engine.dart'; -export 'package:pointycastle/block/blowfish.dart'; -export 'package:pointycastle/block/camellia.dart'; -export 'package:pointycastle/block/twofish.dart'; - -// block/modes -export 'package:pointycastle/block/modes/cbc.dart'; -export 'package:pointycastle/block/modes/cfb.dart'; -export 'package:pointycastle/block/modes/ctr.dart'; -export 'package:pointycastle/block/modes/ecb.dart'; -export 'package:pointycastle/block/modes/gctr.dart'; -export 'package:pointycastle/block/modes/ofb.dart'; -export 'package:pointycastle/block/modes/gcm.dart'; -export 'package:pointycastle/block/modes/ccm.dart'; -export 'package:pointycastle/block/modes/sic.dart'; -export 'package:pointycastle/block/modes/ige.dart'; - -// digests -export 'package:pointycastle/digests/blake2b.dart'; -export 'package:pointycastle/digests/keccak.dart'; -export 'package:pointycastle/digests/sha3.dart'; -export 'package:pointycastle/digests/shake.dart'; -export 'package:pointycastle/digests/cshake.dart'; -export 'package:pointycastle/digests/md2.dart'; -export 'package:pointycastle/digests/md4.dart'; -export 'package:pointycastle/digests/md5.dart'; -export 'package:pointycastle/digests/ripemd128.dart'; -export 'package:pointycastle/digests/ripemd160.dart'; -export 'package:pointycastle/digests/ripemd256.dart'; -export 'package:pointycastle/digests/ripemd320.dart'; -export 'package:pointycastle/digests/sha1.dart'; -export 'package:pointycastle/digests/sha224.dart'; -export 'package:pointycastle/digests/sha256.dart'; -export 'package:pointycastle/digests/sha384.dart'; -export 'package:pointycastle/digests/sha512.dart'; -export 'package:pointycastle/digests/sha512t.dart'; -export 'package:pointycastle/digests/tiger.dart'; -export 'package:pointycastle/digests/whirlpool.dart'; -export 'package:pointycastle/digests/sm3.dart'; - -// ecc -export 'package:pointycastle/ecc/api.dart'; -export 'package:pointycastle/ecc/ecc_base.dart'; -//TODO resolve naming overlap here: -//export 'package:pointycastle/ecc/ecc_fp.dart' as fp; - -// key_derivators -export 'package:pointycastle/key_derivators/api.dart'; -export 'package:pointycastle/key_derivators/hkdf.dart'; -export 'package:pointycastle/key_derivators/pbkdf2.dart'; -export 'package:pointycastle/key_derivators/scrypt.dart'; -export 'package:pointycastle/key_derivators/argon2.dart'; -export 'package:pointycastle/key_derivators/pkcs12_parameter_generator.dart'; -export 'package:pointycastle/key_derivators/pkcs5s1_parameter_generator.dart'; - -// key_generators -export 'package:pointycastle/key_generators/api.dart'; -export 'package:pointycastle/key_generators/ec_key_generator.dart'; -export 'package:pointycastle/key_generators/rsa_key_generator.dart'; - -// macs -export 'package:pointycastle/macs/hmac.dart'; -export 'package:pointycastle/macs/cmac.dart'; -export 'package:pointycastle/macs/poly1305.dart'; -export 'package:pointycastle/macs/cbc_block_cipher_mac.dart'; - -// paddings -export 'package:pointycastle/padded_block_cipher/padded_block_cipher_impl.dart'; -export 'package:pointycastle/paddings/pkcs7.dart'; -export 'package:pointycastle/paddings/iso7816d4.dart'; - -// random -export 'package:pointycastle/random/auto_seed_block_ctr_random.dart'; -export 'package:pointycastle/random/block_ctr_random.dart'; -export 'package:pointycastle/random/fortuna_random.dart'; - -// signers -export 'package:pointycastle/signers/ecdsa_signer.dart'; -export 'package:pointycastle/signers/rsa_signer.dart'; -export 'package:pointycastle/signers/pss_signer.dart'; - -// stream -export 'package:pointycastle/stream/ctr.dart'; -export 'package:pointycastle/stream/salsa20.dart'; -export 'package:pointycastle/stream/chacha20.dart'; -export 'package:pointycastle/stream/chacha7539.dart'; -export 'package:pointycastle/stream/chacha20poly1305.dart'; -export 'package:pointycastle/stream/sic.dart'; -export 'package:pointycastle/stream/eax.dart'; -export 'package:pointycastle/stream/rc4_engine.dart'; - -// ecc curves -export 'package:pointycastle/ecc/curves/brainpoolp160r1.dart'; -export 'package:pointycastle/ecc/curves/brainpoolp160t1.dart'; -export 'package:pointycastle/ecc/curves/brainpoolp192r1.dart'; -export 'package:pointycastle/ecc/curves/brainpoolp192t1.dart'; -export 'package:pointycastle/ecc/curves/brainpoolp224r1.dart'; -export 'package:pointycastle/ecc/curves/brainpoolp224t1.dart'; -export 'package:pointycastle/ecc/curves/brainpoolp256r1.dart'; -export 'package:pointycastle/ecc/curves/brainpoolp256t1.dart'; -export 'package:pointycastle/ecc/curves/brainpoolp320r1.dart'; -export 'package:pointycastle/ecc/curves/brainpoolp320t1.dart'; -export 'package:pointycastle/ecc/curves/brainpoolp384r1.dart'; -export 'package:pointycastle/ecc/curves/brainpoolp384t1.dart'; -export 'package:pointycastle/ecc/curves/brainpoolp512r1.dart'; -export 'package:pointycastle/ecc/curves/brainpoolp512t1.dart'; -export 'package:pointycastle/ecc/curves/gostr3410_2001_cryptopro_a.dart'; -export 'package:pointycastle/ecc/curves/gostr3410_2001_cryptopro_b.dart'; -export 'package:pointycastle/ecc/curves/gostr3410_2001_cryptopro_c.dart'; -export 'package:pointycastle/ecc/curves/gostr3410_2001_cryptopro_xcha.dart'; -export 'package:pointycastle/ecc/curves/gostr3410_2001_cryptopro_xchb.dart'; -export 'package:pointycastle/ecc/curves/prime192v1.dart'; -export 'package:pointycastle/ecc/curves/prime192v2.dart'; -export 'package:pointycastle/ecc/curves/prime192v3.dart'; -export 'package:pointycastle/ecc/curves/prime239v1.dart'; -export 'package:pointycastle/ecc/curves/prime239v2.dart'; -export 'package:pointycastle/ecc/curves/prime239v3.dart'; -export 'package:pointycastle/ecc/curves/prime256v1.dart'; -export 'package:pointycastle/ecc/curves/secp112r1.dart'; -export 'package:pointycastle/ecc/curves/secp112r2.dart'; -export 'package:pointycastle/ecc/curves/secp128r1.dart'; -export 'package:pointycastle/ecc/curves/secp128r2.dart'; -export 'package:pointycastle/ecc/curves/secp160k1.dart'; -export 'package:pointycastle/ecc/curves/secp160r1.dart'; -export 'package:pointycastle/ecc/curves/secp160r2.dart'; -export 'package:pointycastle/ecc/curves/secp192k1.dart'; -export 'package:pointycastle/ecc/curves/secp192r1.dart'; -export 'package:pointycastle/ecc/curves/secp224k1.dart'; -export 'package:pointycastle/ecc/curves/secp224r1.dart'; -export 'package:pointycastle/ecc/curves/secp256k1.dart'; -export 'package:pointycastle/ecc/curves/secp256r1.dart'; -export 'package:pointycastle/ecc/curves/secp384r1.dart'; -export 'package:pointycastle/ecc/curves/secp521r1.dart'; diff --git a/pointycastle/lib/impl.dart b/pointycastle/lib/impl.dart deleted file mode 100644 index e3cce50..0000000 --- a/pointycastle/lib/impl.dart +++ /dev/null @@ -1,13 +0,0 @@ -// See file LICENSE for more information. - -/// This library contains all out-of-the-box implementations of the interfaces provided in the API -/// which are compatible with client and server sides. -library impl; - -// cipher implementations - -// asymmetric -export 'package:pointycastle/asymmetric/api.dart'; -export 'package:pointycastle/ecc/api.dart'; -export 'package:pointycastle/key_derivators/api.dart'; -export 'package:pointycastle/key_generators/api.dart'; diff --git a/pointycastle/lib/key_derivators/api.dart b/pointycastle/lib/key_derivators/api.dart deleted file mode 100644 index 84e24c7..0000000 --- a/pointycastle/lib/key_derivators/api.dart +++ /dev/null @@ -1,126 +0,0 @@ -// See file LICENSE for more information. - -library api.key_derivators; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/ecc/api.dart'; - -/// [CipherParameters] used by PBKDF2. -class Pbkdf2Parameters extends CipherParameters { - final Uint8List salt; - final int iterationCount; - final int desiredKeyLength; - - Pbkdf2Parameters(this.salt, this.iterationCount, this.desiredKeyLength); -} - -/// [CipherParameters] for the scrypt password based key derivation function. -class ScryptParameters implements CipherParameters { - final int N; - final int r; - final int p; - final int desiredKeyLength; - final Uint8List salt; - - ScryptParameters(this.N, this.r, this.p, this.desiredKeyLength, this.salt); -} - -/// Generates [CipherParameters] for HKDF key derivation function. -class HkdfParameters extends CipherParameters { - final Uint8List ikm; // the input keying material or seed - final int desiredKeyLength; - final Uint8List? - salt; // the salt to use, may be null for a salt for hashLen zeros - final Uint8List? - info; // the info to use, may be null for an info field of zero bytes - final bool skipExtract; - - HkdfParameters._(this.ikm, this.desiredKeyLength, - [this.salt, this.info, this.skipExtract = false]); - - factory HkdfParameters(ikm, desiredKeyLength, - [salt, info, skipExtract = false]) { - if (ikm == null) { - throw ArgumentError('IKM (input keying material) should not be null'); - } - - if (salt == null || salt.length == 0) { - salt = null; - } - - return HkdfParameters._( - ikm, desiredKeyLength, salt, info ?? Uint8List(0), skipExtract); - } -} - -/// The Argon2 parameters. -class Argon2Parameters extends CipherParameters { - static const int ARGON2_d = 0x00; - static const int ARGON2_i = 0x01; - static const int ARGON2_id = 0x02; - - static const int ARGON2_VERSION_10 = 0x10; - static const int ARGON2_VERSION_13 = 0x13; - - static const int DEFAULT_ITERATIONS = 3; - static const int DEFAULT_MEMORY_COST = 12; - static const int DEFAULT_LANES = 1; - static const int DEFAULT_TYPE = ARGON2_i; - static const int DEFAULT_VERSION = ARGON2_VERSION_13; - - final int type; - final int desiredKeyLength; - - final Uint8List _salt; - final Uint8List? _secret; - final Uint8List? _additional; - - final int iterations; - final int memory; - final int lanes; - - final int version; - - Argon2Parameters( - this.type, - this._salt, { - required this.desiredKeyLength, - Uint8List? secret, - Uint8List? additional, - this.iterations = DEFAULT_ITERATIONS, - int? memoryPowerOf2, - int? memory, - this.lanes = DEFAULT_LANES, - this.version = DEFAULT_VERSION, - }) : memory = memoryPowerOf2 != null - ? 1 << memoryPowerOf2 - : (memory ?? (1 << DEFAULT_MEMORY_COST)), - _secret = secret, - _additional = additional; - - Uint8List get salt => _salt; - - Uint8List? get secret => _secret; - - Uint8List? get additional => _additional; - - void clear() { - _salt.clear(); - _secret?.clear(); - _additional?.clear(); - } - - @override - String toString() { - return 'Argon2Parameters{ type: $type, iterations: $iterations, memory: $memory, lanes: $lanes, version: $version }'; - } -} - -class ECDHKDFParameters extends CipherParameters { - final ECPrivateKey privateKey; - final ECPublicKey publicKey; - - ECDHKDFParameters(this.privateKey, this.publicKey); -} diff --git a/pointycastle/lib/key_derivators/argon2.dart b/pointycastle/lib/key_derivators/argon2.dart deleted file mode 100644 index b34315b..0000000 --- a/pointycastle/lib/key_derivators/argon2.dart +++ /dev/null @@ -1,2 +0,0 @@ -export 'argon2_register64_impl.dart' - if (dart.library.io) 'argon2_native_int_impl.dart'; diff --git a/pointycastle/lib/key_derivators/argon2_native_int_impl.dart b/pointycastle/lib/key_derivators/argon2_native_int_impl.dart deleted file mode 100644 index 045c434..0000000 --- a/pointycastle/lib/key_derivators/argon2_native_int_impl.dart +++ /dev/null @@ -1,658 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/digests/blake2b.dart'; -import 'package:pointycastle/src/impl/base_key_derivator.dart'; -import 'package:pointycastle/src/platform_check/platform_check.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/utils.dart'; - -import 'api.dart'; - -/// Argon2 PBKDF, the winner of the 2015 Password Hashing Competition. -/// Read more: -/// - https://password-hashing.net/ -/// - https://www.ietf.org/archive/id/draft-irtf-cfrg-argon2-03.txt -/// -/// First ported to Dart by Graciliano M. Passos: -/// - https://pub.dev/packages/argon2 -/// - https://github.com/gmpassos/argon2 -/// -/// The linked project was adapted for the purposes of this project, since it -/// is a 1:1 port of BouncyCastle's Java implementation. -class Argon2BytesGenerator extends BaseKeyDerivator { - static const int ARGON2_BLOCK_SIZE = 1024; - static const int ARGON2_QWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE ~/ 8; - - static const int ARGON2_ADDRESSES_IN_BLOCK = 128; - - static const int ARGON2_PREHASH_DIGEST_LENGTH = 64; - static const int ARGON2_PREHASH_SEED_LENGTH = 72; - - static const int ARGON2_SYNC_POINTS = 4; - - /// Minimum and maximum number of lanes (degree of parallelism). - static const int MIN_PARALLELISM = 1; - static const int MAX_PARALLELISM = 16777216; - - /// Minimum and maximum digest size in bytes. - static const int MIN_OUTLEN = 4; - - /// Minimum and maximum number of passes. - static const int MIN_ITERATIONS = 1; - - //static const int M32L = 0xFFFFFFFFFFFFFFFF; - - static const int M32L = (0xFFFFFFFF << 32) + 0xFFFFFFFF; - - static final Uint8List _ZERO_BYTES = Uint8List(4); - - late Argon2Parameters _parameters; - late List<_Block> _memory; - late int _segmentLength; - late int _laneLength; - - static final FactoryConfig factoryConfig = - StaticFactoryConfig(KeyDerivator, 'argon2', () => Argon2BytesGenerator()); - - Argon2BytesGenerator() { - Platform.instance.assertFullWidthInteger(); - } - - Argon2Parameters get parameters => _parameters; - - @override - int get keySize => parameters.desiredKeyLength; - - @override - String get algorithmName => 'Argon2'; - - /// Initialise the Argon2BytesGenerator from the parameters. - /// - [param] parameters Argon2 configuration. - @override - void init(covariant Argon2Parameters parameters) { - _parameters = parameters; - - if (parameters.lanes < MIN_PARALLELISM) { - throw ArgumentError.value(parameters.lanes, 'parameters.lanes', - 'lanes must be greater than $MIN_PARALLELISM'); - } else if (parameters.lanes > MAX_PARALLELISM) { - throw ArgumentError.value(parameters.lanes, 'parameters.lanes', - 'lanes must be less than $MAX_PARALLELISM'); - } else if (parameters.memory < 2 * parameters.lanes) { - throw ArgumentError.value(parameters.memory, 'parameters.memory', - 'memory is less than: ${2 * parameters.lanes} expected ${2 * parameters.lanes}'); - } else if (parameters.iterations < MIN_ITERATIONS) { - throw ArgumentError.value(parameters.iterations, 'parameters.iterations', - 'iterations is less than: $MIN_ITERATIONS'); - } - - _doInit(parameters); - } - - @override - int deriveKey(Uint8List inp, int inpOff, Uint8List out, int outOff) { - inp = inp.sublist(inpOff); - var outLen = parameters.desiredKeyLength; - - if (outLen < MIN_OUTLEN) { - throw ArgumentError.value( - outLen, 'outLen', 'output length less than $MIN_OUTLEN'); - } - - var tmpBlockBytes = Uint8List(ARGON2_BLOCK_SIZE); - - _initialize(tmpBlockBytes, inp, outLen); - _fillMemoryBlocks(); - _digest(tmpBlockBytes, out, outOff, outLen); - - _reset(); - - return outLen; - } - - /// Clear memory. - void _reset() { - for (var i = _memory.length - 1; i >= 0; --i) { - var b = _memory[i]; - b.clear(); - } - } - - void _doInit(Argon2Parameters parameters) { - /* 2. Align memory size */ - /* Minimum memoryBlocks = 8L blocks, where L is the number of lanes */ - var memoryBlocks = parameters.memory; - - if (memoryBlocks < 2 * ARGON2_SYNC_POINTS * parameters.lanes) { - memoryBlocks = 2 * ARGON2_SYNC_POINTS * parameters.lanes; - } - - _segmentLength = memoryBlocks ~/ (parameters.lanes * ARGON2_SYNC_POINTS); - _laneLength = _segmentLength * ARGON2_SYNC_POINTS; - - /* Ensure that all segments have equal length */ - memoryBlocks = _segmentLength * (parameters.lanes * ARGON2_SYNC_POINTS); - - _initMemory(memoryBlocks); - } - - void _initMemory(int memoryBlocks) { - _memory = List<_Block>.generate(memoryBlocks, (i) => _Block()); - } - - void _fillMemoryBlocks() { - var filler = _FillBlock(); - var position = _Position(); - for (var pass = 0; pass < _parameters.iterations; ++pass) { - position.pass = pass; - - for (var slice = 0; slice < ARGON2_SYNC_POINTS; ++slice) { - position.slice = slice; - - for (var lane = 0; lane < _parameters.lanes; ++lane) { - position.lane = lane; - - _fillSegment(filler, position); - } - } - } - } - - void _fillSegment(_FillBlock filler, _Position position) { - _Block? addressBlock; - _Block? inputBlock; - - var dataIndependentAddressing = _isDataIndependentAddressing(position); - var startingIndex = _getStartingIndex(position); - var currentOffset = position.lane * _laneLength + - position.slice * _segmentLength + - startingIndex; - var prevOffset = _getPrevOffset(currentOffset); - - if (dataIndependentAddressing) { - addressBlock = filler.addressBlock.clear(); - inputBlock = filler.inputBlock.clear(); - - _initAddressBlocks(filler, position, inputBlock, addressBlock); - } - - final withXor = _isWithXor(position); - - for (var index = startingIndex; index < _segmentLength; ++index) { - var pseudoRandom = _getPseudoRandom(filler, index, addressBlock, - inputBlock, prevOffset, dataIndependentAddressing); - var refLane = _getRefLane(position, pseudoRandom); - var refColumn = _getRefColumn( - position, index, pseudoRandom, refLane == position.lane); - - /* 2 Creating a new block */ - var prevBlock = _memory[prevOffset]; - var refBlock = _memory[(_laneLength * refLane + refColumn)]; - var currentBlock = _memory[currentOffset]; - - if (withXor) { - filler.fillBlockWithXor(prevBlock, refBlock, currentBlock); - } else { - filler.fillBlock2(prevBlock, refBlock, currentBlock); - } - - prevOffset = currentOffset; - currentOffset++; - } - } - - bool _isDataIndependentAddressing(_Position position) { - return (_parameters.type == Argon2Parameters.ARGON2_i) || - (_parameters.type == Argon2Parameters.ARGON2_id && - (position.pass == 0) && - (position.slice < ARGON2_SYNC_POINTS / 2)); - } - - void _initAddressBlocks(_FillBlock filler, _Position position, - _Block inputBlock, _Block addressBlock) { - inputBlock._v[0] = _intToLong(position.pass); - inputBlock._v[1] = _intToLong(position.lane); - inputBlock._v[2] = _intToLong(position.slice); - inputBlock._v[3] = _intToLong(_memory.length); - inputBlock._v[4] = _intToLong(_parameters.iterations); - inputBlock._v[5] = _intToLong(_parameters.type); - - if ((position.pass == 0) && (position.slice == 0)) { - /* Don't forget to generate the first block of addresses: */ - _nextAddresses(filler, inputBlock, addressBlock); - } - } - - bool _isWithXor(_Position position) { - return !(position.pass == 0 || - _parameters.version == Argon2Parameters.ARGON2_VERSION_10); - } - - int _getPrevOffset(int currentOffset) { - if (currentOffset % _laneLength == 0) { - /* Last block in this lane */ - return currentOffset + _laneLength - 1; - } else { - /* Previous block */ - return currentOffset - 1; - } - } - - static int _getStartingIndex(_Position position) { - if ((position.pass == 0) && (position.slice == 0)) { - return 2; /* we have already generated the first two blocks */ - } else { - return 0; - } - } - - void _nextAddresses( - _FillBlock filler, _Block inputBlock, _Block addressBlock) { - inputBlock._v[6]++; - filler.fillBlock(inputBlock, addressBlock); - filler.fillBlock(addressBlock, addressBlock); - } - - /* 1.2 Computing the index of the reference block */ - /* 1.2.1 Taking pseudo-random value from the previous block */ - int _getPseudoRandom(_FillBlock filler, int index, _Block? addressBlock, - _Block? inputBlock, int prevOffset, bool dataIndependentAddressing) { - if (dataIndependentAddressing) { - var addressIndex = index % ARGON2_ADDRESSES_IN_BLOCK; - if (addressIndex == 0) { - _nextAddresses(filler, inputBlock!, addressBlock!); - } - return addressBlock!._v[addressIndex]; - } else { - return _memory[prevOffset]._v[0]; - } - } - - int _getRefLane(_Position position, int pseudoRandom) { - var refLane = unsignedShiftRight64(pseudoRandom, 32) % _parameters.lanes; - - if ((position.pass == 0) && (position.slice == 0)) { - /* Can not reference other lanes yet */ - refLane = position.lane; - } - return refLane; - } - - int _getRefColumn( - _Position position, int index, int pseudoRandom, bool sameLane) { - int referenceAreaSize; - int startPosition; - - if (position.pass == 0) { - startPosition = 0; - - if (sameLane) { - /* The same lane => add current segment */ - referenceAreaSize = position.slice * _segmentLength + index - 1; - } else { - /* pass == 0 && !sameLane => position.slice > 0*/ - referenceAreaSize = - position.slice * _segmentLength + ((index == 0) ? (-1) : 0); - } - } else { - startPosition = ((position.slice + 1) * _segmentLength) % _laneLength; - - if (sameLane) { - referenceAreaSize = _laneLength - _segmentLength + index - 1; - } else { - referenceAreaSize = - _laneLength - _segmentLength + ((index == 0) ? (-1) : 0); - } - } - - var relativePosition = pseudoRandom & 0xFFFFFFFF; - relativePosition = - unsignedShiftRight64(relativePosition * relativePosition, 32); - relativePosition = referenceAreaSize - - 1 - - unsignedShiftRight64(referenceAreaSize * relativePosition, 32); - - return (startPosition + relativePosition) % _laneLength; - } - - void _digest(Uint8List tmpBlockBytes, Uint8List out, int outOff, int outLen) { - var finalBlock = _memory[_laneLength - 1]; - - /* XOR the last blocks */ - for (var i = 1; i < _parameters.lanes; i++) { - var lastBlockInLane = i * _laneLength + (_laneLength - 1); - finalBlock.xorWith(_memory[lastBlockInLane]); - } - - finalBlock.toBytes(tmpBlockBytes); - - _hash(tmpBlockBytes, out, outOff, outLen); - } - - /// H' - hash - variable length hash function - void _hash(Uint8List input, Uint8List out, int outOff, int outLen) { - var outLenBytes = Uint8List(4); - Pack.intToLittleEndianAtList(outLen, outLenBytes, 0); - - var blake2bLength = 64; - - if (outLen <= blake2bLength) { - var blake = Blake2bDigest(digestSize: outLen); - - blake.update(outLenBytes, 0, outLenBytes.length); - blake.update(input, 0, input.length); - blake.doFinal(out, outOff); - } else { - var digest = Blake2bDigest(digestSize: blake2bLength); - - var outBuffer = Uint8List(blake2bLength); - - /* V1 */ - digest.update(outLenBytes, 0, outLenBytes.length); - digest.update(input, 0, input.length); - digest.doFinal(outBuffer, 0); - - var halfLen = blake2bLength ~/ 2, outPos = outOff; - out.setFrom(outPos, outBuffer, 0, halfLen); - - outPos += halfLen; - - var r = ((outLen + 31) ~/ 32) - 2; - - for (var i = 2; i <= r; i++, outPos += halfLen) { - digest.reset(); - /* V2 to Vr */ - digest.update(outBuffer, 0, outBuffer.length); - digest.doFinal(outBuffer, 0); - - out.setFrom(outPos, outBuffer, 0, halfLen); - } - - var lastLength = outLen - 32 * r; - - /* Vr+1 */ - digest = Blake2bDigest(digestSize: lastLength); - digest.update(outBuffer, 0, outBuffer.length); - digest.doFinal(out, outPos); - } - } - - void _initialize( - Uint8List tmpBlockBytes, Uint8List password, int outputLength) { - /** - * H0 = H64(p, τ, m, t, v, y, |P|, P, |S|, S, |L|, K, |X|, X) - * -> 64 byte (ARGON2_PREHASH_DIGEST_LENGTH) - */ - - var blake = Blake2bDigest(digestSize: ARGON2_PREHASH_DIGEST_LENGTH); - - var values = Uint32List.fromList([ - _parameters.lanes, - outputLength, - _parameters.memory, - _parameters.iterations, - _parameters.version, - _parameters.type - ]); - - Pack.intListToLittleEndianAtList(values, tmpBlockBytes, 0); - blake.update(tmpBlockBytes, 0, values.length * 4); - - _addByteString(tmpBlockBytes, blake, password); - _addByteString(tmpBlockBytes, blake, _parameters.salt); - _addByteString(tmpBlockBytes, blake, _parameters.secret); - _addByteString(tmpBlockBytes, blake, _parameters.additional); - - var initialHashWithZeros = Uint8List(ARGON2_PREHASH_SEED_LENGTH); - blake.doFinal(initialHashWithZeros, 0); - - _fillFirstBlocks(tmpBlockBytes, initialHashWithZeros); - } - - static void _addByteString(Uint8List tmpBlockBytes, Digest digest, - [Uint8List? octets]) { - if (octets == null) { - digest.update(_ZERO_BYTES, 0, 4); - return; - } - - Pack.intToLittleEndianAtList(octets.length, tmpBlockBytes, 0); - digest.update(tmpBlockBytes, 0, 4); - digest.update(octets, 0, octets.length); - } - - /// (H0 || 0 || i) 72 byte -> 1024 byte - /// (H0 || 1 || i) 72 byte -> 1024 byte - void _fillFirstBlocks( - Uint8List tmpBlockBytes, Uint8List initialHashWithZeros) { - var initialHashWithOnes = Uint8List(ARGON2_PREHASH_SEED_LENGTH); - initialHashWithOnes.setFrom( - 0, initialHashWithZeros, 0, ARGON2_PREHASH_DIGEST_LENGTH); - - initialHashWithOnes[ARGON2_PREHASH_DIGEST_LENGTH] = 1; - - for (var i = 0; i < _parameters.lanes; i++) { - Pack.intToLittleEndianAtList( - i, initialHashWithZeros, ARGON2_PREHASH_DIGEST_LENGTH + 4); - Pack.intToLittleEndianAtList( - i, initialHashWithOnes, ARGON2_PREHASH_DIGEST_LENGTH + 4); - - _hash(initialHashWithZeros, tmpBlockBytes, 0, ARGON2_BLOCK_SIZE); - _memory[i * _laneLength + 0].fromBytes(tmpBlockBytes); - - _hash(initialHashWithOnes, tmpBlockBytes, 0, ARGON2_BLOCK_SIZE); - _memory[i * _laneLength + 1].fromBytes(tmpBlockBytes); - } - } - - static int _intToLong(int x) => x & M32L; -} - -class _FillBlock { - final _Block _r = _Block(); - final _Block _z = _Block(); - - _Block addressBlock = _Block(); - _Block inputBlock = _Block(); - - void _applyBlake() { - /* Apply Blake2 on columns of 64-bit words: (0,1,...,15) , then - (16,17,..31)... finally (112,113,...127) */ - for (var i = 0; i < 8; i++) { - var i16 = 16 * i; - _roundFunction( - _z, - i16, - i16 + 1, - i16 + 2, - i16 + 3, - i16 + 4, - i16 + 5, - i16 + 6, - i16 + 7, - i16 + 8, - i16 + 9, - i16 + 10, - i16 + 11, - i16 + 12, - i16 + 13, - i16 + 14, - i16 + 15); - } - - /* Apply Blake2 on rows of 64-bit words: (0,1,16,17,...112,113), then - (2,3,18,19,...,114,115).. finally (14,15,30,31,...,126,127) */ - for (var i = 0; i < 8; i++) { - var i2 = 2 * i; - _roundFunction( - _z, - i2, - i2 + 1, - i2 + 16, - i2 + 17, - i2 + 32, - i2 + 33, - i2 + 48, - i2 + 49, - i2 + 64, - i2 + 65, - i2 + 80, - i2 + 81, - i2 + 96, - i2 + 97, - i2 + 112, - i2 + 113); - } - } - - void fillBlock(_Block Y, _Block currentBlock) { - _z.copyBlock(Y); - _applyBlake(); - currentBlock.xor(Y, _z); - } - - void fillBlock2(_Block X, _Block Y, _Block currentBlock) { - _r.xor(X, Y); - _z.copyBlock(_r); - _applyBlake(); - currentBlock.xor(_r, _z); - } - - void fillBlockWithXor(_Block X, _Block Y, _Block currentBlock) { - _r.xor(X, Y); - _z.copyBlock(_r); - _applyBlake(); - currentBlock.xorWith2(_r, _z); - } - - static void _roundFunction( - _Block block, - int v0, - int v1, - int v2, - int v3, - int v4, - int v5, - int v6, - int v7, - int v8, - int v9, - int v10, - int v11, - int v12, - int v13, - int v14, - int v15) { - final v = block._v; - - _F(v, v0, v4, v8, v12); - _F(v, v1, v5, v9, v13); - _F(v, v2, v6, v10, v14); - _F(v, v3, v7, v11, v15); - - _F(v, v0, v5, v10, v15); - _F(v, v1, v6, v11, v12); - _F(v, v2, v7, v8, v13); - _F(v, v3, v4, v9, v14); - } - - static void _F(Uint64List v, int a, int b, int c, int d) { - _quarterRound(v, a, b, d, 32); - _quarterRound(v, c, d, b, 24); - _quarterRound(v, a, b, d, 16); - _quarterRound(v, c, d, b, 63); - } - - static void _quarterRound(Uint64List v, int x, int y, int z, int s) { - var a = v[x]; - var b = v[y]; - var c = v[z]; - - a += b + 2 * Longs.toInt32(a) * Longs.toInt32(b); - c = Longs.rotateRight(c ^ a, s); - - v[x] = a; - v[z] = c; - } -} - -class _Block { - static const int SIZE = Argon2BytesGenerator.ARGON2_QWORDS_IN_BLOCK; - - /// 128 * 8 Byte QWords. - final Uint64List _v = Uint64List(SIZE); - - _Block(); - - void fromBytes(Uint8List input) { - if (input.length < Argon2BytesGenerator.ARGON2_BLOCK_SIZE) { - throw ArgumentError.value( - input.length, 'input.length', 'input shorter than blocksize'); - } - - Pack.littleEndianToLongAtList(input, 0, _v); - } - - void toBytes(Uint8List output) { - if (output.length < Argon2BytesGenerator.ARGON2_BLOCK_SIZE) { - throw ArgumentError.value( - output.length, 'output.length', 'output shorter than blocksize'); - } - - Pack.longListToLittleEndianAtList(_v, output, 0); - } - - void copyBlock(_Block other) { - _v.setAll(0, other._v); - } - - void xor(_Block b1, _Block b2) { - var v0 = _v; - var v1 = b1._v; - var v2 = b2._v; - - for (var i = SIZE - 1; i >= 0; --i) { - v0[i] = v1[i] ^ v2[i]; - } - } - - void xorWith(_Block b1) { - var v0 = _v; - var v1 = b1._v; - for (var i = SIZE - 1; i >= 0; --i) { - v0[i] ^= v1[i]; - } - } - - void xorWith2(_Block b1, _Block b2) { - var v0 = _v; - var v1 = b1._v; - var v2 = b2._v; - for (var i = SIZE - 1; i >= 0; --i) { - v0[i] ^= v1[i] ^ v2[i]; - } - } - - _Block clear() { - _v.fillRange(0, _v.length, 0); - - return this; - } -} - -class _Position { - late int pass; - late int lane; - late int slice; - - _Position(); -} - -extension _SetFrom on List { - void setFrom(int startIndex, List from, int fromIndex, int length) { - for (var i = 0; i < length; ++i) { - this[startIndex + i] = from[fromIndex + i]; - } - } -} diff --git a/pointycastle/lib/key_derivators/argon2_register64_impl.dart b/pointycastle/lib/key_derivators/argon2_register64_impl.dart deleted file mode 100644 index 338e494..0000000 --- a/pointycastle/lib/key_derivators/argon2_register64_impl.dart +++ /dev/null @@ -1,695 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/digests/blake2b.dart'; -import 'package:pointycastle/src/impl/base_key_derivator.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; -import 'package:pointycastle/src/utils.dart'; - -import 'api.dart'; - -/// Argon2 PBKDF, the winner of the 2015 Password Hashing Competition. -/// Read more: -/// - https://password-hashing.net/ -/// - https://www.ietf.org/archive/id/draft-irtf-cfrg-argon2-03.txt -/// -/// First ported to Dart by Graciliano M. Passos: -/// - https://pub.dev/packages/argon2 -/// - https://github.com/gmpassos/argon2 -/// -/// The linked project was adapted for the purposes of this project, since it -/// is a 1:1 port of BouncyCastle's Java implementation. -/// This is an implementation using [Register64]. If platform is not web, -/// consider use native int impl for better performance. -class Argon2BytesGenerator extends BaseKeyDerivator { - static const int ARGON2_BLOCK_SIZE = 1024; - static const int ARGON2_QWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE ~/ 8; - - static const int ARGON2_ADDRESSES_IN_BLOCK = 128; - - static const int ARGON2_PREHASH_DIGEST_LENGTH = 64; - static const int ARGON2_PREHASH_SEED_LENGTH = 72; - - static const int ARGON2_SYNC_POINTS = 4; - - /// Minimum and maximum number of lanes (degree of parallelism). - static const int MIN_PARALLELISM = 1; - static const int MAX_PARALLELISM = 16777216; - - /// Minimum and maximum digest size in bytes. - static const int MIN_OUTLEN = 4; - - /// Minimum and maximum number of passes. - static const int MIN_ITERATIONS = 1; - - static final Uint8List _ZERO_BYTES = Uint8List(4); - - late Argon2Parameters _parameters; - late List<_Block> _memory; - late int _segmentLength; - late int _laneLength; - - static final FactoryConfig factoryConfig = - StaticFactoryConfig(KeyDerivator, 'argon2', () => Argon2BytesGenerator()); - - final _reg = Register64(); - - Argon2Parameters get parameters => _parameters; - - @override - int get keySize => parameters.desiredKeyLength; - - @override - String get algorithmName => 'Argon2'; - - /// Initialise the Argon2BytesGenerator from the parameters. - /// - [param] parameters Argon2 configuration. - @override - void init(covariant Argon2Parameters parameters) { - _parameters = parameters; - - if (parameters.lanes < MIN_PARALLELISM) { - throw ArgumentError.value(parameters.lanes, 'parameters.lanes', - 'lanes must be greater than $MIN_PARALLELISM'); - } else if (parameters.lanes > MAX_PARALLELISM) { - throw ArgumentError.value(parameters.lanes, 'parameters.lanes', - 'lanes must be less than $MAX_PARALLELISM'); - } else if (parameters.memory < 2 * parameters.lanes) { - throw ArgumentError.value(parameters.memory, 'parameters.memory', - 'memory is less than: ${2 * parameters.lanes} expected ${2 * parameters.lanes}'); - } else if (parameters.iterations < MIN_ITERATIONS) { - throw ArgumentError.value(parameters.iterations, 'parameters.iterations', - 'iterations is less than: $MIN_ITERATIONS'); - } - - _doInit(parameters); - } - - @override - int deriveKey(Uint8List inp, int inpOff, Uint8List out, int outOff) { - inp = inp.sublist(inpOff); - var outLen = parameters.desiredKeyLength; - - if (outLen < MIN_OUTLEN) { - throw ArgumentError.value( - outLen, 'outLen', 'output length less than $MIN_OUTLEN'); - } - - var tmpBlockBytes = Uint8List(ARGON2_BLOCK_SIZE); - - _initialize(tmpBlockBytes, inp, outLen); - _fillMemoryBlocks(); - _digest(tmpBlockBytes, out, outOff, outLen); - - _reset(); - - return outLen; - } - - /// Clear memory. - void _reset() { - for (var i = _memory.length - 1; i >= 0; --i) { - var b = _memory[i]; - b.clear(); - } - } - - void _doInit(Argon2Parameters parameters) { - /* 2. Align memory size */ - /* Minimum memoryBlocks = 8L blocks, where L is the number of lanes */ - var memoryBlocks = parameters.memory; - - if (memoryBlocks < 2 * ARGON2_SYNC_POINTS * parameters.lanes) { - memoryBlocks = 2 * ARGON2_SYNC_POINTS * parameters.lanes; - } - - _segmentLength = memoryBlocks ~/ (parameters.lanes * ARGON2_SYNC_POINTS); - _laneLength = _segmentLength * ARGON2_SYNC_POINTS; - - /* Ensure that all segments have equal length */ - memoryBlocks = _segmentLength * (parameters.lanes * ARGON2_SYNC_POINTS); - - _initMemory(memoryBlocks); - } - - void _initMemory(int memoryBlocks) { - _memory = List<_Block>.generate(memoryBlocks, (i) => _Block()); - } - - void _fillMemoryBlocks() { - var filler = _FillBlock(); - var position = _Position(); - for (var pass = 0; pass < _parameters.iterations; ++pass) { - position.pass = pass; - - for (var slice = 0; slice < ARGON2_SYNC_POINTS; ++slice) { - position.slice = slice; - - for (var lane = 0; lane < _parameters.lanes; ++lane) { - position.lane = lane; - - _fillSegment(filler, position); - } - } - } - } - - void _fillSegment(_FillBlock filler, _Position position) { - _Block? addressBlock; - _Block? inputBlock; - - var dataIndependentAddressing = _isDataIndependentAddressing(position); - var startingIndex = _getStartingIndex(position); - var currentOffset = position.lane * _laneLength + - position.slice * _segmentLength + - startingIndex; - var prevOffset = _getPrevOffset(currentOffset); - - if (dataIndependentAddressing) { - addressBlock = filler.addressBlock.clear(); - inputBlock = filler.inputBlock.clear(); - - _initAddressBlocks(filler, position, inputBlock, addressBlock); - } - - final withXor = _isWithXor(position); - - for (var index = startingIndex; index < _segmentLength; ++index) { - var pseudoRandomReg = _getPseudoRandom(filler, index, addressBlock, - inputBlock, prevOffset, dataIndependentAddressing); - var refLane = _getRefLane(position, pseudoRandomReg); - var refColumn = _getRefColumn( - position, index, pseudoRandomReg, refLane == position.lane); - - /* 2 Creating a new block */ - var prevBlock = _memory[prevOffset]; - var refBlock = _memory[(_laneLength * refLane + refColumn)]; - var currentBlock = _memory[currentOffset]; - - if (withXor) { - filler.fillBlockWithXor(prevBlock, refBlock, currentBlock); - } else { - filler.fillBlock2(prevBlock, refBlock, currentBlock); - } - - prevOffset = currentOffset; - currentOffset++; - } - } - - bool _isDataIndependentAddressing(_Position position) { - return (_parameters.type == Argon2Parameters.ARGON2_i) || - (_parameters.type == Argon2Parameters.ARGON2_id && - (position.pass == 0) && - (position.slice < ARGON2_SYNC_POINTS / 2)); - } - - void _initAddressBlocks(_FillBlock filler, _Position position, - _Block inputBlock, _Block addressBlock) { - inputBlock._v[0].set(position.pass); - inputBlock._v[1].set(position.lane); - inputBlock._v[2].set(position.slice); - inputBlock._v[3].set(_memory.length); - inputBlock._v[4].set(_parameters.iterations); - inputBlock._v[5].set(_parameters.type); - - if ((position.pass == 0) && (position.slice == 0)) { - /* Don't forget to generate the first block of addresses: */ - _nextAddresses(filler, inputBlock, addressBlock); - } - } - - bool _isWithXor(_Position position) { - return !(position.pass == 0 || - _parameters.version == Argon2Parameters.ARGON2_VERSION_10); - } - - int _getPrevOffset(int currentOffset) { - if (currentOffset % _laneLength == 0) { - /* Last block in this lane */ - return currentOffset + _laneLength - 1; - } else { - /* Previous block */ - return currentOffset - 1; - } - } - - @pragma('vm:prefer-inline') - @pragma('dart2js:tryInline') - static int _getStartingIndex(_Position position) { - if ((position.pass == 0) && (position.slice == 0)) { - return 2; /* we have already generated the first two blocks */ - } else { - return 0; - } - } - - static void _nextAddresses( - _FillBlock filler, _Block inputBlock, _Block addressBlock) { - inputBlock._v[6].sum(1); - filler.fillBlock(inputBlock, addressBlock); - filler.fillBlock(addressBlock, addressBlock); - } - - /* 1.2 Computing the index of the reference block */ - /* 1.2.1 Taking pseudo-random value from the previous block */ - Register64 _getPseudoRandom( - _FillBlock filler, - int index, - _Block? addressBlock, - _Block? inputBlock, - int prevOffset, - bool dataIndependentAddressing) { - if (dataIndependentAddressing) { - var addressIndex = index % ARGON2_ADDRESSES_IN_BLOCK; - if (addressIndex == 0) { - _nextAddresses(filler, inputBlock!, addressBlock!); - } - return addressBlock!._v[addressIndex]; - } else { - return _memory[prevOffset]._v[0]; - } - } - - int _getRefLane(_Position position, Register64 pseudoRandom) { - var refLane = pseudoRandom.hi32 % _parameters.lanes; - - if ((position.pass == 0) && (position.slice == 0)) { - /* Can not reference other lanes yet */ - refLane = position.lane; - } - return refLane; - } - - int _getRefColumn( - _Position position, int index, Register64 pseudoRandom, bool sameLane) { - int referenceAreaSize; - int startPosition; - - if (position.pass == 0) { - startPosition = 0; - - if (sameLane) { - /* The same lane => add current segment */ - referenceAreaSize = position.slice * _segmentLength + index - 1; - } else { - /* pass == 0 && !sameLane => position.slice > 0*/ - referenceAreaSize = - position.slice * _segmentLength + ((index == 0) ? (-1) : 0); - } - } else { - startPosition = ((position.slice + 1) * _segmentLength) % _laneLength; - - if (sameLane) { - referenceAreaSize = _laneLength - _segmentLength + index - 1; - } else { - referenceAreaSize = - _laneLength - _segmentLength + ((index == 0) ? (-1) : 0); - } - } - - var relativePosition = _reg..set(pseudoRandom.lo32); - relativePosition - ..mul(pseudoRandom.lo32) - ..shiftr(32); - relativePosition - ..mul(referenceAreaSize) - ..shiftr(32) - ..neg() - ..sum(referenceAreaSize - 1); - return (relativePosition - ..sum(startPosition) - ..mod(_laneLength)) - .lo32; - } - - void _digest(Uint8List tmpBlockBytes, Uint8List out, int outOff, int outLen) { - var finalBlock = _memory[_laneLength - 1]; - - /* XOR the last blocks */ - for (var i = 1; i < _parameters.lanes; i++) { - var lastBlockInLane = i * _laneLength + (_laneLength - 1); - finalBlock.xorWith(_memory[lastBlockInLane]); - } - - finalBlock.toBytes(tmpBlockBytes); - - _hash(tmpBlockBytes, out, outOff, outLen); - } - - /// H' - hash - variable length hash function - static void _hash(Uint8List input, Uint8List out, int outOff, int outLen) { - var outLenBytes = Uint8List(4); - Pack.intToLittleEndianAtList(outLen, outLenBytes, 0); - - var blake2bLength = 64; - - if (outLen <= blake2bLength) { - var blake = Blake2bDigest(digestSize: outLen); - - blake.update(outLenBytes, 0, outLenBytes.length); - blake.update(input, 0, input.length); - blake.doFinal(out, outOff); - } else { - var digest = Blake2bDigest(digestSize: blake2bLength); - - var outBuffer = Uint8List(blake2bLength); - - /* V1 */ - digest.update(outLenBytes, 0, outLenBytes.length); - digest.update(input, 0, input.length); - digest.doFinal(outBuffer, 0); - - var halfLen = blake2bLength ~/ 2, outPos = outOff; - out.setFrom(outPos, outBuffer, 0, halfLen); - - outPos += halfLen; - - var r = ((outLen + 31) ~/ 32) - 2; - - for (var i = 2; i <= r; i++, outPos += halfLen) { - digest.reset(); - /* V2 to Vr */ - digest.update(outBuffer, 0, outBuffer.length); - digest.doFinal(outBuffer, 0); - - out.setFrom(outPos, outBuffer, 0, halfLen); - } - - var lastLength = outLen - 32 * r; - - /* Vr+1 */ - digest = Blake2bDigest(digestSize: lastLength); - digest.update(outBuffer, 0, outBuffer.length); - digest.doFinal(out, outPos); - } - } - - void _initialize( - Uint8List tmpBlockBytes, Uint8List password, int outputLength) { - /** - * H0 = H64(p, τ, m, t, v, y, |P|, P, |S|, S, |L|, K, |X|, X) - * -> 64 byte (ARGON2_PREHASH_DIGEST_LENGTH) - */ - - var blake = Blake2bDigest(digestSize: ARGON2_PREHASH_DIGEST_LENGTH); - - var values = Uint32List.fromList([ - _parameters.lanes, - outputLength, - _parameters.memory, - _parameters.iterations, - _parameters.version, - _parameters.type - ]); - - Pack.intListToLittleEndianAtList(values, tmpBlockBytes, 0); - blake.update(tmpBlockBytes, 0, values.length * 4); - - _addByteString(tmpBlockBytes, blake, password); - _addByteString(tmpBlockBytes, blake, _parameters.salt); - _addByteString(tmpBlockBytes, blake, _parameters.secret); - _addByteString(tmpBlockBytes, blake, _parameters.additional); - - var initialHashWithZeros = Uint8List(ARGON2_PREHASH_SEED_LENGTH); - blake.doFinal(initialHashWithZeros, 0); - - _fillFirstBlocks(tmpBlockBytes, initialHashWithZeros); - } - - @pragma('vm:prefer-inline') - @pragma('dart2js:tryInline') - static void _addByteString(Uint8List tmpBlockBytes, Digest digest, - [Uint8List? octets]) { - if (octets == null) { - digest.update(_ZERO_BYTES, 0, 4); - return; - } - - Pack.intToLittleEndianAtList(octets.length, tmpBlockBytes, 0); - digest.update(tmpBlockBytes, 0, 4); - digest.update(octets, 0, octets.length); - } - - /// (H0 || 0 || i) 72 byte -> 1024 byte - /// (H0 || 1 || i) 72 byte -> 1024 byte - void _fillFirstBlocks( - Uint8List tmpBlockBytes, Uint8List initialHashWithZeros) { - var initialHashWithOnes = Uint8List(ARGON2_PREHASH_SEED_LENGTH); - initialHashWithOnes.setFrom( - 0, initialHashWithZeros, 0, ARGON2_PREHASH_DIGEST_LENGTH); - - initialHashWithOnes[ARGON2_PREHASH_DIGEST_LENGTH] = 1; - - for (var i = 0; i < _parameters.lanes; i++) { - Pack.intToLittleEndianAtList( - i, initialHashWithZeros, ARGON2_PREHASH_DIGEST_LENGTH + 4); - Pack.intToLittleEndianAtList( - i, initialHashWithOnes, ARGON2_PREHASH_DIGEST_LENGTH + 4); - - _hash(initialHashWithZeros, tmpBlockBytes, 0, ARGON2_BLOCK_SIZE); - _memory[i * _laneLength + 0].fromBytes(tmpBlockBytes); - - _hash(initialHashWithOnes, tmpBlockBytes, 0, ARGON2_BLOCK_SIZE); - _memory[i * _laneLength + 1].fromBytes(tmpBlockBytes); - } - } -} - -class _FillBlock { - final _Block _r = _Block(); - final _Block _z = _Block(); - static final Register64 _reg = Register64(); - _Block addressBlock = _Block(); - _Block inputBlock = _Block(); - - void _applyBlake() { - /* Apply Blake2 on columns of 64-bit words: (0,1,...,15) , then - (16,17,..31)... finally (112,113,...127) */ - for (var i = 0; i < 8; i++) { - var i16 = 16 * i; - _roundFunction( - _z, - i16, - i16 + 1, - i16 + 2, - i16 + 3, - i16 + 4, - i16 + 5, - i16 + 6, - i16 + 7, - i16 + 8, - i16 + 9, - i16 + 10, - i16 + 11, - i16 + 12, - i16 + 13, - i16 + 14, - i16 + 15); - } - - /* Apply Blake2 on rows of 64-bit words: (0,1,16,17,...112,113), then - (2,3,18,19,...,114,115).. finally (14,15,30,31,...,126,127) */ - for (var i = 0; i < 8; i++) { - var i2 = 2 * i; - _roundFunction( - _z, - i2, - i2 + 1, - i2 + 16, - i2 + 17, - i2 + 32, - i2 + 33, - i2 + 48, - i2 + 49, - i2 + 64, - i2 + 65, - i2 + 80, - i2 + 81, - i2 + 96, - i2 + 97, - i2 + 112, - i2 + 113); - } - } - - void fillBlock(_Block Y, _Block currentBlock) { - _z.copyBlock(Y); - _applyBlake(); - currentBlock.xor(Y, _z); - } - - void fillBlock2(_Block X, _Block Y, _Block currentBlock) { - _r.xor(X, Y); - _z.copyBlock(_r); - _applyBlake(); - currentBlock.xor(_r, _z); - } - - void fillBlockWithXor(_Block X, _Block Y, _Block currentBlock) { - _r.xor(X, Y); - _z.copyBlock(_r); - _applyBlake(); - currentBlock.xorWith2(_r, _z); - } - - @pragma('vm:prefer-inline') - @pragma('dart2js:tryInline') - static void _roundFunction( - _Block block, - int v0, - int v1, - int v2, - int v3, - int v4, - int v5, - int v6, - int v7, - int v8, - int v9, - int v10, - int v11, - int v12, - int v13, - int v14, - int v15) { - final v = block._v; - - _F(v, v0, v4, v8, v12); - _F(v, v1, v5, v9, v13); - _F(v, v2, v6, v10, v14); - _F(v, v3, v7, v11, v15); - - _F(v, v0, v5, v10, v15); - _F(v, v1, v6, v11, v12); - _F(v, v2, v7, v8, v13); - _F(v, v3, v4, v9, v14); - } - - @pragma('vm:prefer-inline') - @pragma('dart2js:tryInline') - static void _F(List v, int a, int b, int c, int d) { - _quarterRound(v, a, b, d, 32); - _quarterRound(v, c, d, b, 24); - _quarterRound(v, a, b, d, 16); - _quarterRound(v, c, d, b, 63); - } - - @pragma('vm:prefer-inline') - @pragma('dart2js:tryInline') - static void _quarterRound(List v, int x, int y, int z, int s) { - var a = v[x]; - var b = v[y]; - var c = v[z]; - _reg - ..set(2) - ..mul(a.lo32) - ..mul(b.lo32); - a - ..sumReg(b) - ..sumReg(_reg); - c - ..xor(a) - ..rotr(s); - } -} - -class _Block { - static const int SIZE = Argon2BytesGenerator.ARGON2_QWORDS_IN_BLOCK; - - /// 128 * 8 Byte QWords. - final List _v = - List.unmodifiable(List.generate(SIZE, (_) => Register64())); - - _Block(); - - void fromBytes(Uint8List input) { - if (input.length < Argon2BytesGenerator.ARGON2_BLOCK_SIZE) { - throw ArgumentError.value( - input.length, 'input.length', 'input shorter than blocksize'); - } - var data = ByteData.view(input.buffer, input.offsetInBytes); - var off = 0; - for (var i = 0; i < _v.length; ++i) { - _v[i].set( - data.getUint32(off + 4, Endian.little), - data.getUint32(off, Endian.little), - ); - off += 8; - } - } - - void toBytes(Uint8List output) { - if (output.length < Argon2BytesGenerator.ARGON2_BLOCK_SIZE) { - throw ArgumentError.value( - output.length, 'output.length', 'output shorter than blocksize'); - } - var data = ByteData.view(output.buffer, output.offsetInBytes); - var off = 0; - for (var i = 0; i < _v.length; ++i) { - data.setUint32(off, _v[i].lo32, Endian.little); - data.setUint32(off + 4, _v[i].hi32, Endian.little); - off += 8; - } - } - - void copyBlock(_Block other) { - for (var i = 0; i < _v.length; ++i) { - _v[i].set(other._v[i]); - } - } - - void xor(_Block b1, _Block b2) { - var v0 = _v; - var v1 = b1._v; - var v2 = b2._v; - - for (var i = SIZE - 1; i >= 0; --i) { - v0[i] - ..set(v1[i]) - ..xor(v2[i]); - } - } - - void xorWith(_Block b1) { - var v0 = _v; - var v1 = b1._v; - for (var i = SIZE - 1; i >= 0; --i) { - v0[i].xor(v1[i]); - } - } - - void xorWith2(_Block b1, _Block b2) { - var v0 = _v; - var v1 = b1._v; - var v2 = b2._v; - for (var i = SIZE - 1; i >= 0; --i) { - v0[i] - ..xor(v1[i]) - ..xor(v2[i]); - } - } - - _Block clear() { - for (var reg in _v) { - reg.set(0); - } - return this; - } -} - -class _Position { - late int pass; - late int lane; - late int slice; - - _Position(); -} - -extension _SetFrom on List { - void setFrom(int startIndex, List from, int fromIndex, int length) { - // Use [setRange] for a faster copy on [TypedData] - setRange(startIndex, startIndex + length, from, fromIndex); - } -} diff --git a/pointycastle/lib/key_derivators/concat_kdf.dart b/pointycastle/lib/key_derivators/concat_kdf.dart deleted file mode 100644 index 5aa8b9b..0000000 --- a/pointycastle/lib/key_derivators/concat_kdf.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/key_derivators/api.dart'; -import 'package:pointycastle/src/impl/base_key_derivator.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -class ConcatKDFDerivator extends BaseKeyDerivator { - /// Intended for internal use. - static final FactoryConfig factoryConfig = - DynamicFactoryConfig.suffix(KeyDerivator, '/ConcatKDF', (_, Match match) { - final digestName = match.group(1); - final digest = Digest(digestName!); - return () { - return ConcatKDFDerivator(digest); - }; - }); - - final Digest _digest; - late final HkdfParameters _parameters; - - ConcatKDFDerivator(this._digest); - - @override - String get algorithmName => '${_digest.algorithmName}/ConcatKDF'; - - @override - int deriveKey(Uint8List inp, int inpOff, Uint8List out, int outOff) { - _digest.reset(); - - var reps = _getReps(_parameters.desiredKeyLength, _digest.digestSize * 8); - var output = Uint8List(reps * _digest.digestSize); - var counter = Uint8List(4); - for (var i = 1; i <= reps; i++) { - var counterInt = i.toUnsigned(32); - counter[0] = (counterInt >> 24) & 255; - counter[1] = (counterInt >> 16) & 255; - counter[2] = (counterInt >> 8) & 255; - counter[3] = counterInt & 255; - _digest.update(counter, 0, 4); - _digest.update(_parameters.ikm, 0, _parameters.ikm.length); - _digest.update(_parameters.salt ?? inp.sublist(inpOff), 0, - _parameters.salt?.length ?? inp.sublist(inpOff).length); - _digest.doFinal(output, (i - 1) * _digest.digestSize); - } - - out.setAll(outOff, output.getRange(0, keySize)); - return keySize; - } - - int _getReps(int keydatalen, int messagedigestlen) { - return (keydatalen / messagedigestlen).ceil(); - } - - @override - void init(covariant HkdfParameters params) { - _parameters = params; - } - - @override - int get keySize => (_parameters.desiredKeyLength / 8).ceil(); -} diff --git a/pointycastle/lib/key_derivators/ecdh_kdf.dart b/pointycastle/lib/key_derivators/ecdh_kdf.dart deleted file mode 100644 index 51f4898..0000000 --- a/pointycastle/lib/key_derivators/ecdh_kdf.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'dart:math'; -import 'dart:typed_data'; - -import 'package:pointycastle/export.dart'; -import 'package:pointycastle/src/impl/base_key_derivator.dart'; -import 'package:pointycastle/src/utils.dart'; - -import '../src/registry/registry.dart'; - -class ECDHKeyDerivator extends BaseKeyDerivator { - late ECDHKDFParameters parameters; - static final FactoryConfig factoryConfig = - StaticFactoryConfig(KeyDerivator, 'ECDH', () => ECDHKeyDerivator()); - - @override - String get algorithmName => '/ECDH'; - - @override - int deriveKey(Uint8List inp, int inpOff, Uint8List out, int outOff) { - var ecdh = ECDHBasicAgreement()..init(parameters.privateKey); - var ag = ecdh.calculateAgreement(parameters.publicKey); - var key = encodeBigIntAsUnsigned(ag); - // pad to keysize - var padlength = max((keySize / 8).ceil() - key.length, 0); - out.setAll(outOff, Uint8List.fromList(List.filled(padlength, 0))); - out.setAll(outOff + padlength, key); - return padlength + key.length; - } - - @override - void init(covariant ECDHKDFParameters params) { - parameters = params; - } - - @override - int get keySize => parameters.privateKey.parameters!.curve.fieldSize; -} diff --git a/pointycastle/lib/key_derivators/hkdf.dart b/pointycastle/lib/key_derivators/hkdf.dart deleted file mode 100644 index 5d22489..0000000 --- a/pointycastle/lib/key_derivators/hkdf.dart +++ /dev/null @@ -1,185 +0,0 @@ -// See file LICENSE for more information. - -library impl.key_derivator.hkdf; - -import 'dart:math'; -import 'dart:typed_data'; - -import 'package:collection/collection.dart' show IterableExtension; -import 'package:pointycastle/export.dart'; -import 'package:pointycastle/src/impl/base_key_derivator.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// HMAC-based Extract-and-Expand Key Derivation Function (HKDF) implemented -/// according to IETF RFC 5869. -class HKDFKeyDerivator extends BaseKeyDerivator { - /// Intended for internal use. - static final FactoryConfig factoryConfig = - DynamicFactoryConfig.suffix(KeyDerivator, '/HKDF', (_, Match match) { - final digestName = match.group(1); - final digest = Digest(digestName!); - return () { - return HKDFKeyDerivator(digest); - }; - }); - - static final Map _digestBlockLength = { - 'GOST3411': 32, - 'MD2': 16, - 'MD4': 64, - 'MD5': 64, - 'RIPEMD-128': 64, - 'RIPEMD-160': 64, - 'SHA-1': 64, - 'SHA-224': 64, - 'SHA-256': 64, - 'SHA-384': 128, - 'SHA-512': 128, - 'SHA-512/224': 128, - 'SHA-512/256': 128, - 'SHA3-224': 1152 ~/ 8, - 'SHA3-256': 1088 ~/ 8, - 'SHA3-384': 832 ~/ 8, - 'SHA3-512': 576 ~/ 8, - 'Tiger': 64, - 'Whirlpool': 64, - }; - - late HkdfParameters _params; - - late HMac _hMac; - late int _hashLen; - - Uint8List? _info; - late Uint8List _currentT; - - late int _generatedBytes; - - HKDFKeyDerivator(Digest digest) { - ArgumentError.checkNotNull(digest); - - _hMac = HMac(digest, _getBlockLengthFromDigest(digest.algorithmName)); - _hashLen = _hMac.macSize; - } - - @override - String get algorithmName => '${_hMac.algorithmName}/HKDF'; - - @override - int get keySize => _params.desiredKeyLength; - - @override - void init(covariant HkdfParameters params) { - _params = params; - - if (_params.skipExtract) { - // use IKM directly as PRK - _hMac.init(KeyParameter(_params.ikm)); - } else { - _hMac.init(extract(_params.salt, _params.ikm)); - } - - _info = _params.info; - - _generatedBytes = 0; - _currentT = Uint8List(_hashLen); - } - - @override - int deriveKey(Uint8List? inp, int inpOff, Uint8List out, int outOff) { - // append input to the 'info' part for key derivation - if (inp != null) { - // TODO: find better way to concatenate Uint8Lists with null elements - _info = combineLists(_info!, inp); - } - - return _generate(out, outOff, keySize); - } - - Uint8List combineLists(Uint8List a, Uint8List b) { - var length = a.length + b.length; - var holder = Uint8List(length); - holder.setRange(0, a.length, a); - holder.setRange(a.length, length, b); - return holder; - } - - /// Performs the extract part of the key derivation function. - KeyParameter extract(Uint8List? salt, Uint8List ikm) { - if (salt == null || salt.isEmpty) { - if (_hashLen != _hMac.macSize) { - throw ArgumentError( - 'Hash length doesn\'t equal MAC size of: ${_hMac.algorithmName}'); - } - - _hMac.init(KeyParameter(Uint8List(_hashLen))); - } else { - _hMac.init(KeyParameter(salt)); - } - - _hMac.update(ikm, 0, ikm.length); - - var prk = Uint8List(_hashLen); - _hMac.doFinal(prk, 0); - return KeyParameter(prk); - } - - /// Performs the expand part of the key derivation function, using currentT - /// as input and output buffer. - void expandNext() { - var n = _generatedBytes ~/ _hashLen + 1; - if (n >= 256) { - throw ArgumentError( - 'HKDF cannot generate more than 255 blocks of HashLen size'); - } - - // special case for T(0): T(0) is empty, so no update - if (_generatedBytes != 0) { - _hMac.update(_currentT, 0, _hashLen); - } - - _hMac.update(_info!, 0, _info!.length); - _hMac.updateByte(n); - _hMac.doFinal(_currentT, 0); - } - - int _generate(Uint8List out, int outOff, int len) { - if (_generatedBytes + len > 255 * _hashLen) { - throw ArgumentError( - 'HKDF may only be used for 255 * HashLen bytes of output'); - } - - if (_generatedBytes % _hashLen == 0) { - expandNext(); - } - - // copy what is left in the currentT - var toGenerate = len; - var posInT = _generatedBytes % _hashLen; - var leftInT = _hashLen - _generatedBytes % _hashLen; - var toCopy = min(leftInT, toGenerate); - out.setRange(outOff, outOff + toCopy, _currentT.sublist(posInT)); - _generatedBytes += toCopy; - toGenerate -= toCopy; - outOff += toCopy; - - while (toGenerate > 0) { - expandNext(); - toCopy = min(_hashLen, toGenerate); - out.setRange(outOff, outOff + toCopy, _currentT.sublist(0)); - _generatedBytes += toCopy; - toGenerate -= toCopy; - outOff += toCopy; - } - - return len; - } - - static int _getBlockLengthFromDigest(String digestName) { - var blockLength = _digestBlockLength.entries - .firstWhereOrNull( - (map) => map.key.toLowerCase() == digestName.toLowerCase()) - ?.value; - return blockLength!; - } -} diff --git a/pointycastle/lib/key_derivators/pbkdf2.dart b/pointycastle/lib/key_derivators/pbkdf2.dart deleted file mode 100644 index e5d6556..0000000 --- a/pointycastle/lib/key_derivators/pbkdf2.dart +++ /dev/null @@ -1,102 +0,0 @@ -// See file LICENSE for more information. - -library impl.key_derivator.pbkdf2; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/key_derivators/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/impl/base_key_derivator.dart'; - -/// Generator for PBE derived keys and ivs as defined by PKCS 5 V2.0 Scheme 2. This generator uses a SHA-1 HMac as the -/// calculation function. The document this implementation is based on can be found at: -/// -/// * [http://www.rsasecurity.com/rsalabs/pkcs/pkcs-5/index.html] -/// -class PBKDF2KeyDerivator extends BaseKeyDerivator { - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - KeyDerivator, - '/PBKDF2', - (_, final Match match) => () { - var mac = Mac(match.group(1)!); - return PBKDF2KeyDerivator(mac); - }); - - late Pbkdf2Parameters _params; - final Mac _mac; - late Uint8List _state; - - PBKDF2KeyDerivator(this._mac) { - _state = Uint8List(_mac.macSize); - } - - @override - String get algorithmName => '${_mac.algorithmName}/PBKDF2'; - - @override - int get keySize => _params.desiredKeyLength; - - void reset() { - _mac.reset(); - _state.fillRange(0, _state.length, 0); - } - - @override - void init(covariant Pbkdf2Parameters params) { - _params = params; - } - - @override - int deriveKey(Uint8List inp, int inpOff, Uint8List out, int outOff) { - var dkLen = _params.desiredKeyLength; - var hLen = _mac.macSize; - var l = (dkLen + hLen - 1) ~/ hLen; - var iBuf = Uint8List(4); - var outBytes = Uint8List(l * hLen); - var outPos = 0; - - CipherParameters param = KeyParameter(inp.sublist(inpOff)); - _mac.init(param); - - for (var i = 1; i <= l; i++) { - // Increment the value in 'iBuf' - for (var pos = 3;; pos--) { - iBuf[pos]++; - if (iBuf[pos] != 0) break; - } - - _f(_params.salt, _params.iterationCount, iBuf, outBytes, outPos); - outPos += hLen; - } - - out.setRange(outOff, outOff + dkLen, outBytes); - - return keySize; - } - - void _f(Uint8List? S, int c, Uint8List iBuf, Uint8List out, int outOff) { - if (c <= 0) { - throw ArgumentError('Iteration count must be at least 1.'); - } - - if (S != null) { - _mac.update(S, 0, S.length); - } - - _mac.update(iBuf, 0, iBuf.length); - _mac.doFinal(_state, 0); - - out.setRange(outOff, outOff + _state.length, _state); - - for (var count = 1; count < c; count++) { - _mac.update(_state, 0, _state.length); - _mac.doFinal(_state, 0); - - for (var j = 0; j != _state.length; j++) { - out[outOff + j] ^= _state[j]; - } - } - } -} diff --git a/pointycastle/lib/key_derivators/pkcs12_parameter_generator.dart b/pointycastle/lib/key_derivators/pkcs12_parameter_generator.dart deleted file mode 100644 index faf4cd1..0000000 --- a/pointycastle/lib/key_derivators/pkcs12_parameter_generator.dart +++ /dev/null @@ -1,148 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/pointycastle.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -class PKCS12ParametersGenerator implements PBEParametersGenerator { - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - PBEParametersGenerator, - '/PKCS12', - (_, final Match match) => () { - var mac = Digest(match.group(1)!); - return PKCS12ParametersGenerator(mac); - }); - - static const int KEY_MATERIAL = 1; - - static const int IV_MATERIAL = 2; - - static const int MAC_MATERIAL = 3; - - Digest digest; - - late int u; - - late int v; - - late Uint8List salt; - - late Uint8List password; - late int iterationCount; - - PKCS12ParametersGenerator(this.digest) { - u = digest.digestSize; - v = digest.byteLength; - } - - @override - void init(Uint8List password, Uint8List salt, int iterationCount) { - this.password = password; - this.salt = salt; - this.iterationCount = iterationCount; - } - - /// - /// Generates a derived key with the given [keySize] in bytes. - /// - @override - KeyParameter generateDerivedParameters(int keySize) { - var dKey = _generateDerivedKey(KEY_MATERIAL, keySize); - - return KeyParameter(dKey); - } - - /// - /// Generates a derived key with the given [keySize] in bytes and a derived IV with the given [ivSize]. - /// - @override - ParametersWithIV generateDerivedParametersWithIV(int keySize, int ivSize) { - var dKey = _generateDerivedKey(KEY_MATERIAL, keySize); - - var iv = _generateDerivedKey(IV_MATERIAL, ivSize); - - return ParametersWithIV(KeyParameter(dKey), iv); - } - - /// - /// Generates a derived key with the given [keySize] in bytes used for mac generating. - /// - @override - KeyParameter generateDerivedMacParameters(int keySize) { - var dKey = _generateDerivedKey(MAC_MATERIAL, keySize); - - return KeyParameter(dKey); - } - - Uint8List _generateDerivedKey(int idByte, int n) { - var D = Uint8List(v); - var dKey = Uint8List(n); - for (var i = 0; i != D.length; i++) { - D[i] = idByte; - } - Uint8List S; - if (salt.isNotEmpty) { - S = Uint8List(v * (((salt.length + v) - 1) ~/ v)); - for (var i = 0; i != S.length; i++) { - S[i] = salt[i % salt.length]; - } - } else { - S = Uint8List(0); - } - Uint8List P; - if (password.isNotEmpty) { - P = Uint8List(v * (((password.length + v) - 1) ~/ v)); - for (var i = 0; i != P.length; i++) { - P[i] = password[i % password.length]; - } - } else { - P = Uint8List(0); - } - var I = Uint8List(S.length + P.length); - _arrayCopy(S, 0, I, 0, S.length); - _arrayCopy(P, 0, I, S.length, P.length); - var B = Uint8List(v); - var c = ((n + u) - 1) ~/ u; - var A = Uint8List(u); - for (var i = 1; i <= c; i++) { - digest.update(D, 0, D.length); - digest.update(I, 0, I.length); - digest.doFinal(A, 0); - for (var j = 1; j < iterationCount; j++) { - digest.update(A, 0, A.length); - digest.doFinal(A, 0); - } - for (var j = 0; j != B.length; j++) { - B[j] = A[j % A.length]; - } - for (var j = 0; j != (I.length ~/ v); j++) { - _adjust(I, j * v, B); - } - if (i == c) { - _arrayCopy(A, 0, dKey, (i - 1) * u, dKey.length - ((i - 1) * u)); - } else { - _arrayCopy(A, 0, dKey, (i - 1) * u, A.length); - } - } - return dKey; - } - - void _arrayCopy(Uint8List? sourceArr, int sourcePos, Uint8List? outArr, - int outPos, int len) { - for (var i = 0; i < len; i++) { - outArr![outPos + i] = sourceArr![sourcePos + i]; - } - } - - void _adjust(Uint8List a, int aOff, Uint8List b) { - var x = (b[b.length - 1] & 0xff) + (a[aOff + b.length - 1] & 0xff) + 1; - - a[aOff + b.length - 1] = x; - x >>>= 8; - - for (var i = b.length - 2; i >= 0; i--) { - x += (b[i] & 0xff) + (a[aOff + i] & 0xff); - a[aOff + i] = x; - x >>>= 8; - } - } -} diff --git a/pointycastle/lib/key_derivators/pkcs5s1_parameter_generator.dart b/pointycastle/lib/key_derivators/pkcs5s1_parameter_generator.dart deleted file mode 100644 index 1097743..0000000 --- a/pointycastle/lib/key_derivators/pkcs5s1_parameter_generator.dart +++ /dev/null @@ -1,75 +0,0 @@ -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -class PKCS5S1ParameterGenerator implements PBEParametersGenerator { - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - PBEParametersGenerator, - '/PKCS5S1', - (_, final Match match) => () { - var mac = Digest(match.group(1)!); - return PKCS5S1ParameterGenerator(mac); - }); - - Digest digest; - - PKCS5S1ParameterGenerator(this.digest); - - late Uint8List password; - late Uint8List salt; - late int iterationCount; - - @override - void init(Uint8List password, Uint8List salt, int iterationCount) { - this.password = password; - this.salt = salt; - this.iterationCount = iterationCount; - } - - Uint8List generateDerivedKey() { - var digestBytes = Uint8List(digest.digestSize); - - digest.update(password, 0, password.length); - digest.update(salt, 0, salt.length); - - digest.doFinal(digestBytes, 0); - for (var i = 1; i < iterationCount; i++) { - digest.update(digestBytes, 0, digestBytes.length); - digest.doFinal(digestBytes, 0); - } - - return digestBytes; - } - - @override - KeyParameter generateDerivedParameters(int keySize) { - if (keySize > digest.digestSize) { - throw ArgumentError("Can't generate a derived key $keySize bytes long."); - } - - var dKey = generateDerivedKey(); - - return KeyParameter(dKey); - } - - @override - ParametersWithIV generateDerivedParametersWithIV(int keySize, int ivSize) { - keySize = keySize; - ivSize = ivSize; - - if ((keySize + ivSize) > digest.digestSize) { - throw ArgumentError( - "Can't generate a derived key ${keySize + ivSize} bytes long."); - } - - var dKey = generateDerivedKey(); - - return ParametersWithIV(KeyParameter(dKey), dKey); - } - - @override - KeyParameter generateDerivedMacParameters(int keySize) { - return generateDerivedParameters(keySize); - } -} diff --git a/pointycastle/lib/key_derivators/scrypt.dart b/pointycastle/lib/key_derivators/scrypt.dart deleted file mode 100644 index 1101ea5..0000000 --- a/pointycastle/lib/key_derivators/scrypt.dart +++ /dev/null @@ -1,207 +0,0 @@ -// See file LICENSE for more information. - -library impl.key_derivator.scrypt; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/digests/sha256.dart'; -import 'package:pointycastle/key_derivators/api.dart'; -import 'package:pointycastle/key_derivators/pbkdf2.dart'; -import 'package:pointycastle/macs/hmac.dart'; -import 'package:pointycastle/src/impl/base_key_derivator.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// -/// Implementation of SCrypt password based key derivation function. See the next link for info on -/// how to choose N, r, and p: -/// * -/// -/// This implementation is based on Java implementation by Will Glozer, which can be found at: -/// * -/// -class Scrypt extends BaseKeyDerivator { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(KeyDerivator, 'scrypt', () => Scrypt()); - - static const int _maxValue = 0x7fffffff; - - ScryptParameters? _params; - - @override - final String algorithmName = 'scrypt'; - - @override - int get keySize => _params!.desiredKeyLength; - - void reset() { - _params = null; - } - - @override - void init(covariant ScryptParameters params) { - _params = params; - - final N = _params!.N; - final r = _params!.r; - final p = _params!.p; - - if (N < 2 || (N & (N - 1)) != 0) { - throw ArgumentError('N must be a power of 2 greater than 1'); - } - - if (N > _maxValue ~/ 128 ~/ r) { - throw ArgumentError('Parameter N is too large'); - } - - if (r > _maxValue ~/ 128 ~/ p) { - throw ArgumentError('Parameter r is too large'); - } - } - - @override - int deriveKey(Uint8List inp, int inpOff, Uint8List out, int outOff) { - if (_params == null) { - throw StateError('Initialize first.'); - } - - _scryptJ(inp, inpOff, out, outOff, _params!.salt, _params!.N, _params!.r, - _params!.p, _params!.desiredKeyLength); - - return keySize; - } - - void _scryptJ(Uint8List pwd, int pwdOff, Uint8List dk, int dkOff, - Uint8List salt, int N, int r, int p, int dkLen) { - final b = Uint8List(128 * r * p); - final xy = Uint8List(256 * r); - final v = Uint8List(128 * r * N); - - final pbkdf2 = PBKDF2KeyDerivator(HMac(SHA256Digest(), 64)); - - pbkdf2.init(Pbkdf2Parameters(salt, 1, p * 128 * r)); - pbkdf2.deriveKey(pwd, pwdOff, b, 0); - - for (var i = 0; i < p; i++) { - _smix(b, i * 128 * r, r, N, v, xy); - } - - pbkdf2.init(Pbkdf2Parameters(b, 1, dkLen)); - pbkdf2.deriveKey(pwd, pwdOff, dk, dkOff); - } - - void _smix(Uint8List B, int bi, int r, int N, Uint8List V, Uint8List xy) { - const xi = 0; - final yi = 128 * r; - - _arraycopy(B, bi, xy, xi, 128 * r); - - for (var i = 0; i < N; i++) { - _arraycopy(xy, xi, V, i * (128 * r), 128 * r); - _blockmixSalsa8(xy, xi, yi, r); - } - - for (var i = 0; i < N; i++) { - var j = _integerify(xy, xi, r) & (N - 1); - _blockxor(V, j * (128 * r), xy, xi, 128 * r); - _blockmixSalsa8(xy, xi, yi, r); - } - - _arraycopy(xy, xi, B, bi, 128 * r); - } - - final _b32 = List.filled(16, 0); - final _x = List.filled(16, 0); - - void _blockmixSalsa8(Uint8List by, int bi, int yi, int r) { - final byByteData = by.buffer.asByteData(by.offsetInBytes, by.length); - - for (var i = 0; i < 16; ++i) { - _b32[i] = - byByteData.getUint32(bi + (2 * r - 1) * 64 + i * 4, Endian.little); - } - - for (var i = 0; i < 2 * r; i++) { - for (var j = 0; j < 16; ++j) { - _b32[j] ^= byByteData.getUint32(i * 64 + j * 4, Endian.little); - _x[j] = _b32[j]; - } - _salsa20_8(); - for (var j = 0; j < 16; ++j) { - byByteData.setUint32(yi + (i * 64) + j * 4, _b32[j], Endian.little); - } - } - - for (var i = 0; i < r; i++) { - _arraycopy(by, yi + (i * 2) * 64, by, bi + (i * 64), 64); - } - - for (var i = 0; i < r; i++) { - _arraycopy(by, yi + (i * 2 + 1) * 64, by, bi + (i + r) * 64, 64); - } - } - - @pragma('vm:prefer-inline') - @pragma('dart2js:tryInline') - int _R(int sum, int n) => - ((sum << n) & 0xFFFFFFFF) | (sum & 0xFFFFFFFF) >> (32 - n); - - void _salsa20_8() { - for (var i = 8; i > 0; i -= 2) { - _x[4] ^= _R(_x[0] + _x[12], 7); - _x[8] ^= _R(_x[4] + _x[0], 9); - _x[12] ^= _R(_x[8] + _x[4], 13); - _x[0] ^= _R(_x[12] + _x[8], 18); - _x[9] ^= _R(_x[5] + _x[1], 7); - _x[13] ^= _R(_x[9] + _x[5], 9); - _x[1] ^= _R(_x[13] + _x[9], 13); - _x[5] ^= _R(_x[1] + _x[13], 18); - _x[14] ^= _R(_x[10] + _x[6], 7); - _x[2] ^= _R(_x[14] + _x[10], 9); - _x[6] ^= _R(_x[2] + _x[14], 13); - _x[10] ^= _R(_x[6] + _x[2], 18); - _x[3] ^= _R(_x[15] + _x[11], 7); - _x[7] ^= _R(_x[3] + _x[15], 9); - _x[11] ^= _R(_x[7] + _x[3], 13); - _x[15] ^= _R(_x[11] + _x[7], 18); - _x[1] ^= _R(_x[0] + _x[3], 7); - _x[2] ^= _R(_x[1] + _x[0], 9); - _x[3] ^= _R(_x[2] + _x[1], 13); - _x[0] ^= _R(_x[3] + _x[2], 18); - _x[6] ^= _R(_x[5] + _x[4], 7); - _x[7] ^= _R(_x[6] + _x[5], 9); - _x[4] ^= _R(_x[7] + _x[6], 13); - _x[5] ^= _R(_x[4] + _x[7], 18); - _x[11] ^= _R(_x[10] + _x[9], 7); - _x[8] ^= _R(_x[11] + _x[10], 9); - _x[9] ^= _R(_x[8] + _x[11], 13); - _x[10] ^= _R(_x[9] + _x[8], 18); - _x[12] ^= _R(_x[15] + _x[14], 7); - _x[13] ^= _R(_x[12] + _x[15], 9); - _x[14] ^= _R(_x[13] + _x[12], 13); - _x[15] ^= _R(_x[14] + _x[13], 18); - } - - for (var i = 0; i < 16; i++) { - _b32[i] = (_x[i] + _b32[i]) & 0xFFFFFFFF; - } - } - - void _blockxor(Uint8List s, int si, Uint8List d, int di, int len) { - for (var i = 0; i < len; i++) { - d[di + i] ^= s[si + i]; - } - } - - @pragma('vm:prefer-inline') - @pragma('dart2js:tryInline') - int _integerify(Uint8List b, int bi, int r) { - return b.buffer - .asByteData(b.offsetInBytes, b.length) - .getUint32(bi + (2 * r - 1) * 64, Endian.little); - } - - void _arraycopy( - List inp, int inpOff, List out, int outOff, int len) => - out.setRange(outOff, outOff + len, inp, inpOff); -} diff --git a/pointycastle/lib/key_generators/api.dart b/pointycastle/lib/key_generators/api.dart deleted file mode 100644 index b5d7cc6..0000000 --- a/pointycastle/lib/key_generators/api.dart +++ /dev/null @@ -1,27 +0,0 @@ -// See file LICENSE for more information. - -library api.key_generators; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/ecc/api.dart'; - -/// Abstract [CipherParameters] to init an ECC key generator. -class ECKeyGeneratorParameters extends KeyGeneratorParameters { - final ECDomainParameters _domainParameters; - - ECKeyGeneratorParameters(ECDomainParameters domainParameters) - : _domainParameters = domainParameters, - super(domainParameters.n.bitLength); - - ECDomainParameters get domainParameters => _domainParameters; -} - -/// Abstract [CipherParameters] to init an RSA key generator. -class RSAKeyGeneratorParameters extends KeyGeneratorParameters { - final BigInt publicExponent; - final int certainty; - - RSAKeyGeneratorParameters( - this.publicExponent, int bitStrength, this.certainty) - : super(bitStrength); -} diff --git a/pointycastle/lib/key_generators/ec_key_generator.dart b/pointycastle/lib/key_generators/ec_key_generator.dart deleted file mode 100644 index 2689ab4..0000000 --- a/pointycastle/lib/key_generators/ec_key_generator.dart +++ /dev/null @@ -1,50 +0,0 @@ -// See file LICENSE for more information. - -library impl.key_generator.ec_key_generator; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/key_generators/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// Abstract [CipherParameters] to init an ECC key generator. -class ECKeyGenerator implements KeyGenerator { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(KeyGenerator, 'EC', () => ECKeyGenerator()); - - late ECDomainParameters _params; - late SecureRandom _random; - - @override - String get algorithmName => 'EC'; - - @override - void init(CipherParameters params) { - ECKeyGeneratorParameters ecparams; - - if (params is ParametersWithRandom) { - _random = params.random; - ecparams = params.parameters as ECKeyGeneratorParameters; - } else { - _random = SecureRandom(); - ecparams = params as ECKeyGeneratorParameters; - } - - _params = ecparams.domainParameters; - } - - @override - AsymmetricKeyPair generateKeyPair() { - var n = _params.n; - var nBitLength = n.bitLength; - BigInt? d; - - do { - d = _random.nextBigInteger(nBitLength); - } while (d == BigInt.zero || (d >= n)); - - var Q = _params.G * d; - - return AsymmetricKeyPair(ECPublicKey(Q, _params), ECPrivateKey(d, _params)); - } -} diff --git a/pointycastle/lib/key_generators/rsa_key_generator.dart b/pointycastle/lib/key_generators/rsa_key_generator.dart deleted file mode 100644 index 9b3af75..0000000 --- a/pointycastle/lib/key_generators/rsa_key_generator.dart +++ /dev/null @@ -1,339 +0,0 @@ -// See file LICENSE for more information. - -library impl.key_generator.rsa_key_generator; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/asymmetric/api.dart'; -import 'package:pointycastle/key_generators/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -bool _testBit(BigInt i, int n) { - return (i & (BigInt.one << n)) != BigInt.zero; -} - -class RSAKeyGenerator implements KeyGenerator { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(KeyGenerator, 'RSA', () => RSAKeyGenerator()); - - late SecureRandom _random; - late RSAKeyGeneratorParameters _params; - - @override - String get algorithmName => 'RSA'; - - @override - void init(CipherParameters params) { - if (params is ParametersWithRandom) { - _random = params.random; - _params = params.parameters as RSAKeyGeneratorParameters; - } else { - _random = SecureRandom(); - _params = params as RSAKeyGeneratorParameters; - } - - if (_params.bitStrength < 12) { - throw ArgumentError('key bit strength cannot be smaller than 12'); - } - - if (!_testBit(_params.publicExponent, 0)) { - throw ArgumentError('Public exponent cannot be even'); - } - } - - @override - AsymmetricKeyPair generateKeyPair() { - BigInt p, q, n, e; - - // p and q values should have a length of half the strength in bits - var strength = _params.bitStrength; - var pbitlength = (strength + 1) ~/ 2; - var qbitlength = strength - pbitlength; - var mindiffbits = strength ~/ 3; - - e = _params.publicExponent; - - // TODO Consider generating safe primes for p, q (see DHParametersHelper.generateSafePrimes) - // (then p-1 and q-1 will not consist of only small factors - see "Pollard's algorithm") - - // generate p, prime and (p-1) relatively prime to e - while (true) { - p = generateProbablePrime(pbitlength, 1, _random); - - if (p % e == BigInt.one) { - continue; - } - - if (!_isProbablePrime(p, _params.certainty)) { - continue; - } - - if (e.gcd(p - BigInt.one) == BigInt.one) { - break; - } - } - - // generate a modulus of the required length - while (true) { - // generate q, prime and (q-1) relatively prime to e, and not equal to p - while (true) { - q = generateProbablePrime(qbitlength, 1, _random); - - if ((q - p).abs().bitLength < mindiffbits) { - continue; - } - - if (q % e == BigInt.one) { - continue; - } - - if (!_isProbablePrime(q, _params.certainty)) { - continue; - } - - if (e.gcd(q - BigInt.one) == BigInt.one) { - break; - } - } - - // calculate the modulus - n = p * q; - - if (n.bitLength == _params.bitStrength) { - break; - } - - // if we get here our primes aren't big enough, make the largest of the two p and try again - p = (p.compareTo(q) > 0) ? p : q; - } - - // Swap p and q if necessary - if (p < q) { - var swap = p; - p = q; - q = swap; - } - - // calculate the private exponent - var pSub1 = p - BigInt.one; - var qSub1 = q - BigInt.one; - var phi = pSub1 * qSub1; - var d = e.modInverse(phi); - - // ignore: deprecated_member_use_from_same_package - return AsymmetricKeyPair(RSAPublicKey(n, e), RSAPrivateKey(n, d, p, q, e)); - } -} - -/// [List] of low primes -final List _lowprimes = [ - BigInt.from(2), - BigInt.from(3), - BigInt.from(5), - BigInt.from(7), - BigInt.from(11), - BigInt.from(13), - BigInt.from(17), - BigInt.from(19), - BigInt.from(23), - BigInt.from(29), - BigInt.from(31), - BigInt.from(37), - BigInt.from(41), - BigInt.from(43), - BigInt.from(47), - BigInt.from(53), - BigInt.from(59), - BigInt.from(61), - BigInt.from(67), - BigInt.from(71), - BigInt.from(73), - BigInt.from(79), - BigInt.from(83), - BigInt.from(89), - BigInt.from(97), - BigInt.from(101), - BigInt.from(103), - BigInt.from(107), - BigInt.from(109), - BigInt.from(113), - BigInt.from(127), - BigInt.from(131), - BigInt.from(137), - BigInt.from(139), - BigInt.from(149), - BigInt.from(151), - BigInt.from(157), - BigInt.from(163), - BigInt.from(167), - BigInt.from(173), - BigInt.from(179), - BigInt.from(181), - BigInt.from(191), - BigInt.from(193), - BigInt.from(197), - BigInt.from(199), - BigInt.from(211), - BigInt.from(223), - BigInt.from(227), - BigInt.from(229), - BigInt.from(233), - BigInt.from(239), - BigInt.from(241), - BigInt.from(251), - BigInt.from(257), - BigInt.from(263), - BigInt.from(269), - BigInt.from(271), - BigInt.from(277), - BigInt.from(281), - BigInt.from(283), - BigInt.from(293), - BigInt.from(307), - BigInt.from(311), - BigInt.from(313), - BigInt.from(317), - BigInt.from(331), - BigInt.from(337), - BigInt.from(347), - BigInt.from(349), - BigInt.from(353), - BigInt.from(359), - BigInt.from(367), - BigInt.from(373), - BigInt.from(379), - BigInt.from(383), - BigInt.from(389), - BigInt.from(397), - BigInt.from(401), - BigInt.from(409), - BigInt.from(419), - BigInt.from(421), - BigInt.from(431), - BigInt.from(433), - BigInt.from(439), - BigInt.from(443), - BigInt.from(449), - BigInt.from(457), - BigInt.from(461), - BigInt.from(463), - BigInt.from(467), - BigInt.from(479), - BigInt.from(487), - BigInt.from(491), - BigInt.from(499), - BigInt.from(503), - BigInt.from(509) -]; - -final BigInt _lplim = (BigInt.one << 26) ~/ _lowprimes.last; - -final BigInt _bigTwo = BigInt.from(2); - -/// return index of lowest 1-bit in x, x < 2^31 -int _lbit(BigInt x) { - // Implementation borrowed from bignum.BigIntegerDartvm. - if (x == BigInt.zero) return -1; - var r = 0; - while ((x & BigInt.from(0xffffffff)) == BigInt.zero) { - x >>= 32; - r += 32; - } - if ((x & BigInt.from(0xffff)) == BigInt.zero) { - x >>= 16; - r += 16; - } - if ((x & BigInt.from(0xff)) == BigInt.zero) { - x >>= 8; - r += 8; - } - if ((x & BigInt.from(0xf)) == BigInt.zero) { - x >>= 4; - r += 4; - } - if ((x & BigInt.from(3)) == BigInt.zero) { - x >>= 2; - r += 2; - } - if ((x & BigInt.one) == BigInt.zero) ++r; - return r; -} - -/// true if probably prime (HAC 4.24, Miller-Rabin) */ -bool _millerRabin(BigInt b, int t) { - // Implementation borrowed from bignum.BigIntegerDartvm. - var n1 = b - BigInt.one; - var k = _lbit(n1); - if (k <= 0) return false; - var r = n1 >> k; - t = (t + 1) >> 1; - if (t > _lowprimes.length) t = _lowprimes.length; - BigInt a; - for (var i = 0; i < t; ++i) { - a = _lowprimes[i]; - var y = a.modPow(r, b); - if (y.compareTo(BigInt.one) != 0 && y.compareTo(n1) != 0) { - var j = 1; - while (j++ < k && y.compareTo(n1) != 0) { - y = y.modPow(_bigTwo, b); - if (y.compareTo(BigInt.one) == 0) return false; - } - if (y.compareTo(n1) != 0) return false; - } - } - return true; -} - -/// test primality with certainty >= 1-.5^t */ -bool _isProbablePrime(BigInt b, int t) { - // Implementation borrowed from bignum.BigIntegerDartvm. - int i; - var x = b.abs(); - if (b <= _lowprimes.last) { - for (i = 0; i < _lowprimes.length; ++i) { - if (b == _lowprimes[i]) return true; - } - return false; - } - if (x.isEven) return false; - i = 1; - while (i < _lowprimes.length) { - var m = _lowprimes[i], j = i + 1; - while (j < _lowprimes.length && m < _lplim) { - m *= _lowprimes[j++]; - } - m = x % m; - while (i < j) { - if (m % _lowprimes[i++] == BigInt.zero) { - return false; - } - } - } - return _millerRabin(x, t); -} - -BigInt generateProbablePrime(int bitLength, int certainty, SecureRandom rnd) { - if (bitLength < 2) { - return BigInt.one; - } - - var candidate = rnd.nextBigInteger(bitLength); - - // force MSB set - if (!_testBit(candidate, bitLength - 1)) { - candidate |= BigInt.one << (bitLength - 1); - } - - // force odd - if (candidate.isEven) { - candidate += BigInt.one; - } - - while (!_isProbablePrime(candidate, certainty)) { - candidate += _bigTwo; - if (candidate.bitLength > bitLength) { - candidate -= BigInt.one << (bitLength - 1); - } - } - - return candidate; -} diff --git a/pointycastle/lib/macs/cbc_block_cipher_mac.dart b/pointycastle/lib/macs/cbc_block_cipher_mac.dart deleted file mode 100644 index 63d3a19..0000000 --- a/pointycastle/lib/macs/cbc_block_cipher_mac.dart +++ /dev/null @@ -1,214 +0,0 @@ -// See file LICENSE for more information. - -library impl.mac.cbc_block_cipher_mac; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/impl/base_mac.dart'; -import 'package:pointycastle/block/modes/cbc.dart'; - -/// standard CBC Block Cipher MAC - if no padding is specified the default of -/// pad of zeroes is used. -class CBCBlockCipherMac extends BaseMac { - static final FactoryConfig factoryConfig = DynamicFactoryConfig.regex( - Mac, - r'^(.+)/CBC_CMAC(/(.+))?$', - (_, final Match match) => () { - var cipher = BlockCipher(match.group(1)!); - var padding = match.groupCount >= 3 && - match.group(3) != null && - match.group(3)!.isNotEmpty - ? Padding(match.group(3)!) - : null; - return CBCBlockCipherMac.fromCipherAndPadding(cipher, padding); - }, - ); - - late Uint8List _mac; - - late Uint8List _buf; - late int _bufOff; - final BlockCipher _cipher; - final Padding? _padding; - - final int _macSize; - - ParametersWithIV? _params; - - /// - /// create a standard MAC based on a CBC block cipher. This will produce an - /// authentication code half the length of the block size of the cipher. - /// - /// * [cipher] the cipher to be used as the basis of the MAC generation. - CBCBlockCipherMac.fromCipher(BlockCipher cipher) - : this(cipher, (cipher.blockSize * 8) ~/ 2, null); - - /// - /// create a standard MAC based on a CBC block cipher. This will produce an - /// authentication code half the length of the block size of the cipher. - /// - /// * [cipher] the cipher to be used as the basis of the MAC generation. - /// * [padding] the padding to be used to complete the last block. - CBCBlockCipherMac.fromCipherAndPadding(BlockCipher cipher, Padding? padding) - : this(cipher, (cipher.blockSize * 8) ~/ 2, padding); - - /// - /// create a standard MAC based on a block cipher with the size of the - /// MAC been given in bits. This class uses CBC mode as the basis for the - /// MAC generation. - /// - /// Note: the size of the MAC must be at least 24 bits (FIPS Publication 81), - /// or 16 bits if being used as a data authenticator (FIPS Publication 113), - /// and in general should be less than the size of the block cipher as it - /// reduces the chance of an exhaustive attack (see Handbook of Applied - /// Cryptography). - /// - /// * [cipher] the cipher to be used as the basis of the MAC generation. - /// * [macSizeInBits] the size of the MAC in bits, must be a multiple of 8. - CBCBlockCipherMac.fromCipherAndMacSize(BlockCipher cipher, int macSizeInBits) - : this(cipher, macSizeInBits, null); - - /// - /// create a standard MAC based on a block cipher with the size of the - /// MAC been given in bits. This class uses CBC mode as the basis for the - /// MAC generation. - /// - /// Note: the size of the MAC must be at least 24 bits (FIPS Publication 81), - /// or 16 bits if being used as a data authenticator (FIPS Publication 113), - /// and in general should be less than the size of the block cipher as it - /// reduces the chance of an exhaustive attack (see Handbook of Applied - /// Cryptography). - /// - /// * [cipher] the cipher to be used as the basis of the MAC generation. - /// * [macSizeInBits] the size of the MAC in bits, must be a multiple of 8. - /// * [padding] the padding to be used to complete the last block. - CBCBlockCipherMac(BlockCipher cipher, int macSizeInBits, Padding? padding) - : _cipher = CBCBlockCipher(cipher), - _macSize = macSizeInBits ~/ 8, - _padding = padding { - if ((macSizeInBits % 8) != 0) { - throw ArgumentError('MAC size must be multiple of 8'); - } - - _mac = Uint8List(cipher.blockSize); - - _buf = Uint8List(cipher.blockSize); - _bufOff = 0; - } - - @override - String get algorithmName { - var paddingName = _padding != null ? '/${_padding.algorithmName}' : ''; - return '${_cipher.algorithmName}_CMAC$paddingName'; - } - - @override - void init(CipherParameters params) { - if (params is ParametersWithIV) { - _params = params; - } else if (params is KeyParameter) { - final zeroIV = Uint8List(params.key.length); - _params = ParametersWithIV(params, zeroIV); - } - - reset(); - - _cipher.init(true, _params); - } - - @override - int get macSize => _macSize; - - @override - void updateByte(int inp) { - if (_bufOff == _buf.length) { - _cipher.processBlock(_buf, 0, _mac, 0); - _bufOff = 0; - } - - _buf[_bufOff++] = inp; - } - - @override - void update(Uint8List inp, int inOff, int len) { - if (len < 0) { - throw ArgumentError('Can\'t have a negative input length!'); - } - - var blockSize = _cipher.blockSize; - var gapLen = blockSize - _bufOff; - - if (len > gapLen) { - _buf.setRange(_bufOff, _bufOff + gapLen, inp.sublist(inOff)); - - _cipher.processBlock(_buf, 0, _mac, 0); - - _bufOff = 0; - len -= gapLen; - inOff += gapLen; - - while (len > blockSize) { - _cipher.processBlock(inp, inOff, _mac, 0); - - len -= blockSize; - inOff += blockSize; - } - } - - _buf.setRange(_bufOff, _bufOff + len, inp.sublist(inOff)); - - _bufOff += len; - } - - /// Reset the mac generator. - @override - void reset() { - // clean the buffer. - for (var i = 0; i < _buf.length; i++) { - _buf[i] = 0; - } - - _bufOff = 0; - - // reset the underlying cipher. - _cipher.reset(); - - _cipher.init(true, _params); - - if (_params != null) { - _cipher.init(true, _params); - } - } - - @override - int doFinal(Uint8List out, int outOff) { - var blockSize = _cipher.blockSize; - - if (_padding == null) { - // - // pad with zeroes - // - while (_bufOff < blockSize) { - _buf[_bufOff] = 0; - _bufOff++; - } - } else { - if (_bufOff == blockSize) { - _cipher.processBlock(_buf, 0, _mac, 0); - _bufOff = 0; - } - - _padding.addPadding(_buf, _bufOff); - } - - _cipher.processBlock(_buf, 0, _mac, 0); - - out.setRange(outOff, outOff + _macSize, _mac); - - reset(); - - return _macSize; - } -} diff --git a/pointycastle/lib/macs/cmac.dart b/pointycastle/lib/macs/cmac.dart deleted file mode 100644 index c317080..0000000 --- a/pointycastle/lib/macs/cmac.dart +++ /dev/null @@ -1,287 +0,0 @@ -// See file LICENSE for more information. - -library impl.mac.cmac; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/impl/base_mac.dart'; -import 'package:pointycastle/paddings/iso7816d4.dart'; -import 'package:pointycastle/block/modes/cbc.dart'; - -/// CMAC - as specified at www.nuee.nagoya-u.ac.jp/labs/tiwata/omac/omac.html -///

-/// CMAC is analogous to OMAC1 - see also en.wikipedia.org/wiki/CMAC -///

-/// CMAC is a NIST recomendation - see -/// csrc.nist.gov/CryptoToolkit/modes/800-38_Series_Publications/SP800-38B.pdf -///

-/// CMAC/OMAC1 is a blockcipher-based message authentication code designed and -/// analyzed by Tetsu Iwata and Kaoru Kurosawa. -///

-/// CMAC/OMAC1 is a simple variant of the CBC MAC (Cipher Block Chaining Message -/// Authentication Code). OMAC stands for One-Key CBC MAC. -///

-/// It supports 128- or 64-bits block ciphers, with any key size, and returns -/// a MAC with dimension less or equal to the block size of the underlying -/// cipher. -///

-class CMac extends BaseMac { - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - Mac, - '/CMAC', - (_, final Match match) => () { - var cipher = BlockCipher(match.group(1)!); - return CMac.fromCipher(cipher); - }, - ); - - late Uint8List _poly; - late Uint8List _zeros; - - late Uint8List _mac; - - late Uint8List _buf; - late int _bufOff; - final BlockCipher _cipher; - - final int _macSize; - - late Uint8List _lu, _lu2; - - ParametersWithIV? _params; - - /// - /// create a standard MAC based on a CBC block cipher (64 or 128 bit block). - /// This will produce an authentication code the length of the block size - /// of the cipher. - /// - /// @param cipher the cipher to be used as the basis of the MAC generation. - CMac.fromCipher(BlockCipher cipher) : this(cipher, cipher.blockSize * 8); - - /// - /// create a standard MAC based on a block cipher with the size of the - /// MAC been given in bits. - ///

- /// Note: the size of the MAC must be at least 24 bits (FIPS Publication 81), - /// or 16 bits if being used as a data authenticator (FIPS Publication 113), - /// and in general should be less than the size of the block cipher as it - /// reduces the chance of an exhaustive attack (see Handbook of Applied - /// Cryptography). - /// - /// @param cipher the cipher to be used as the basis of the MAC generation. - /// @param macSizeInBits the size of the MAC in bits, must be a multiple of 8 and <= 128. - CMac(BlockCipher cipher, int macSizeInBits) - : _macSize = macSizeInBits ~/ 8, - _cipher = CBCBlockCipher(cipher) { - if ((macSizeInBits % 8) != 0) { - throw ArgumentError('MAC size must be multiple of 8'); - } - - if (macSizeInBits > (_cipher.blockSize * 8)) { - throw ArgumentError( - 'MAC size must be less or equal to ${_cipher.blockSize * 8}'); - } - - _poly = lookupPoly(cipher.blockSize); - - _mac = Uint8List(cipher.blockSize); - - _buf = Uint8List(cipher.blockSize); - - _zeros = Uint8List(cipher.blockSize); - - _bufOff = 0; - } - - @override - String get algorithmName { - var blockCipherAlgorithmName = _cipher.algorithmName.split('/').first; - return '$blockCipherAlgorithmName/CMAC'; - } - - static int shiftLeft(Uint8List block, Uint8List output) { - var i = block.length; - var bit = 0; - while (--i >= 0) { - var b = block[i] & 0xff; - output[i] = (b << 1) | bit; - bit = (b >> 7) & 1; - } - return bit; - } - - Uint8List _doubleLu(Uint8List inp) { - var ret = Uint8List(inp.length); - var carry = shiftLeft(inp, ret); - - // NOTE: This construction is an attempt at a constant-time implementation. - var mask = (-carry) & 0xff; - ret[inp.length - 3] ^= _poly[1] & mask; - ret[inp.length - 2] ^= _poly[2] & mask; - ret[inp.length - 1] ^= _poly[3] & mask; - - return ret; - } - - static Uint8List lookupPoly(int blockSizeLength) { - int xor; - switch (blockSizeLength * 8) { - case 64: - xor = 0x1B; - break; - case 128: - xor = 0x87; - break; - case 160: - xor = 0x2D; - break; - case 192: - xor = 0x87; - break; - case 224: - xor = 0x309; - break; - case 256: - xor = 0x425; - break; - case 320: - xor = 0x1B; - break; - case 384: - xor = 0x100D; - break; - case 448: - xor = 0x851; - break; - case 512: - xor = 0x125; - break; - case 768: - xor = 0xA0011; - break; - case 1024: - xor = 0x80043; - break; - case 2048: - xor = 0x86001; - break; - default: - throw ArgumentError( - 'Unknown block size for CMAC: ${blockSizeLength * 8}'); - } - - final out = Uint8List(4); - out[3] = xor >> 0; - out[2] = xor >> 8; - out[1] = xor >> 16; - out[0] = xor >> 24; - return out; - } - - @override - void init(covariant KeyParameter keyParams) { - final zeroIV = Uint8List(keyParams.key.length); - _params = ParametersWithIV(keyParams, zeroIV); - - // Initialize before computing L, Lu, Lu2 - _cipher.init(true, _params!); - - //initializes the L, Lu, Lu2 numbers - var L = Uint8List(_zeros.length); - _cipher.processBlock(_zeros, 0, L, 0); - _lu = _doubleLu(L); - _lu2 = _doubleLu(_lu); - - // Reset _buf/_cipher state after computing L, Lu, Lu2 - reset(); - } - - @override - int get macSize => _macSize; - - @override - void updateByte(int inp) { - if (_bufOff == _buf.length) { - _cipher.processBlock(_buf, 0, _mac, 0); - _bufOff = 0; - } - - _buf[_bufOff++] = inp; - } - - @override - void update(Uint8List inp, int inOff, int len) { - if (len < 0) { - throw ArgumentError('Can\'t have a negative input length!'); - } - - var blockSize = _cipher.blockSize; - var gapLen = blockSize - _bufOff; - - if (len > gapLen) { - _buf.setRange(_bufOff, _bufOff + gapLen, inp.sublist(inOff)); - - _cipher.processBlock(_buf, 0, _mac, 0); - - _bufOff = 0; - len -= gapLen; - inOff += gapLen; - - while (len > blockSize) { - _cipher.processBlock(inp, inOff, _mac, 0); - - len -= blockSize; - inOff += blockSize; - } - } - - _buf.setRange(_bufOff, _bufOff + len, inp.sublist(inOff)); - - _bufOff += len; - } - - @override - int doFinal(Uint8List out, int outOff) { - var blockSize = _cipher.blockSize; - - Uint8List? lu; - if (_bufOff == blockSize) { - lu = _lu; - } else { - ISO7816d4Padding().addPadding(_buf, _bufOff); - lu = _lu2; - } - - for (var i = 0; i < _mac.length; i++) { - _buf[i] ^= lu[i]; - } - - _cipher.processBlock(_buf, 0, _mac, 0); - - out.setRange(outOff, outOff + _macSize, _mac); - - reset(); - - return _macSize; - } - - /// Reset the mac generator. - @override - void reset() { - // clean the buffer. - for (var i = 0; i < _buf.length; i++) { - _buf[i] = 0; - } - - _bufOff = 0; - - // reset the underlying cipher. - _cipher.reset(); - - if (_params != null) { - _cipher.init(true, _params!); - } - } -} diff --git a/pointycastle/lib/macs/hmac.dart b/pointycastle/lib/macs/hmac.dart deleted file mode 100644 index 426b8f0..0000000 --- a/pointycastle/lib/macs/hmac.dart +++ /dev/null @@ -1,120 +0,0 @@ -// See file LICENSE for more information. - -library impl.mac.hmac; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_mac.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// HMAC implementation based on RFC2104 -/// -/// H(K XOR opad, H(K XOR ipad, text)) -class HMac extends BaseMac { - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - Mac, - '/HMAC', - (_, Match match) { - final digestName = match.group(1); - return () { - return HMac.withDigest(Digest(digestName!)); - }; - }, - ); - - //TODO reindent - - static final _ipad = 0x36; - static final _opad = 0x5C; - - final Digest _digest; - late int _digestSize; - late int _blockLength; - - late Uint8List _inputPad; - late Uint8List _outputBuf; - - HMac(this._digest, this._blockLength) { - _digestSize = _digest.digestSize; - _inputPad = Uint8List(_blockLength); - _outputBuf = Uint8List(_blockLength + _digestSize); - } - - HMac.withDigest(this._digest) { - _blockLength = _digest.byteLength; - - _digestSize = _digest.digestSize; - _inputPad = Uint8List(_blockLength); - _outputBuf = Uint8List(_blockLength + _digestSize); - } - - @override - String get algorithmName => '${_digest.algorithmName}/HMAC'; - - @override - int get macSize => _digestSize; - - @override - void reset() { - // reset the underlying digest. - _digest.reset(); - - // reinitialize the digest. - _digest.update(_inputPad, 0, _inputPad.length); - } - - @override - void init(covariant KeyParameter params) { - _digest.reset(); - - var key = params.key; - var keyLength = key.length; - - if (keyLength > _blockLength) { - _digest.update(key, 0, keyLength); - _digest.doFinal(_inputPad, 0); - - keyLength = _digestSize; - } else { - _inputPad.setRange(0, keyLength, key); - } - - _inputPad.fillRange(keyLength, _inputPad.length, 0); - - _outputBuf.setRange(0, _blockLength, _inputPad); - - _xorPad(_inputPad, _blockLength, _ipad); - _xorPad(_outputBuf, _blockLength, _opad); - - _digest.update(_inputPad, 0, _inputPad.length); - } - - @override - void updateByte(int inp) { - _digest.updateByte(inp); - } - - @override - void update(Uint8List inp, int inpOff, int len) { - _digest.update(inp, inpOff, len); - } - - @override - int doFinal(Uint8List out, int outOff) { - _digest.doFinal(_outputBuf, _blockLength); - _digest.update(_outputBuf, 0, _outputBuf.length); - - var len = _digest.doFinal(out, outOff); - _outputBuf.fillRange(_blockLength, _outputBuf.length, 0); - _digest.update(_inputPad, 0, _inputPad.length); - - return len; - } - - void _xorPad(Uint8List pad, int len, int n) { - for (var i = 0; i < len; i++) { - pad[i] ^= n; - } - } -} diff --git a/pointycastle/lib/macs/poly1305.dart b/pointycastle/lib/macs/poly1305.dart deleted file mode 100644 index 9ee4b51..0000000 --- a/pointycastle/lib/macs/poly1305.dart +++ /dev/null @@ -1,323 +0,0 @@ -// This file has been migrated. - -library impl.mac.poly1305; - -import 'dart:typed_data'; - -import 'package:pointycastle/src/platform_check/platform_check.dart'; - -import '../api.dart'; -import '../src/impl/base_mac.dart'; -import '../src/registry/registry.dart'; -import '../src/ufixnum.dart'; -import '../src/utils.dart'; - -class Poly1305 extends BaseMac { - static const R_MASK_LOW_2 = 0xFC; - static const R_MASK_HIGH_4 = 0x0F; - - Poly1305() { - Platform.instance.assertFullWidthInteger(); - cipher = null; - } - - Poly1305.withCipher(this.cipher) { - Platform.instance.assertFullWidthInteger(); - if (cipher!.blockSize != BLOCK_SIZE) { - throw ArgumentError('Poly1305 requires a 128 bit block cipher.'); - } - } - - // ignore: non_constant_identifier_names - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - Mac, - '/Poly1305', - (_, final Match match) => () { - var cipher = BlockCipher(match.group(1)!); - return Poly1305.withCipher(cipher); - }, - ); - - static void clamp(Uint8List key) { - key[3] &= R_MASK_HIGH_4; - key[7] &= R_MASK_HIGH_4; - key[11] &= R_MASK_HIGH_4; - key[15] &= R_MASK_HIGH_4; - - key[4] &= R_MASK_LOW_2; - key[8] &= R_MASK_LOW_2; - key[12] &= R_MASK_LOW_2; - } - - static bool checkKey(Uint8List key) { - var c1 = checkMask(key[3], R_MASK_HIGH_4); - var c2 = checkMask(key[7], R_MASK_HIGH_4); - var c3 = checkMask(key[11], R_MASK_HIGH_4); - var c4 = checkMask(key[15], R_MASK_HIGH_4); - - var c5 = checkMask(key[4], R_MASK_LOW_2); - var c6 = checkMask(key[8], R_MASK_LOW_2); - var c7 = checkMask(key[12], R_MASK_LOW_2); - - return !(c1 || c2 || c3 || c4 || c5 || c6 || c7); - } - - static bool checkMask(int b, int mask) { - if (b & not32(mask) != 0) { - return false; - } - return true; - } - - @override - String get algorithmName => - cipher == null ? 'Poly1305' : '${cipher!.algorithmName}/Poly1305'; - - @override - int get macSize => BLOCK_SIZE; - - static const BLOCK_SIZE = 16; - - BlockCipher? cipher; - - final Uint8List singleByte = Uint8List(1); - - late int r0, r1, r2, r3, r4; - - late int s1, s2, s3, s4; - - late int k0, k1, k2, k3; - - final Uint8List currentBlock = Uint8List(BLOCK_SIZE); - - int currentBlockOffset = 0; - - late int h0, h1, h2, h3, h4; - - @override - void init(CipherParameters params) { - Uint8List? nonce; - - if (cipher != null) { - if (params is! ParametersWithIV) { - throw ArgumentError( - 'Poly1305 requires an IV when used with a block cipher.'); - } - - nonce = params.iv; - params = params.parameters!; - } - - if (params is! KeyParameter) { - throw ArgumentError('Poly1305 requires a key.'); - } - - if (!checkKey(params.key)) clamp(params.key); - - setKey(params.key, nonce); - - reset(); - } - - void setKey(Uint8List key, Uint8List? nonce) { - if (key.length != 32) throw ArgumentError('Poly1305 key must be 256 bits.'); - if (cipher != null && (nonce == null || nonce.length != BLOCK_SIZE)) { - throw ArgumentError('Poly1305-AES requires a 128 bit IV.'); - } - - var keyByteData = ByteData.view(key.buffer, key.offsetInBytes, key.length); - var t0 = unpack32(keyByteData, 0, Endian.little); - var t1 = unpack32(keyByteData, 4, Endian.little); - var t2 = unpack32(keyByteData, 8, Endian.little); - var t3 = unpack32(keyByteData, 12, Endian.little); - - r0 = t0 & (0x03FFFFFF); - r1 = (cshiftr32(t0, 26) | shiftl32(t1, 6)) & 0x03FFFF03; - r2 = (cshiftr32(t1, 20) | shiftl32(t2, 12)) & 0x03FFC0FF; - r3 = (cshiftr32(t2, 14) | shiftl32(t3, 18)) & 0x03F03FFF; - r4 = (cshiftr32(t3, 8)) & 0x000FFFFF; - - s1 = r1 * 5; - s2 = r2 * 5; - s3 = r3 * 5; - s4 = r4 * 5; - - Uint8List kBytes; - int kOff; - if (cipher == null) { - kBytes = key; - kOff = BLOCK_SIZE; - } else { - kBytes = Uint8List(BLOCK_SIZE); - kOff = 0; - - cipher!.init(true, KeyParameter.offset(key, BLOCK_SIZE, BLOCK_SIZE)); - cipher!.processBlock(nonce!, 0, kBytes, 0); - } - - var kByteData = - ByteData.view(kBytes.buffer, kBytes.offsetInBytes, kBytes.length); - k0 = unpack32(kByteData, kOff, Endian.little); - k1 = unpack32(kByteData, kOff + 4, Endian.little); - k2 = unpack32(kByteData, kOff + 8, Endian.little); - k3 = unpack32(kByteData, kOff + 12, Endian.little); - } - - @override - void updateByte(final int inp) { - singleByte[0] = inp; - update(singleByte, 0, 1); - } - - @override - void update(final Uint8List inp, final int inOff, final int len) { - var copied = 0; - while (len > copied) { - if (currentBlockOffset == BLOCK_SIZE) { - processBlock(); - currentBlockOffset = 0; - } - - var toCopy = (len - copied) > (BLOCK_SIZE - currentBlockOffset) - ? (BLOCK_SIZE - currentBlockOffset) - : (len - copied); - arrayCopy(inp, copied + inOff, currentBlock, currentBlockOffset, toCopy); - copied += toCopy; - currentBlockOffset += toCopy; - } - } - - void processBlock() { - // TODO Calculation varied between web and native. - if (currentBlockOffset < BLOCK_SIZE) { - currentBlock[currentBlockOffset] = 1; - for (var i = currentBlockOffset + 1; i < BLOCK_SIZE; i++) { - currentBlock[i] = 0; - } - } - - final t0 = unpack32(currentBlock, 0, Endian.little); - final t1 = unpack32(currentBlock, 4, Endian.little); - final t2 = unpack32(currentBlock, 8, Endian.little); - final t3 = unpack32(currentBlock, 12, Endian.little); - - h0 += t0 & 0x3ffffff; - h1 += uRS((t1 << 32) | t0, 26) & 0x3ffffff; - h2 += uRS((t2 << 32) | t1, 20) & 0x3ffffff; - h3 += uRS((t3 << 32) | t2, 14) & 0x3ffffff; - h4 += uRS(t3, 8); - - if (currentBlockOffset == BLOCK_SIZE) { - h4 += shiftl32(1, 24); - } - - var tp0 = h0 * r0 + h1 * s4 + h2 * s3 + h3 * s2 + h4 * s1; - var tp1 = h0 * r1 + h1 * r0 + h2 * s4 + h3 * s3 + h4 * s2; - var tp2 = h0 * r2 + h1 * r1 + h2 * r0 + h3 * s4 + h4 * s3; - var tp3 = h0 * r3 + h1 * r2 + h2 * r1 + h3 * r0 + h4 * s4; - var tp4 = h0 * r4 + h1 * r3 + h2 * r2 + h3 * r1 + h4 * r0; - - h0 = (tp0 & 0xffffffff) & 0x3ffffff; - tp1 += uRS(tp0, 26); - h1 = (tp1 & 0xffffffff) & 0x3ffffff; - tp2 += uRS(tp1, 26); - h2 = (tp2 & 0xffffffff) & 0x3ffffff; - tp3 += uRS(tp2, 26); - h3 = (tp3 & 0xffffffff) & 0x3ffffff; - tp4 += uRS(tp3, 26); - h4 = (tp4 & 0xffffffff) & 0x3ffffff; - - h0 += (uRS(tp4, 26) & 0xffffffff) * 5; - h1 += cshiftr32(h0, 26); - h0 &= 0x3ffffff; - } - - @override - int doFinal(Uint8List out, final int outOff) { - if (outOff + BLOCK_SIZE > out.length) { - throw ArgumentError('Output buffer is too short.'); - } - - if (currentBlockOffset > 0) { - processBlock(); - } - - h1 += cshiftr32(h0, 26); - h0 &= 0x3ffffff; - h2 += cshiftr32(h1, 26); - h1 &= 0x3ffffff; - h3 += cshiftr32(h2, 26); - h2 &= 0x3ffffff; - h4 += cshiftr32(h3, 26); - h3 &= 0x3ffffff; - h0 += cshiftr32(h4, 26) * 5; - h4 &= 0x3ffffff; - h1 += cshiftr32(h0, 26); - h0 &= 0x3ffffff; - - int g0, g1, g2, g3, g4, b; - g0 = sum32(h0, 5); - b = cshiftr32(g0, 26); - g0 &= 0x3ffffff; - g1 = sum32(h1, b); - b = cshiftr32(g1, 26); - g1 &= 0x3ffffff; - g2 = sum32(h2, b); - b = cshiftr32(g2, 26); - g2 &= 0x3ffffff; - g3 = sum32(h3, b); - b = cshiftr32(g3, 26); - g3 &= 0x3ffffff; - g4 = sum32(h4, b) - shiftl32(1, 26); - - b = cshiftr32(g4, 31) - 1; - var nb = not32(b); - h0 = (h0 & nb) | (g0 & b); - h1 = (h1 & nb) | (g1 & b); - h2 = (h2 & nb) | (g2 & b); - h3 = (h3 & nb) | (g3 & b); - h4 = (h4 & nb) | (g4 & b); - - int f0, f1, f2, f3; - f0 = (h0 | shiftl32(h1, 26)) + k0; - f1 = (cshiftr32(h1, 6) | shiftl32(h2, 20)) + k1; - f2 = (cshiftr32(h2, 12) | shiftl32(h3, 14)) + k2; - f3 = (cshiftr32(h3, 18) | shiftl32(h4, 8)) + k3; - - var outByte = ByteData.view(out.buffer, out.offsetInBytes, out.length); - pack32(f0 & 0xffffffff, outByte, outOff, Endian.little); - f1 += uRS(f0, 32); - pack32(f1 & 0xffffffff, outByte, outOff + 4, Endian.little); - f2 += uRS(f1, 32); - pack32(f2 & 0xffffffff, outByte, outOff + 8, Endian.little); - f3 += uRS(f2, 32); - pack32(f3 & 0xffffffff, outByte, outOff + 12, Endian.little); - //End come back here chunk - - out = outByte.buffer.asUint8List(); - - reset(); - return BLOCK_SIZE; - } - - @override - void reset() { - currentBlockOffset = 0; - - h0 = 0; - h1 = 0; - h2 = 0; - h3 = 0; - h4 = 0; - } -} - -int uRS(int x, int n) { - return x >= 0 ? x >> n : ~(~x >> n); -} - -/* -int uRS(int x, int n) { - return (x >= 0) ? x >> (64 - n) : ~(~x >> (64 - n)); -} -*/ diff --git a/pointycastle/lib/padded_block_cipher/padded_block_cipher_impl.dart b/pointycastle/lib/padded_block_cipher/padded_block_cipher_impl.dart deleted file mode 100644 index ae859b4..0000000 --- a/pointycastle/lib/padded_block_cipher/padded_block_cipher_impl.dart +++ /dev/null @@ -1,121 +0,0 @@ -// See file LICENSE for more information. - -library impl.padded_block_cipher.padded_block_cipher_impl; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// The standard implementation of [PaddedBlockCipher]. -class PaddedBlockCipherImpl implements PaddedBlockCipher { - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig.regex( - PaddedBlockCipher, - r'^(.+)/([^/]+)$', - (_, final Match match) => () { - var padding = Padding(match.group(2)!); - var underlyingCipher = BlockCipher(match.group(1)!); - return PaddedBlockCipherImpl(padding, underlyingCipher); - }); - - @override - final Padding padding; - @override - final BlockCipher cipher; - - bool? _encrypting; - - PaddedBlockCipherImpl(this.padding, this.cipher); - - @override - String get algorithmName => - '${cipher.algorithmName}/${padding.algorithmName}'; - - @override - int get blockSize => cipher.blockSize; - - @override - void reset() { - _encrypting = null; - cipher.reset(); - } - - @override - void init(bool forEncryption, covariant PaddedBlockCipherParameters params) { - _encrypting = forEncryption; - cipher.init(forEncryption, params.underlyingCipherParameters); - padding.init(params.paddingCipherParameters); - } - - @override - Uint8List process(Uint8List data) { - var inputBlocks = (data.length + blockSize - 1) ~/ blockSize; - - int outputBlocks; - if (_encrypting ?? false) { - outputBlocks = (data.length + blockSize) ~/ blockSize; - } else { - if ((data.length % blockSize) != 0) { - throw ArgumentError( - 'Input data length must be a multiple of cipher\'s block size'); - } - outputBlocks = inputBlocks; - } - - var out = Uint8List(outputBlocks * blockSize); - - for (var i = 0; i < (inputBlocks - 1); i++) { - var offset = i * blockSize; - processBlock(data, offset, out, offset); - } - - var lastBlockOffset = (inputBlocks - 1) * blockSize; - var lastBlockSize = doFinal(data, lastBlockOffset, out, lastBlockOffset); - - return out.sublist(0, lastBlockOffset + lastBlockSize); - } - - @override - int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { - return cipher.processBlock(inp, inpOff, out, outOff); - } - - @override - int doFinal(Uint8List inp, int inpOff, Uint8List out, int outOff) { - if (_encrypting ?? false) { - var lastInputBlock = Uint8List(blockSize)..setAll(0, inp.sublist(inpOff)); - - var remainder = inp.length - inpOff; - - if (remainder < blockSize) { - // Padding goes embedded in last block of data - padding.addPadding(lastInputBlock, inp.length - inpOff); - - processBlock(lastInputBlock, 0, out, outOff); - - return blockSize; - } else { - // Padding goes alone in an additional block - processBlock(inp, inpOff, out, outOff); - - padding.addPadding(lastInputBlock, 0); - - processBlock(lastInputBlock, 0, out, outOff + blockSize); - - return 2 * blockSize; - } - } else { - // Decrypt last block and remove padding - processBlock(inp, inpOff, out, outOff); - - var padCount = padding.padCount(out.sublist(outOff)); - - var padOffsetInBlock = blockSize - padCount; - - out.fillRange(outOff + padOffsetInBlock, out.length, 0); - - return padOffsetInBlock; - } - } -} diff --git a/pointycastle/lib/paddings/iso7816d4.dart b/pointycastle/lib/paddings/iso7816d4.dart deleted file mode 100644 index db4fca4..0000000 --- a/pointycastle/lib/paddings/iso7816d4.dart +++ /dev/null @@ -1,57 +0,0 @@ -// See file LICENSE for more information. - -library impl.padding.iso7816d4; - -import 'dart:typed_data' show Uint8List; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_padding.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// A padder that adds the padding according to the scheme referenced in -/// ISO 7814-4 - scheme 2 from ISO 9797-1. The first byte is 0x80, rest is 0x00 -class ISO7816d4Padding extends BasePadding { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Padding, 'ISO7816-4', () => ISO7816d4Padding()); - - @override - String get algorithmName => 'ISO7816-4'; - - @override - void init([CipherParameters? params]) { - // nothing to do. - } - - /// add the pad bytes to the passed in block, returning the - /// number of bytes added. - @override - int addPadding(Uint8List data, int offset) { - var added = data.length - offset; - - data[offset] = 0x80; - offset++; - - while (offset < data.length) { - data[offset] = 0; - offset++; - } - - return added; - } - - /// return the number of pad bytes present in the block. - @override - int padCount(Uint8List data) { - var count = data.length - 1; - - while (count > 0 && data[count] == 0) { - count--; - } - - if (data[count] != 0x80) { - throw ArgumentError('pad block corrupted'); - } - - return data.length - count; - } -} diff --git a/pointycastle/lib/paddings/pkcs7.dart b/pointycastle/lib/paddings/pkcs7.dart deleted file mode 100644 index 0fff9df..0000000 --- a/pointycastle/lib/paddings/pkcs7.dart +++ /dev/null @@ -1,53 +0,0 @@ -// See file LICENSE for more information. - -library impl.padding.pkcs7; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_padding.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// A [Padding] that adds PKCS7/PKCS5 padding to a block. -class PKCS7Padding extends BasePadding { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(Padding, 'PKCS7', () => PKCS7Padding()); - - @override - String get algorithmName => 'PKCS7'; - - @override - void init([CipherParameters? params]) { - // nothing to do. - } - - @override - int addPadding(Uint8List data, int offset) { - var code = data.length - offset; - - while (offset < data.length) { - data[offset] = code; - offset++; - } - - return code; - } - - @override - int padCount(Uint8List data) { - var count = clip8(data[data.length - 1]); - - if (count > data.length || count == 0) { - throw ArgumentError('Invalid or corrupted pad block'); - } - - for (var i = 1; i <= count; i++) { - if (data[data.length - i] != count) { - throw ArgumentError('Invalid or corrupted pad block'); - } - } - - return count; - } -} diff --git a/pointycastle/lib/pointycastle.dart b/pointycastle/lib/pointycastle.dart deleted file mode 100644 index 9fd5d74..0000000 --- a/pointycastle/lib/pointycastle.dart +++ /dev/null @@ -1,15 +0,0 @@ -// See file LICENSE for more information. - -/// -/// This is the main entry point to the cipher library API. -/// -/// It includes the following libraries: -/// * **api.dart** = comprises the whole API specification -/// * **impl.dart** = defines algorithm implementations and all cipherParameters to be used with them -/// * **asn1.dart** = ASN1 library to encode and decode ASN1 objects -/// -library pointycastle; - -export 'package:pointycastle/api.dart'; -export 'package:pointycastle/impl.dart'; -export 'package:pointycastle/asn1.dart'; diff --git a/pointycastle/lib/random/auto_seed_block_ctr_random.dart b/pointycastle/lib/random/auto_seed_block_ctr_random.dart deleted file mode 100644 index 6d6f8fa..0000000 --- a/pointycastle/lib/random/auto_seed_block_ctr_random.dart +++ /dev/null @@ -1,105 +0,0 @@ -// See file LICENSE for more information. - -library impl.secure_random.auto_seed_block_ctr_random; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/random/block_ctr_random.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// An implementation of [SecureRandom] that uses a [BlockCipher] with CTR mode to generate random -/// values and automatically self reseeds itself after each request for data, in order to achieve -/// forward security. See section 4.1 of the paper: -/// Practical Random Number Generation in Software (by John Viega). -class AutoSeedBlockCtrRandom implements SecureRandom { - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig.regex( - SecureRandom, - r'^(.*)/CTR/AUTO-SEED-PRNG$', - (_, final Match match) => () { - var blockCipherName = match.group(1); - var blockCipher = BlockCipher(blockCipherName!); - return AutoSeedBlockCtrRandom(blockCipher); - }); - - late BlockCtrRandom _delegate; - final bool _reseedIV; - - var _inAutoReseed = false; - late int _autoReseedKeyLength; - - @override - String get algorithmName => - '${_delegate.cipher.algorithmName}/CTR/AUTO-SEED-PRNG'; - - AutoSeedBlockCtrRandom(BlockCipher cipher, [this._reseedIV = true]) { - _delegate = BlockCtrRandom(cipher); - } - - @override - void seed(CipherParameters params) { - if (params is ParametersWithIV) { - _autoReseedKeyLength = params.parameters!.key.length; - _delegate.seed(params); - } else if (params is KeyParameter) { - _autoReseedKeyLength = params.key.length; - _delegate.seed(params); - } else { - throw ArgumentError( - 'Only types ParametersWithIV or KeyParameter allowed for seeding'); - } - } - - @override - int nextUint8() => _autoReseedIfNeededAfter(() { - return _delegate.nextUint8(); - }); - - @override - int nextUint16() => _autoReseedIfNeededAfter(() { - return _delegate.nextUint16(); - }); - - @override - int nextUint32() => _autoReseedIfNeededAfter(() { - return _delegate.nextUint32(); - }); - - @override - BigInt nextBigInteger(int bitLength) => _autoReseedIfNeededAfter(() { - return _delegate.nextBigInteger(bitLength); - }); - - @override - Uint8List nextBytes(int count) => _autoReseedIfNeededAfter(() { - return _delegate.nextBytes(count); - }); - - dynamic _autoReseedIfNeededAfter(dynamic closure) { - if (_inAutoReseed) { - return closure(); - } else { - _inAutoReseed = true; - var ret = closure(); - _doAutoReseed(); - _inAutoReseed = false; - return ret; - } - } - - void _doAutoReseed() { - var newKey = nextBytes(_autoReseedKeyLength); - var keyParam = KeyParameter(newKey); - - CipherParameters params; - if (_reseedIV) { - params = - ParametersWithIV(keyParam, nextBytes(_delegate.cipher.blockSize)); - } else { - params = keyParam; - } - - _delegate.seed(params); - } -} diff --git a/pointycastle/lib/random/block_ctr_random.dart b/pointycastle/lib/random/block_ctr_random.dart deleted file mode 100644 index d1585d9..0000000 --- a/pointycastle/lib/random/block_ctr_random.dart +++ /dev/null @@ -1,69 +0,0 @@ -// See file LICENSE for more information. - -library impl.secure_random.block_ctr_random; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; -import 'package:pointycastle/src/impl/secure_random_base.dart'; - -/// An implementation of [SecureRandom] that uses a [BlockCipher] with CTR mode to generate random -/// values. -class BlockCtrRandom extends SecureRandomBase implements SecureRandom { - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig.regex( - SecureRandom, - r'^(.*)/CTR/PRNG$', - (_, final Match match) => () { - var blockCipherName = match.group(1); - var blockCipher = BlockCipher(blockCipherName!); - return BlockCtrRandom(blockCipher); - }); - - final BlockCipher cipher; - - late Uint8List _input; - late Uint8List _output; - late int _used; - - BlockCtrRandom(this.cipher) { - _input = Uint8List(cipher.blockSize); - _output = Uint8List(cipher.blockSize); - _used = _output.length; - } - - @override - String get algorithmName => '${cipher.algorithmName}/CTR/PRNG'; - - @override - void seed(CipherParameters params) { - _used = _output.length; - if (params is ParametersWithIV) { - _input.setAll(0, params.iv); - cipher.init(true, params.parameters!); - } else { - cipher.init(true, params); - } - } - - @override - int nextUint8() { - if (_used == _output.length) { - cipher.processBlock(_input, 0, _output, 0); - _used = 0; - _incrementInput(); - } - - return clip8(_output[_used++]); - } - - void _incrementInput() { - var offset = _input.length; - do { - offset--; - _input[offset] += 1; - } while (_input[offset] == 0); - } -} diff --git a/pointycastle/lib/random/fortuna_random.dart b/pointycastle/lib/random/fortuna_random.dart deleted file mode 100644 index e698002..0000000 --- a/pointycastle/lib/random/fortuna_random.dart +++ /dev/null @@ -1,59 +0,0 @@ -// See file LICENSE for more information. - -library impl.secure_random.fortuna_random; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/block/aes.dart'; -import 'package:pointycastle/random/auto_seed_block_ctr_random.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// An implementation of [SecureRandom] as specified in the Fortuna algorithm. -class FortunaRandom implements SecureRandom { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(SecureRandom, 'Fortuna', () => FortunaRandom()); - - final AESEngine _aes; - late AutoSeedBlockCtrRandom _prng; - - @override - String get algorithmName => 'Fortuna'; - - FortunaRandom() : _aes = AESEngine() { - _prng = AutoSeedBlockCtrRandom(_aes, false); - } - - @override - void seed(covariant KeyParameter param) { - if (param.key.length != 32) { - throw ArgumentError('Fortuna PRNG can only be used with 256 bits keys'); - } - - final iv = Uint8List(16); - iv[15] = 1; - _prng.seed(ParametersWithIV(param, iv)); - } - - @override - int nextUint8() => _prng.nextUint8(); - - @override - int nextUint16() => _prng.nextUint16(); - - @override - int nextUint32() => _prng.nextUint32(); - - @override - BigInt nextBigInteger(int bitLength) => _prng.nextBigInteger(bitLength); - - @override - Uint8List nextBytes(int count) { - if (count > 1048576) { - throw ArgumentError( - 'Fortuna PRNG cannot generate more than 1MB of random data per invocation'); - } - - return _prng.nextBytes(count); - } -} diff --git a/pointycastle/lib/signers/ecdsa_signer.dart b/pointycastle/lib/signers/ecdsa_signer.dart deleted file mode 100644 index 3e4510f..0000000 --- a/pointycastle/lib/signers/ecdsa_signer.dart +++ /dev/null @@ -1,402 +0,0 @@ -// See file LICENSE for more information. - -library impl.signer.ecdsa_signer; - -import 'dart:math'; -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/ecc/api.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/utils.dart' as utils; - -bool _testBit(BigInt i, int n) { - return (i & (BigInt.one << n)) != BigInt.zero; -} - -class ECDSASigner implements Signer { - /// Intended for internal use. - // ignore: non_constant_identifier_names - static final FactoryConfig factoryConfig = DynamicFactoryConfig.regex( - Signer, r'^(.+)/(DET-)?ECDSA$', (_, final Match match) { - // ignore: omit_local_variable_types - final String? digestName = match.group(1); - // ignore: omit_local_variable_types - final bool withMac = match.group(2) != null; - return () { - var underlyingDigest = Digest(digestName!); - var mac = withMac ? Mac('$digestName/HMAC') : null; - return ECDSASigner(underlyingDigest, mac); - }; - }); - - ECPublicKey? _pbkey; - ECPrivateKey? _pvkey; - SecureRandom? _random; - final Digest? _digest; - final Mac? _kMac; - - /// If [_digest] is not null it is used to hash the message before signing and verifying, otherwise, the message needs to be - /// hashed by the user of this [ECDSASigner] object. - /// If [_kMac] is not null, RFC 6979 is used for k calculation with the given [Mac]. Keep in mind that, to comply with - /// RFC 69679, [_kMac] must be HMAC with the same digest used to hash the message. - ECDSASigner([this._digest, this._kMac]); - - @override - String get algorithmName => - '${_digest!.algorithmName}/${_kMac == null ? '' : 'DET-'}ECDSA'; - - @override - void reset() {} - - /// Init this [Signer]. The [params] argument can be: - /// -A [ParametersWithRandom] containing a [PrivateKeyParameter] or a raw [PrivateKeyParameter] for signing - /// -An [PublicKeyParameter] for verifying. - @override - void init(bool forSigning, CipherParameters params) { - _pbkey = _pvkey = null; - - if (forSigning) { - PrivateKeyParameter pvparams; - - if (params is ParametersWithRandom) { - _random = params.random; - pvparams = params.parameters as PrivateKeyParameter; - } else if (_kMac != null) { - _random = null; - pvparams = params as PrivateKeyParameter; - } else { - _random = SecureRandom(); - pvparams = params as PrivateKeyParameter; - } - - _pvkey = pvparams.key as ECPrivateKey; - } else { - PublicKeyParameter pbparams; - - pbparams = params as PublicKeyParameter; - - _pbkey = pbparams.key as ECPublicKey; - } - } - - @override - Signature generateSignature(Uint8List message) { - message = _hashMessageIfNeeded(message); - - var n = _pvkey!.parameters!.n; - var e = _calculateE(n, message); - BigInt r; - BigInt s; - - dynamic kCalculator; - if (_kMac != null) { - kCalculator = _RFC6979KCalculator(_kMac, n, _pvkey!.d!, message); - } else { - kCalculator = _RandomKCalculator(n, _random!); - } - - // 5.3.2 - do { - // generate s - BigInt? k; - - do { - // generate r - k = kCalculator.nextK() as BigInt?; - - var p = (_pvkey!.parameters!.G * k)!; - - // 5.3.3 - var x = p.x!.toBigInteger()!; - - r = x % n; - } while (r == BigInt.zero); - - var d = _pvkey!.d!; - - s = (k!.modInverse(n) * (e + (d * r))) % n; - } while (s == BigInt.zero); - - return ECSignature(r, s); - } - - @override - bool verifySignature(Uint8List message, covariant ECSignature signature) { - message = _hashMessageIfNeeded(message); - - var n = _pbkey!.parameters!.n; - var e = _calculateE(n, message); - - var r = signature.r; - var s = signature.s; - - // r in the range [1,n-1] - if (r.compareTo(BigInt.one) < 0 || r.compareTo(n) >= 0) { - return false; - } - - // s in the range [1,n-1] - if (s.compareTo(BigInt.one) < 0 || s.compareTo(n) >= 0) { - return false; - } - - var c = s.modInverse(n); - - var u1 = (e * c) % n; - var u2 = (r * c) % n; - - var G = _pbkey!.parameters!.G; - var Q = _pbkey!.Q!; - - var point = _sumOfTwoMultiplies(G, u1, Q, u2)!; - - // components must be bogus. - if (point.isInfinity) { - return false; - } - - var v = point.x!.toBigInteger()! % n; - - return v == r; - } - - Uint8List _hashMessageIfNeeded(Uint8List message) { - if (_digest != null) { - _digest.reset(); - return _digest.process(message); - } else { - return message; - } - } - - BigInt _calculateE(BigInt n, Uint8List message) { - var log2n = n.bitLength; - var messageBitLength = message.length * 8; - - if (log2n >= messageBitLength) { - return utils.decodeBigIntWithSign(1, message); - } else { - var trunc = utils.decodeBigIntWithSign(1, message); - - trunc = trunc >> (messageBitLength - log2n); - - return trunc; - } - } - - ECPoint? _sumOfTwoMultiplies(ECPoint P, BigInt a, ECPoint Q, BigInt b) { - var c = P.curve; - - if (c != Q.curve) { - throw ArgumentError('P and Q must be on same curve'); - } - - // Point multiplication for Koblitz curves (using WTNAF) beats Shamir's trick - // TODO: uncomment this when F2m available - /* - if( c is ECCurve.F2m ) { - ECCurve.F2m f2mCurve = (ECCurve.F2m)c; - if( f2mCurve.isKoblitz() ) { - return P.multiply(a).add(Q.multiply(b)); - } - } - */ - - return _implShamirsTrick(P, a, Q, b); - } - - ECPoint? _implShamirsTrick(ECPoint P, BigInt k, ECPoint Q, BigInt l) { - var m = max(k.bitLength, l.bitLength); - - var Z = P + Q; - var R = P.curve.infinity; - - for (var i = m - 1; i >= 0; --i) { - R = R!.twice(); - - if (_testBit(k, i)) { - if (_testBit(l, i)) { - R = R! + Z; - } else { - R = R! + P; - } - } else { - if (_testBit(l, i)) { - R = R! + Q; - } - } - } - - return R; - } -} - -class NormalizedECDSASigner implements Signer { - final ECDSASigner signer; - final bool enforceNormalized; - - /// Wraps ECDSASigner and enforces normalisation on verify if - /// [enforceNormalized] is true. - /// - /// Always generates normalized signatures. - NormalizedECDSASigner(this.signer, {this.enforceNormalized = false}); - - @override - String get algorithmName => signer.algorithmName; - - @override - Signature generateSignature(Uint8List message) { - return (signer.generateSignature(message) as ECSignature) - .normalize(signer._pvkey!.parameters!); - } - - @override - void init(bool forSigning, CipherParameters params) { - signer.init(forSigning, params); - } - - @override - void reset() { - signer.reset(); - } - - @override - bool verifySignature(Uint8List message, Signature signature) { - var isNormalized = - (signature as ECSignature).isNormalized(signer._pbkey!.parameters!); - var isVerified = signer.verifySignature(message, signature); - - // Constant time. - return (isNormalized | !enforceNormalized) & isVerified; - } -} - -class _RFC6979KCalculator { - final Mac _mac; - // ignore: non_constant_identifier_names - late Uint8List _K; - // ignore: non_constant_identifier_names - late Uint8List _V; - final BigInt _n; - - _RFC6979KCalculator(this._mac, this._n, BigInt d, Uint8List message) { - _V = Uint8List(_mac.macSize); - _K = Uint8List(_mac.macSize); - _init(d, message); - } - - void _init(BigInt d, Uint8List message) { - _V.fillRange(0, _V.length, 0x01); - _K.fillRange(0, _K.length, 0x00); - - var x = Uint8List((_n.bitLength + 7) ~/ 8); - var dVal = _asUnsignedByteArray(d); - - x.setRange(x.length - dVal.length, x.length, dVal); - - var m = Uint8List((_n.bitLength + 7) ~/ 8); - - var mInt = _bitsToInt(message); - - if (mInt > _n) { - mInt -= _n; - } - - var mVal = _asUnsignedByteArray(mInt); - - m.setRange(m.length - mVal.length, m.length, mVal); - - _mac.init(KeyParameter(_K)); - - _mac.update(_V, 0, _V.length); - _mac.updateByte(0x00); - _mac.update(x, 0, x.length); - _mac.update(m, 0, m.length); - _mac.doFinal(_K, 0); - - _mac.init(KeyParameter(_K)); - _mac.update(_V, 0, _V.length); - _mac.doFinal(_V, 0); - - _mac.update(_V, 0, _V.length); - _mac.updateByte(0x01); - _mac.update(x, 0, x.length); - _mac.update(m, 0, m.length); - _mac.doFinal(_K, 0); - - _mac.init(KeyParameter(_K)); - _mac.update(_V, 0, _V.length); - _mac.doFinal(_V, 0); - } - - BigInt nextK() { - var t = Uint8List((_n.bitLength + 7) ~/ 8); - - for (;;) { - var tOff = 0; - - while (tOff < t.length) { - _mac.update(_V, 0, _V.length); - _mac.doFinal(_V, 0); - - if ((t.length - tOff) < _V.length) { - t.setRange(tOff, t.length, _V); - tOff += t.length - tOff; - } else { - t.setRange(tOff, tOff + _V.length, _V); - tOff += _V.length; - } - } - - var k = _bitsToInt(t); - - // ignore: unrelated_type_equality_checks - if ((k == 0) || (k >= _n)) { - _mac.update(_V, 0, _V.length); - _mac.updateByte(0x00); - _mac.doFinal(_K, 0); - - _mac.init(KeyParameter(_K)); - _mac.update(_V, 0, _V.length); - _mac.doFinal(_V, 0); - } else { - return k; - } - } - } - - BigInt _bitsToInt(Uint8List t) { - var v = utils.decodeBigIntWithSign(1, t); - if ((t.length * 8) > _n.bitLength) { - v = v >> ((t.length * 8) - _n.bitLength); - } - - return v; - } - - Uint8List _asUnsignedByteArray(BigInt value) { - var bytes = utils.encodeBigInt(value); - - if (bytes[0] == 0) { - return Uint8List.fromList(bytes.sublist(1)); - } else { - return Uint8List.fromList(bytes); - } - } -} - -class _RandomKCalculator { - final BigInt _n; - final SecureRandom _random; - - _RandomKCalculator(this._n, this._random); - - BigInt nextK() { - BigInt k; - do { - k = _random.nextBigInteger(_n.bitLength); - } while (k == BigInt.zero || k >= _n); - return k; - } -} diff --git a/pointycastle/lib/signers/pss_signer.dart b/pointycastle/lib/signers/pss_signer.dart deleted file mode 100644 index 5f1cf62..0000000 --- a/pointycastle/lib/signers/pss_signer.dart +++ /dev/null @@ -1,269 +0,0 @@ -// See file LICENSE for more information. - -library impl.signer.pss_signer; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/asymmetric/api.dart'; -import 'package:pointycastle/asymmetric/rsa.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -import '../src/utils.dart'; - -class PSSSigner implements Signer { - /// Intended for internal use. - static final FactoryConfig factoryConfig = - DynamicFactoryConfig.suffix(Signer, '/PSS', (_, Match match) { - final digestName = match.group(1); - return () => PSSSigner( - RSAEngine(), - Digest(digestName!), - Digest(digestName), - ); - }); - - static const int TRAILER_IMPLICIT = 0xBC; - - final Digest _contentDigest; - final Digest _mgfDigest; - final AsymmetricBlockCipher _cipher; - final int _hLen; - final int _mgfhLen; - final int _trailer; - - late bool _sSet; - late int _sLen; - late Uint8List _salt; - late SecureRandom _random; - - late int _emBits; - late Uint8List _block; - late Uint8List _mDash; - - late bool _forSigning; - - PSSSigner(this._cipher, this._contentDigest, this._mgfDigest, - {int trailer = TRAILER_IMPLICIT}) - : _hLen = _contentDigest.digestSize, - _mgfhLen = _mgfDigest.digestSize, - _trailer = trailer; - - @override - String get algorithmName => '${_mgfDigest.algorithmName}/PSS'; - - @override - void init(bool forSigning, CipherParameters params) { - _forSigning = forSigning; - - AsymmetricKeyParameter akparams; - if (params is ParametersWithSaltConfiguration) { - akparams = params.parameters as AsymmetricKeyParameter; - _random = params.random; - _sSet = false; - _sLen = params.saltLength; - _salt = Uint8List(_sLen); - } else if (params is ParametersWithSalt) { - akparams = params.parameters as AsymmetricKeyParameter; - _sSet = true; - _salt = params.salt; - _sLen = _salt.length; - } else { - throw ArgumentError( - 'Unsupported parameters type ${params.runtimeType}: should be ParametersWithSaltConfiguration or ParametersWithSalt'); - } - - var k = akparams.key as RSAAsymmetricKey; - - if (forSigning && (k is! RSAPrivateKey)) { - throw ArgumentError('Signing requires private key'); - } - - if (!forSigning && (k is! RSAPublicKey)) { - throw ArgumentError('Verification requires public key'); - } - - _emBits = k.modulus!.bitLength - 1; - - if (_emBits < (8 * _hLen + 8 * _sLen + 9)) { - throw ArgumentError('Key too small for specified hash and salt lengths'); - } - - _mDash = Uint8List(8 + _sLen + _contentDigest.digestSize); - - _cipher.init(forSigning, akparams); - - _block = Uint8List((_emBits + 7) ~/ 8); - - reset(); - } - - /// Clear possibly sensitive data. - void _clearBlock(Uint8List block) { - for (var i = 0; i != block.length; i++) { - block[i] = 0; - } - } - - @override - void reset() { - _contentDigest.reset(); - } - - @override - PSSSignature generateSignature(Uint8List message) { - if (!_forSigning) { - throw StateError('Signer was not initialised for signature generation'); - } - - _contentDigest.reset(); - _contentDigest.update(message, 0, message.length); - _contentDigest.doFinal(_mDash, _mDash.length - _hLen - _sLen); - - if (_sLen != 0) { - if (!_sSet) { - _salt = _random.nextBytes(_sLen); - } - - arrayCopy(_salt, 0, _mDash, _mDash.length - _sLen, _sLen); - } - - var h = Uint8List(_hLen); - - _contentDigest.update(_mDash, 0, _mDash.length); - - _contentDigest.doFinal(h, 0); - - _block[_block.length - _sLen - 1 - _hLen - 1] = 0x01; - arrayCopy(_salt, 0, _block, _block.length - _sLen - _hLen - 1, _sLen); - - var dbMask = - _maskGeneratorFunction1(h, 0, h.length, _block.length - _hLen - 1); - for (var i = 0; i != dbMask.length; i++) { - _block[i] ^= dbMask[i]; - } - - arrayCopy(h, 0, _block, _block.length - _hLen - 1, _hLen); - - var firstByteMask = 0xff >> ((_block.length * 8) - _emBits); - - _block[0] &= firstByteMask; - _block[_block.length - 1] = _trailer; - - var b = _cipher.process(_block); - - _clearBlock(_block); - - return PSSSignature(b); - } - - @override - bool verifySignature(Uint8List message, covariant PSSSignature signature) { - if (_forSigning) { - throw StateError('Signer was not initialised for signature verification'); - } - - _contentDigest.reset(); - _contentDigest.update(message, 0, message.length); - _contentDigest.doFinal(_mDash, _mDash.length - _hLen - _sLen); - - var b = _cipher.process(signature.bytes); - _block.fillRange(0, _block.length - b.length, 0); - arrayCopy(b, 0, _block, _block.length - b.length, b.length); - - var firstByteMask = 0xFF >> ((_block.length * 8) - _emBits); - - if (_block[0] != (_block[0] & firstByteMask) || - _block[_block.length - 1] != _trailer) { - _clearBlock(_block); - return false; - } - - var dbMask = _maskGeneratorFunction1( - _block, _block.length - _hLen - 1, _hLen, _block.length - _hLen - 1); - - for (var i = 0; i != dbMask.length; i++) { - _block[i] ^= dbMask[i]; - } - - _block[0] &= firstByteMask; - - for (var i = 0; i != _block.length - _hLen - _sLen - 2; i++) { - if (_block[i] != 0) { - _clearBlock(_block); - return false; - } - } - - if (_block[_block.length - _hLen - _sLen - 2] != 0x01) { - _clearBlock(_block); - return false; - } - - if (_sSet) { - arrayCopy(_salt, 0, _mDash, _mDash.length - _sLen, _sLen); - } else { - arrayCopy(_block, _block.length - _sLen - _hLen - 1, _mDash, - _mDash.length - _sLen, _sLen); - } - - _contentDigest.update(_mDash, 0, _mDash.length); - _contentDigest.doFinal(_mDash, _mDash.length - _hLen); - - for (var i = _block.length - _hLen - 1, j = _mDash.length - _hLen; - j != _mDash.length; - i++, j++) { - if ((_block[i] ^ _mDash[j]) != 0) { - _clearBlock(_mDash); - _clearBlock(_block); - return false; - } - } - - _clearBlock(_mDash); - _clearBlock(_block); - return true; - } - - /// Convert int to octet string. - void _intToOSP(int i, Uint8List sp) { - sp[0] = i >> 24; - sp[1] = i >> 16; - sp[2] = i >> 8; - sp[3] = i >> 0; - } - - Uint8List _maskGeneratorFunction1( - Uint8List Z, int zOff, int zLen, int length) { - var mask = Uint8List(length); - var hashBuf = Uint8List(_mgfhLen); - var C = Uint8List(4); - var counter = 0; - - _mgfDigest.reset(); - - while (counter < (length ~/ _mgfhLen)) { - _intToOSP(counter, C); - - _mgfDigest.update(Z, zOff, zLen); - _mgfDigest.update(C, 0, C.length); - _mgfDigest.doFinal(hashBuf, 0); - - arrayCopy(hashBuf, 0, mask, counter * _mgfhLen, _mgfhLen); - counter++; - } - - if ((counter * _mgfhLen) < length) { - _intToOSP(counter, C); - - _mgfDigest.update(Z, zOff, zLen); - _mgfDigest.update(C, 0, C.length); - _mgfDigest.doFinal(hashBuf, 0); - - arrayCopy(hashBuf, 0, mask, counter * _mgfhLen, - mask.length - (counter * _mgfhLen)); - } - - return mask; - } -} diff --git a/pointycastle/lib/signers/rsa_signer.dart b/pointycastle/lib/signers/rsa_signer.dart deleted file mode 100644 index 49f73f8..0000000 --- a/pointycastle/lib/signers/rsa_signer.dart +++ /dev/null @@ -1,197 +0,0 @@ -// See file LICENSE for more information. - -library impl.signer.rsa_signer; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/asymmetric/api.dart'; -import 'package:pointycastle/asymmetric/pkcs1.dart'; -import 'package:pointycastle/asymmetric/rsa.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -// TODO: implement full ASN1 encoding (for now I will do a little ad-hoc implementation of just what is needed here) -class RSASigner implements Signer { - /// Intended for internal use. - static final FactoryConfig factoryConfig = - DynamicFactoryConfig.suffix(Signer, '/RSA', (_, Match match) { - final digestName = match.group(1); - final digestIdentifierHex = _digestIdentifierHexes[digestName!]; - if (digestIdentifierHex == null) { - throw RegistryFactoryException( - 'RSA signing with digest $digestName is not supported'); - } - return () => RSASigner(Digest(digestName), digestIdentifierHex); - }); - - static final Map _digestIdentifierHexes = { - 'MD2': '06082a864886f70d0202', - 'MD4': '06082a864886f70d0204', - 'MD5': '06082a864886f70d0205', - 'RIPEMD-128': '06052b24030202', - 'RIPEMD-160': '06052b24030201', - 'RIPEMD-256': '06052b24030203', - 'SHA-1': '06052b0e03021a', - 'SHA-224': '0609608648016503040204', - 'SHA-256': '0609608648016503040201', - 'SHA-384': '0609608648016503040202', - 'SHA-512': '0609608648016503040203' - }; - - final AsymmetricBlockCipher _rsa = PKCS1Encoding(RSAEngine()); - final Digest _digest; - late Uint8List - _digestIdentifier; // DER encoded with trailing tag (06)+length byte - late bool _forSigning; - - RSASigner(this._digest, String digestIdentifierHex) { - _digestIdentifier = _hexStringToBytes(digestIdentifierHex); - } - - @override - String get algorithmName => '${_digest.algorithmName}/RSA'; - - @override - void reset() { - _digest.reset(); - _rsa.reset(); - } - - @override - void init(bool forSigning, CipherParameters params) { - _forSigning = forSigning; - - AsymmetricKeyParameter akparams; - if (params is ParametersWithRandom) { - akparams = params.parameters as AsymmetricKeyParameter; - } else { - akparams = params as AsymmetricKeyParameter; - } - var k = akparams.key as RSAAsymmetricKey; - - if (forSigning && (k is! RSAPrivateKey)) { - throw ArgumentError('Signing requires private key'); - } - - if (!forSigning && (k is! RSAPublicKey)) { - throw ArgumentError('Verification requires public key'); - } - - reset(); - - _rsa.init(forSigning, params); - } - - @override - RSASignature generateSignature(Uint8List message, {bool normalize = false}) { - if (!_forSigning) { - throw StateError('Signer was not initialised for signature generation'); - } - - var hash = Uint8List(_digest.digestSize); - _digest.reset(); - _digest.update(message, 0, message.length); - _digest.doFinal(hash, 0); - - var data = _derEncode(hash); - var out = Uint8List(_rsa.outputBlockSize); - var len = _rsa.processBlock(data, 0, data.length, out, 0); - return RSASignature(out.sublist(0, len)); - } - - @override - bool verifySignature(Uint8List message, covariant RSASignature signature) { - if (_forSigning) { - throw StateError('Signer was not initialised for signature verification'); - } - - var hash = Uint8List(_digest.digestSize); - _digest.reset(); - _digest.update(message, 0, message.length); - _digest.doFinal(hash, 0); - var sig = Uint8List(_rsa.outputBlockSize); - - try { - final len = - _rsa.processBlock(signature.bytes, 0, signature.bytes.length, sig, 0); - sig = sig.sublist(0, len); - } on ArgumentError { - // Signature was tampered with so the RSA 'decrypted' block is totally - // different to the original, causing [PKCS1Encoding._decodeBlock] to - // throw an exception because it does not recognise it. - return false; - } - - var expected = _derEncode(hash); - - if (sig.length == expected.length) { - for (var i = 0; i < sig.length; i++) { - if (sig[i] != expected[i]) { - return false; - } - } - return true; //return Arrays.constantTimeAreEqual(sig, expected); - } else if (sig.length == expected.length - 2) { - // NULL left out - var sigOffset = sig.length - hash.length - 2; - var expectedOffset = expected.length - hash.length - 2; - - expected[1] -= 2; // adjust lengths - expected[3] -= 2; - - var nonEqual = 0; - - for (var i = 0; i < hash.length; i++) { - nonEqual |= sig[sigOffset + i] ^ expected[expectedOffset + i]; - } - - for (var i = 0; i < sigOffset; i++) { - nonEqual |= sig[i] ^ expected[i]; // check header less NULL - } - - return nonEqual == 0; - } else { - return false; - } - } - - Uint8List _derEncode(Uint8List hash) { - var out = Uint8List(2 + 2 + _digestIdentifier.length + 2 + 2 + hash.length); - var i = 0; - - // header - out[i++] = 48; - out[i++] = out.length - 2; - - // algorithmIdentifier.header - out[i++] = 48; - out[i++] = _digestIdentifier.length + 2; - - // algorithmIdentifier.bytes - out.setAll(i, _digestIdentifier); - i += _digestIdentifier.length; - - // algorithmIdentifier.null - out[i++] = 5; - out[i++] = 0; - - // hash.header - out[i++] = 4; - out[i++] = hash.length; - - // hash.bytes - out.setAll(i, hash); - - return out; - } - - Uint8List _hexStringToBytes(String hex) { - var result = Uint8List(hex.length ~/ 2); - for (var i = 0; i < hex.length; i += 2) { - var num = hex.substring(i, i + 2); - var byte = int.parse(num, radix: 16); - result[i ~/ 2] = byte; - } - return result; - } -} diff --git a/pointycastle/lib/src/api/aead_block_cipher.dart b/pointycastle/lib/src/api/aead_block_cipher.dart deleted file mode 100644 index d64b209..0000000 --- a/pointycastle/lib/src/api/aead_block_cipher.dart +++ /dev/null @@ -1,26 +0,0 @@ -part of '../../api.dart'; - -/// A block cipher mode that includes authenticated encryption -abstract class AEADBlockCipher extends BlockCipher { - factory AEADBlockCipher(String algorithmName) => - registry.create(algorithmName); - - /// Process [len] bytes from [inp] starting at offset [inpOff] and output the - /// result to [out] at offset [outOff]. - /// - /// Returns the number of bytes written to the output. - int processBytes( - Uint8List inp, int inpOff, int len, Uint8List out, int outOff); - - /// Finish the operation either appending or verifying the MAC at the end of - /// the data. - /// - /// Returns the number of bytes written to the output. - int doFinal(Uint8List out, int outOff); -} - -class InvalidCipherTextException implements Exception { - final String message; - - InvalidCipherTextException(this.message); -} diff --git a/pointycastle/lib/src/api/aead_cipher.dart b/pointycastle/lib/src/api/aead_cipher.dart deleted file mode 100644 index 4e02413..0000000 --- a/pointycastle/lib/src/api/aead_cipher.dart +++ /dev/null @@ -1,30 +0,0 @@ -part of '../../api.dart'; - -abstract class AEADCipher extends Algorithm { - void init(bool forEncryption, CipherParameters params); - - factory AEADCipher(String algorithmName) => - registry.create(algorithmName); - - @override - String get algorithmName; - - void processAADByte(int inp); - - void processAADBytes(Uint8List inp, int inpOff, int len); - - int processByte(int inp, Uint8List out, int outOff); - - int processBytes( - Uint8List inp, int inOff, int len, Uint8List out, int outOff); - - int doFinal(Uint8List out, int outOff); - - Uint8List get mac; - - int getUpdateOutputSize(int len); - - int getOutputSize(int len); - - void reset(); -} diff --git a/pointycastle/lib/src/api/aead_parameters.dart b/pointycastle/lib/src/api/aead_parameters.dart deleted file mode 100644 index 270bb16..0000000 --- a/pointycastle/lib/src/api/aead_parameters.dart +++ /dev/null @@ -1,17 +0,0 @@ -part of '../../api.dart'; - -// ignore_for_file: omit_local_variable_types, prefer_single_quotes, non_constant_identifier_names, directives_ordering, prefer_typing_uninitialized_variables - -class AEADParameters - implements CipherParameters { - final UnderlyingCipherParameters parameters; - - final Uint8List associatedData; - - final Uint8List nonce; - - final int macSize; - - AEADParameters( - this.parameters, this.macSize, this.nonce, this.associatedData); -} diff --git a/pointycastle/lib/src/api/algorithm.dart b/pointycastle/lib/src/api/algorithm.dart deleted file mode 100644 index 19ddab8..0000000 --- a/pointycastle/lib/src/api/algorithm.dart +++ /dev/null @@ -1,9 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// All algorithms defined by Pointy Castle inherit from this class. -abstract class Algorithm { - /// Get this algorithm's standard name. - String get algorithmName; -} diff --git a/pointycastle/lib/src/api/asymmetric_block_cipher.dart b/pointycastle/lib/src/api/asymmetric_block_cipher.dart deleted file mode 100644 index cdae436..0000000 --- a/pointycastle/lib/src/api/asymmetric_block_cipher.dart +++ /dev/null @@ -1,35 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// Asymmetric block cipher engines are expected to conform to this interface. -abstract class AsymmetricBlockCipher extends Algorithm { - /// Create the cipher specified by the standard [algorithmName]. - factory AsymmetricBlockCipher(String algorithmName) => - registry.create(algorithmName); - - /// Get this ciphers's maximum input block size. - int get inputBlockSize; - - /// Get this ciphers's maximum output block size. - int get outputBlockSize; - - /// Reset the cipher to its original state. - void reset(); - - /// Init the cipher with its initialization [params]. The type of [CipherParameters] depends on the algorithm being used (see - /// the documentation of each implementation to find out more). - /// - /// Use the argument [forEncryption] to tell the cipher if you want to encrypt or decrypt data. - void init(bool forEncryption, CipherParameters params); - - /// Process a whole block of [data] at once, returning the result in a byte array. - Uint8List process(Uint8List data); - - /// Process a block of [len] bytes given by [inp] and starting at offset [inpOff] and put the resulting cipher text in [out] - /// beginning at position [outOff]. - /// - /// This method returns the total bytes put in the output buffer. - int processBlock( - Uint8List inp, int inpOff, int len, Uint8List out, int outOff); -} diff --git a/pointycastle/lib/src/api/asymmetric_key.dart b/pointycastle/lib/src/api/asymmetric_key.dart deleted file mode 100644 index c3ff9bc..0000000 --- a/pointycastle/lib/src/api/asymmetric_key.dart +++ /dev/null @@ -1,6 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// The interface that asymmetric (public and private) keys conform to. -abstract class AsymmetricKey {} diff --git a/pointycastle/lib/src/api/asymmetric_key_pair.dart b/pointycastle/lib/src/api/asymmetric_key_pair.dart deleted file mode 100644 index fa0ae74..0000000 --- a/pointycastle/lib/src/api/asymmetric_key_pair.dart +++ /dev/null @@ -1,22 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// A pair of public and private asymmetric keys. -class AsymmetricKeyPair { - final B publicKey; - final V privateKey; - - AsymmetricKeyPair(this.publicKey, this.privateKey); - - @override - bool operator ==(Object other) => - identical(this, other) || - other is AsymmetricKeyPair && - runtimeType == other.runtimeType && - publicKey == other.publicKey && - privateKey == other.privateKey; - - @override - int get hashCode => publicKey.hashCode ^ privateKey.hashCode; -} diff --git a/pointycastle/lib/src/api/asymmetric_key_parameter.dart b/pointycastle/lib/src/api/asymmetric_key_parameter.dart deleted file mode 100644 index 9fa58d8..0000000 --- a/pointycastle/lib/src/api/asymmetric_key_parameter.dart +++ /dev/null @@ -1,11 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// Abstract [CipherParameters] to hold an asymmetric (public or private) key -abstract class AsymmetricKeyParameter - implements CipherParameters { - final T key; - - AsymmetricKeyParameter(this.key); -} diff --git a/pointycastle/lib/src/api/block_cipher.dart b/pointycastle/lib/src/api/block_cipher.dart deleted file mode 100644 index d08c22b..0000000 --- a/pointycastle/lib/src/api/block_cipher.dart +++ /dev/null @@ -1,39 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// Block cipher engines are expected to conform to this interface. -abstract class BlockCipher extends Algorithm { - /// Create the cipher specified by the standard [algorithmName]. - factory BlockCipher(String algorithmName) => - registry.create(algorithmName); - - /// Get this ciphers's block size. - int get blockSize; - - /// Reset the cipher to its original state. - void reset(); - - /// Init the cipher with its initialization [params]. The type of - /// [CipherParameters] depends on the algorithm being used (see the - /// documentation of each implementation to find out more). - /// - /// Use the argument [forEncryption] to tell the cipher if you want to encrypt - /// or decrypt data. - void init(bool forEncryption, CipherParameters? params); - - /// Process a whole block of [blockSize] bytes stored in [data] at once, returning the result in a - /// byte array. - /// - /// This call is equivalent to [processBlock] but it allocates the array under the hood. - Uint8List process(Uint8List data); - - /// Process a whole block of data given by [inp] and starting at offset - /// [inpOff]. - /// - /// The resulting cipher text is put in [out] beginning at position [outOff]. - /// - /// This method returns the total bytes processed (which is the same as the - /// block size of the algorithm). - int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff); -} diff --git a/pointycastle/lib/src/api/cipher_parameters.dart b/pointycastle/lib/src/api/cipher_parameters.dart deleted file mode 100644 index 84081b2..0000000 --- a/pointycastle/lib/src/api/cipher_parameters.dart +++ /dev/null @@ -1,6 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// All cipher initialization parameters classes implement this. -abstract class CipherParameters {} diff --git a/pointycastle/lib/src/api/des_parameters.dart b/pointycastle/lib/src/api/des_parameters.dart deleted file mode 100644 index 32484f3..0000000 --- a/pointycastle/lib/src/api/des_parameters.dart +++ /dev/null @@ -1,7 +0,0 @@ -part of '../../api.dart'; - -class DESParameters extends KeyParameter { - final int DES_KEY_LENGTH = 8; - - DESParameters(super.key); -} diff --git a/pointycastle/lib/src/api/desede_parameters.dart b/pointycastle/lib/src/api/desede_parameters.dart deleted file mode 100644 index 086d017..0000000 --- a/pointycastle/lib/src/api/desede_parameters.dart +++ /dev/null @@ -1,7 +0,0 @@ -part of '../../api.dart'; - -class DESedeParameters extends DESParameters { - final int DES_EDE_KEY_LENGTH = 24; - - DESedeParameters(super.key); -} diff --git a/pointycastle/lib/src/api/digest.dart b/pointycastle/lib/src/api/digest.dart deleted file mode 100644 index 87e5212..0000000 --- a/pointycastle/lib/src/api/digest.dart +++ /dev/null @@ -1,34 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// The interface that a message digest conforms to. -abstract class Digest extends Algorithm { - /// Create the digest specified by the standard [algorithmName]. - factory Digest(String algorithmName) => - registry.create(algorithmName); - - /// Get this digest's output size in bytes - int get digestSize; - - /// Return the size in bytes of the internal buffer the digest applies - /// it's compression function to. - int get byteLength; - - /// Reset the digest to its original state. - void reset(); - - /// Process a whole block of [data] at once, returning the result in a new byte array. - Uint8List process(Uint8List data); - - /// Add one byte of data to the digested input. - void updateByte(int inp); - - /// Add [len] bytes of data contained in [inp], starting at position [inpOff] - /// ti the digested input. - void update(Uint8List inp, int inpOff, int len); - - /// Store the digest of previously given data in buffer [out] starting at - /// offset [outOff]. This method returns the size of the digest. - int doFinal(Uint8List out, int outOff); -} diff --git a/pointycastle/lib/src/api/key_derivator.dart b/pointycastle/lib/src/api/key_derivator.dart deleted file mode 100644 index 269bc51..0000000 --- a/pointycastle/lib/src/api/key_derivator.dart +++ /dev/null @@ -1,25 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// The interface that a symmetric key derivator conforms to. -/// -/// A [KeyDerivator] is normally used to convert some master data (like a password, for instance) to a symmetric key. -abstract class KeyDerivator extends Algorithm { - /// Create the key derivator specified by the standard [algorithmName]. - factory KeyDerivator(String algorithmName) => - registry.create(algorithmName); - - /// Get this derivator key's output size. - int get keySize; - - /// Init the derivator with its initialization [params]. The type of [CipherParameters] depends on the algorithm being used - /// (see the documentation of each implementation to find out more). - void init(CipherParameters params); - - /// Process a whole block of [data] at once, returning the result in a byte array. - Uint8List process(Uint8List data); - - /// Derive key from given input and put it in [out] at offset [outOff]. - int deriveKey(Uint8List inp, int inpOff, Uint8List out, int outOff); -} diff --git a/pointycastle/lib/src/api/key_generator.dart b/pointycastle/lib/src/api/key_generator.dart deleted file mode 100644 index 727aec0..0000000 --- a/pointycastle/lib/src/api/key_generator.dart +++ /dev/null @@ -1,19 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// The interface that asymmetric key generators conform to. -/// -/// A [KeyGenerator] is used to create a pair of public and private keys. -abstract class KeyGenerator extends Algorithm { - /// Create the key generator specified by the standard [algorithmName]. - factory KeyGenerator(String algorithmName) => - registry.create(algorithmName); - - /// Init the generator with its initialization [params]. The type of [CipherParameters] depends on the algorithm being used - /// (see the documentation of each implementation to find out more). - void init(CipherParameters params); - - /// Generate a key pair. - AsymmetricKeyPair generateKeyPair(); -} diff --git a/pointycastle/lib/src/api/key_generator_parameters.dart b/pointycastle/lib/src/api/key_generator_parameters.dart deleted file mode 100644 index cb4be12..0000000 --- a/pointycastle/lib/src/api/key_generator_parameters.dart +++ /dev/null @@ -1,10 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// Abstract [CipherParameters] to init an asymmetric key generator. -abstract class KeyGeneratorParameters implements CipherParameters { - final int bitStrength; - - KeyGeneratorParameters(this.bitStrength); -} diff --git a/pointycastle/lib/src/api/key_parameter.dart b/pointycastle/lib/src/api/key_parameter.dart deleted file mode 100644 index 20835ac..0000000 --- a/pointycastle/lib/src/api/key_parameter.dart +++ /dev/null @@ -1,15 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// [CipherParameters] consisting of just a key of arbitrary length. -class KeyParameter extends CipherParameters { - late Uint8List key; - - KeyParameter(this.key); - - KeyParameter.offset(Uint8List key, int keyOff, int keyLen) { - this.key = Uint8List(keyLen); - arrayCopy(key, keyOff, this.key, 0, keyLen); - } -} diff --git a/pointycastle/lib/src/api/mac.dart b/pointycastle/lib/src/api/mac.dart deleted file mode 100644 index 3d17086..0000000 --- a/pointycastle/lib/src/api/mac.dart +++ /dev/null @@ -1,35 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// The interface that a MAC (message authentication code) conforms to. -abstract class Mac extends Algorithm { - /// Create the MAC specified by the standard [algorithmName]. - factory Mac(String algorithmName) => registry.create(algorithmName); - - /// Get this MAC's output size. - int get macSize; - - /// Reset the MAC to its original state. - void reset(); - - /// Init the MAC with its initialization [params]. The type of - /// [CipherParameters] depends on the algorithm being used (see - /// the documentation of each implementation to find out more). - void init(CipherParameters params); - - /// Process a whole block of [data] at once, returning the result in a new - /// byte array. - Uint8List process(Uint8List data); - - /// Add one byte of data to the MAC input. - void updateByte(int inp); - - /// Add [len] bytes of data contained in [inp], starting at position [inpOff] - /// to the MAC'ed input. - void update(Uint8List inp, int inpOff, int len); - - /// Store the MAC of previously given data in buffer [out] starting at - /// offset [outOff]. This method returns the size of the digest. - int doFinal(Uint8List out, int outOff); -} diff --git a/pointycastle/lib/src/api/padded_block_cipher.dart b/pointycastle/lib/src/api/padded_block_cipher.dart deleted file mode 100644 index a33958d..0000000 --- a/pointycastle/lib/src/api/padded_block_cipher.dart +++ /dev/null @@ -1,48 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// All padded block ciphers conform to this interface. -/// -/// A padded block cipher is a wrapper around a [BlockCipher] that allows padding the last procesed -/// block (when encrypting) in the following way: -/// -/// *If it is smaller than the [blockSize] it will be padded to [blockSize] bytes. -/// *If it is equal to the [blockSize] a pad block will be added. -/// -/// When decrypting, a [PaddedBlockCipher] also removes the padding from the last cipher text block. -/// -/// It is advised to use method [process] as it is much easier than making the correct calls to -/// [processBlock] and [doFinal] which are different depending on whether you are encrypting or -/// decrypting and also depending on the data length being a multiple of the cipher's block size. -abstract class PaddedBlockCipher implements BlockCipher { - /// Create the padded block cipher specified by the standard [algorithmName]. - factory PaddedBlockCipher(String algorithmName) => - registry.create(algorithmName); - - /// Get the underlying [Padding] used by this cipher. - Padding get padding; - - /// Get the underlying [BlockCipher] used by this cipher. - BlockCipher get cipher; - - /// Process a whole block of [data] at once, returning the result in a byte array. - /// - /// This call does as many calls to [processBlock] as needed to process all the given data and a - /// final one to [doFinal] so that the padding can do its job. - @override - Uint8List process(Uint8List data); - - /// Process the last block of data given by [inp] and starting at offset [inpOff] and pad it as - /// explained in this interface's description. - /// - /// For encryption, the resulting cipher text is put in [out] beginning at position [outOff] and - /// the method returns the total bytes put in [out], including the padding. Note that, if [inp] - /// length is equal to the cipher's block size, [out] will need to be twice the cipher's block size - /// to allow place for the padding. - /// - /// For decryption, the resulting plain text is put in [out] beginning at position [outOff] and the - /// method returns the total bytes put in [out], excluding the padding. Note that the method may - /// return 0 if the last block was all padding. - int doFinal(Uint8List inp, int inpOff, Uint8List out, int outOff); -} diff --git a/pointycastle/lib/src/api/padded_block_cipher_parameters.dart b/pointycastle/lib/src/api/padded_block_cipher_parameters.dart deleted file mode 100644 index a5cdf9f..0000000 --- a/pointycastle/lib/src/api/padded_block_cipher_parameters.dart +++ /dev/null @@ -1,16 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// [CipherParameters] for [PaddedBlockCipher]s consisting of two underlying [CipherParameters], one for the [BlockCipher] (of -/// type [UnderlyingCipherParameters]) and the other for the [Padding] (of type [PaddingCipherParameters]). -class PaddedBlockCipherParameters< - UnderlyingCipherParameters extends CipherParameters?, - PaddingCipherParameters extends CipherParameters?> - implements CipherParameters { - final UnderlyingCipherParameters? underlyingCipherParameters; - final PaddingCipherParameters? paddingCipherParameters; - - PaddedBlockCipherParameters( - this.underlyingCipherParameters, this.paddingCipherParameters); -} diff --git a/pointycastle/lib/src/api/padding.dart b/pointycastle/lib/src/api/padding.dart deleted file mode 100644 index d0a7713..0000000 --- a/pointycastle/lib/src/api/padding.dart +++ /dev/null @@ -1,32 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// The interface that a padding conforms to. -abstract class Padding extends Algorithm { - /// Create the digest specified by the standard [algorithmName]. - factory Padding(String algorithmName) => - registry.create(algorithmName); - - /// Initialise the padder. Normally, paddings don't need any init params. - void init([CipherParameters? params]); - - /// Process a whole block of [data] at once, returning the result in a byte array. If [pad] is - /// true adds padding to the given block, otherwise, padding is removed. - /// - /// Note: this assumes that the last block of plain text is always passed to it inside [data]. The - /// reason for this is that some modes such as 'trailing bit compliment' base the padding on the - /// last byte of plain text. - Uint8List process(bool pad, Uint8List data); - - /// Add the pad bytes to the passed in block, returning the number of bytes added. - /// - /// Note: this assumes that the last block of plain text is always passed to it inside [data]. i.e. - /// if [offset] is zero, indicating the entire block is to be overwritten with padding the value of - /// [data] should be the same as the last block of plain text. The reason for this is that some - /// modes such as 'trailing bit compliment' base the padding on the last byte of plain text. - int addPadding(Uint8List data, int offset); - - /// Get the number of pad bytes present in the block. - int padCount(Uint8List data); -} diff --git a/pointycastle/lib/src/api/parameters_with_iv.dart b/pointycastle/lib/src/api/parameters_with_iv.dart deleted file mode 100644 index 3779edd..0000000 --- a/pointycastle/lib/src/api/parameters_with_iv.dart +++ /dev/null @@ -1,13 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// [CipherParameters] consisting of an underlying [CipherParameters] (of type [UnderlyingParameters]) and an initialization -/// vector of arbitrary length. -class ParametersWithIV - implements CipherParameters { - final Uint8List iv; - final UnderlyingParameters? parameters; - - ParametersWithIV(this.parameters, this.iv); -} diff --git a/pointycastle/lib/src/api/parameters_with_random.dart b/pointycastle/lib/src/api/parameters_with_random.dart deleted file mode 100644 index 79608e8..0000000 --- a/pointycastle/lib/src/api/parameters_with_random.dart +++ /dev/null @@ -1,14 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -//TODO consider mixin -/// [CipherParameters] consisting of an underlying [CipherParameters] (of type -/// [UnderlyingParameters]) and an acompanying [SecureRandom]. -class ParametersWithRandom - implements CipherParameters { - final UnderlyingParameters parameters; - final SecureRandom random; - - ParametersWithRandom(this.parameters, this.random); -} diff --git a/pointycastle/lib/src/api/parameters_with_salt.dart b/pointycastle/lib/src/api/parameters_with_salt.dart deleted file mode 100644 index 994e3b1..0000000 --- a/pointycastle/lib/src/api/parameters_with_salt.dart +++ /dev/null @@ -1,13 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// [CipherParameters] consisting of an underlying [CipherParameters] (of type -/// [UnderlyingParameters]) and an acompanying salt of type [Uint8List]. -class ParametersWithSalt - implements CipherParameters { - final UnderlyingParameters parameters; - final Uint8List salt; - - ParametersWithSalt(this.parameters, this.salt); -} diff --git a/pointycastle/lib/src/api/parameters_with_salt_configuration.dart b/pointycastle/lib/src/api/parameters_with_salt_configuration.dart deleted file mode 100644 index acc4550..0000000 --- a/pointycastle/lib/src/api/parameters_with_salt_configuration.dart +++ /dev/null @@ -1,15 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// [CipherParameters] consisting of an underlying [CipherParameters] (of type -/// [UnderlyingParameters]), an acompanying [SecureRandom], and salt length. -class ParametersWithSaltConfiguration< - UnderlyingParameters extends CipherParameters> implements CipherParameters { - final UnderlyingParameters parameters; - final SecureRandom random; - final int saltLength; - - ParametersWithSaltConfiguration( - this.parameters, this.random, this.saltLength); -} diff --git a/pointycastle/lib/src/api/pbe_parameters_generator.dart b/pointycastle/lib/src/api/pbe_parameters_generator.dart deleted file mode 100644 index 4a97c69..0000000 --- a/pointycastle/lib/src/api/pbe_parameters_generator.dart +++ /dev/null @@ -1,23 +0,0 @@ -part of '../../api.dart'; - -abstract class PBEParametersGenerator { - factory PBEParametersGenerator(String algorithmName) => - registry.create(algorithmName); - - void init(Uint8List password, Uint8List salt, int iterationCount); - - /// - /// Generates a derived key with the given [keySize] in bytes. - /// - KeyParameter generateDerivedParameters(int keySize); - - /// - /// Generates a derived key with the given [keySize] in bytes and a derived IV with the given [ivSize]. - /// - ParametersWithIV generateDerivedParametersWithIV(int keySize, int ivSize); - - /// - /// Generates a derived key with the given [keySize] in bytes used for mac generating. - /// - KeyParameter generateDerivedMacParameters(int keySize); -} diff --git a/pointycastle/lib/src/api/private_key.dart b/pointycastle/lib/src/api/private_key.dart deleted file mode 100644 index a8f2a3b..0000000 --- a/pointycastle/lib/src/api/private_key.dart +++ /dev/null @@ -1,6 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// The interface that asymmetric private keys conform to. -abstract class PrivateKey implements AsymmetricKey {} diff --git a/pointycastle/lib/src/api/private_key_parameter.dart b/pointycastle/lib/src/api/private_key_parameter.dart deleted file mode 100644 index 8ee7bb7..0000000 --- a/pointycastle/lib/src/api/private_key_parameter.dart +++ /dev/null @@ -1,9 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// A [CipherParameters] to hold an asymmetric private key -class PrivateKeyParameter - extends AsymmetricKeyParameter { - PrivateKeyParameter(PrivateKey key) : super(key as T); -} diff --git a/pointycastle/lib/src/api/public_key.dart b/pointycastle/lib/src/api/public_key.dart deleted file mode 100644 index 5ab25d7..0000000 --- a/pointycastle/lib/src/api/public_key.dart +++ /dev/null @@ -1,6 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// The interface that asymmetric public keys conform to. -abstract class PublicKey implements AsymmetricKey {} diff --git a/pointycastle/lib/src/api/public_key_parameter.dart b/pointycastle/lib/src/api/public_key_parameter.dart deleted file mode 100644 index a93ef83..0000000 --- a/pointycastle/lib/src/api/public_key_parameter.dart +++ /dev/null @@ -1,9 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// A [CipherParameters] to hold an asymmetric public key -class PublicKeyParameter - extends AsymmetricKeyParameter { - PublicKeyParameter(PublicKey key) : super(key as T); -} diff --git a/pointycastle/lib/src/api/rc2_parameters.dart b/pointycastle/lib/src/api/rc2_parameters.dart deleted file mode 100644 index 14a742d..0000000 --- a/pointycastle/lib/src/api/rc2_parameters.dart +++ /dev/null @@ -1,13 +0,0 @@ -part of '../../api.dart'; - -class RC2Parameters extends KeyParameter { - late int effectiveKeyBits; - - RC2Parameters(Uint8List key, {int? bits}) : super(key) { - if (bits != null) { - effectiveKeyBits = bits; - } else { - effectiveKeyBits = (key.length > 128) ? 1024 : (key.length * 8); - } - } -} diff --git a/pointycastle/lib/src/api/registry_factory_exception.dart b/pointycastle/lib/src/api/registry_factory_exception.dart deleted file mode 100644 index bacb5b6..0000000 --- a/pointycastle/lib/src/api/registry_factory_exception.dart +++ /dev/null @@ -1,24 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// This kind of exception is thrown when a user tries to create an algorithm -/// or domain parameters that were not correctly registered. This can be -/// because the corresponding class was not imported, or because the algorithm -/// does not exist. -class RegistryFactoryException implements Exception { - final String message; - - RegistryFactoryException(this.message); - - RegistryFactoryException.unknown(String algorithm, [Type? type]) - : this( - 'No algorithm registered${type != null ? ' of type $type' : ''} with name: $algorithm'); - - RegistryFactoryException.invalid(String algorithm, [Type? type]) - : this( - 'Algorithm name $algorithm is invalid${type != null ? ' of type $type' : ''}'); - - @override - String toString() => 'RegistryFactoryException: $message'; -} diff --git a/pointycastle/lib/src/api/secure_random.dart b/pointycastle/lib/src/api/secure_random.dart deleted file mode 100644 index 649086c..0000000 --- a/pointycastle/lib/src/api/secure_random.dart +++ /dev/null @@ -1,34 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// A synchronous secure random number generator (RNG). -/// -/// Being synchronous, this RNG cannot return direct results from sources of randomness like -/// '/dev/random' or similar. For that, use an **EntropySource** which allows to be called -/// asynchronously. Usually an **EntropySource** should be seen like a random generation device while -/// a [SecureRandom] should be seen like a cryptographic PRNG. Thus, data from an **EntropySource** -/// should be seen as 'more random' than that returned from a [SecureRandom]. -abstract class SecureRandom extends Algorithm { - /// Create the secure random specified by the standard [algorithmName]. - factory SecureRandom([String algorithmName = '']) => - registry.create(algorithmName); - - /// Seed the RNG with some entropy (look at package cipher_entropy providing entropy sources). - void seed(CipherParameters params); - - /// Get one byte long random int. - int nextUint8(); - - /// Get two bytes long random int. - int nextUint16(); - - /// Get four bytes long random int. - int nextUint32(); - - /// Get a random BigInteger of [bitLength] bits. - BigInt nextBigInteger(int bitLength); - - /// Get a list of bytes of arbitrary length. - Uint8List nextBytes(int count); -} diff --git a/pointycastle/lib/src/api/signature.dart b/pointycastle/lib/src/api/signature.dart deleted file mode 100644 index 19527cc..0000000 --- a/pointycastle/lib/src/api/signature.dart +++ /dev/null @@ -1,6 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// An interface for signatures created by a [Signer] -abstract class Signature {} diff --git a/pointycastle/lib/src/api/signer.dart b/pointycastle/lib/src/api/signer.dart deleted file mode 100644 index a07088b..0000000 --- a/pointycastle/lib/src/api/signer.dart +++ /dev/null @@ -1,25 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// An interface for DSAs (digital signature algorithms) -abstract class Signer extends Algorithm { - /// Create the signer specified by the standard [algorithmName]. - factory Signer(String algorithmName) => - registry.create(algorithmName); - - /// Reset the signer to its original state. - void reset(); - - /// Init the signer with its initialization [params]. The type of [CipherParameters] depends on the algorithm being used (see - /// the documentation of each implementation to find out more). - /// - /// Use the argument [forSigning] to tell the signer if you want to generate or verify signatures. - void init(bool forSigning, CipherParameters params); - - /// Sign the passed in [message] (usually the output of a hash function) - Signature generateSignature(Uint8List message); - - /// Verify the [message] against the [signature]. - bool verifySignature(Uint8List message, Signature signature); -} diff --git a/pointycastle/lib/src/api/srp_client.dart b/pointycastle/lib/src/api/srp_client.dart deleted file mode 100644 index d9a11cc..0000000 --- a/pointycastle/lib/src/api/srp_client.dart +++ /dev/null @@ -1,35 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -abstract class SRPClient { - ///Computes the client evidence message M1 using the previously received values. - ///To be called after calculating the secret S. - ///returns M1: the client side generated evidence message - ///throws Exception - BigInt? calculateClientEvidenceMessage(); - - ///Generates the secret S given the server's credentials - ///@param serverB The server's credentials - ///@return Client's verification message for the server - ///@throws Exception If server's credentials are invalid - /// - BigInt? calculateSecret(BigInt serverB); - - /// Computes the final session key as a result of the SRP successful mutual authentication - /// To be called after verifying the server evidence message M2. - /// returns Key: the mutually authenticated symmetric session key - /// throws Exception - BigInt? calculateSessionKey(); - - /// Generates the client's credentials that are to be sent to the server. - /// @return The client's public value - BigInt? generateClientCredentials( - Uint8List salt, Uint8List identity, Uint8List password); - - /// Authenticates the server evidence message M2 received and saves it only if correct. - /// [serverM2] the server side generated evidence message - /// return A boolean indicating if the server message M2 was the expected one. - /// throws Exception - bool verifyServerEvidenceMessage(BigInt serverM2); -} diff --git a/pointycastle/lib/src/api/srp_server.dart b/pointycastle/lib/src/api/srp_server.dart deleted file mode 100644 index 3dc5e74..0000000 --- a/pointycastle/lib/src/api/srp_server.dart +++ /dev/null @@ -1,37 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// Implements the server side SRP-6a protocol. Note that this class is stateful, and therefore NOT threadsafe. -/// This implementation of SRP is based on the optimized message sequence put forth by Thomas Wu in the paper -/// "SRP-6: Improvements and Refinements to the Secure Remote Password Protocol, 2002" -abstract class SRPServer { - /// Processes the client's credentials. If valid the shared secret is generated and returned. - /// @param clientA The client's credentials - /// @return A shared secret BigInt - /// @throws CryptoException If client's credentials are invalid - BigInt? calculateSecret(BigInt clientA); - - /// Computes the final session key as a result of the SRP successful mutual authentication - /// To be called after calculating the server evidence message M2. - /// @return Key: the mutual authenticated symmetric session key - /// @throws CryptoException - BigInt? calculateSessionKey(); - - /// Generates the server's credentials that are to be sent to the client. - /// @return The server's public value - BigInt? generateServerCredentials(); - - /// Computes the server evidence message M2 using the previously verified values. - /// To be called after successfully verifying the client evidence message M1. - /// @return M2: the server side generated evidence message - /// @throws CryptoException - BigInt? calculateServerEvidenceMessage(); - - /// Authenticates the received client evidence message M1 and saves it only if correct. - /// To be called after calculating the secret S. - /// @param clientM1 the client side generated evidence message - /// @return A boolean indicating if the client message M1 was the expected one. - /// @throws CryptoException - bool verifyClientEvidenceMessage(BigInt clientM1); -} diff --git a/pointycastle/lib/src/api/stream_cipher.dart b/pointycastle/lib/src/api/stream_cipher.dart deleted file mode 100644 index 34e52f3..0000000 --- a/pointycastle/lib/src/api/stream_cipher.dart +++ /dev/null @@ -1,32 +0,0 @@ -// See file LICENSE for more information. - -part of '../../api.dart'; - -/// The interface stream ciphers conform to. -abstract class StreamCipher extends Algorithm { - /// Create the cipher specified by the standard [algorithmName]. - factory StreamCipher(String algorithmName) => - registry.create(algorithmName); - - /// Reset the cipher to its original state. - void reset(); - - /// Init the cipher with its initialization [params]. The type of - /// [CipherParameters] depends on the algorithm being used (see the - /// documentation of each implementation to find out more). - /// - /// Use the argument [forEncryption] to tell the cipher if you want to encrypt - /// or decrypt data. - void init(bool forEncryption, CipherParameters? params); - - /// Process a whole block of [data] at once, returning the result in a byte array. - Uint8List process(Uint8List data); - - /// Process one byte of data given by [inp] and return its encrypted value. - int returnByte(int inp); - - /// Process [len] bytes of data given by [inp] and starting at offset [inpOff]. - /// The resulting cipher text is put in [out] beginning at position [outOff]. - void processBytes( - Uint8List inp, int inpOff, int len, Uint8List out, int outOff); -} diff --git a/pointycastle/lib/src/api/xof.dart b/pointycastle/lib/src/api/xof.dart deleted file mode 100644 index 64dd575..0000000 --- a/pointycastle/lib/src/api/xof.dart +++ /dev/null @@ -1,11 +0,0 @@ -part of '../../api.dart'; - -abstract class Xof extends Digest { - /// Create the Xof specified by the standard [algorithmName]. - factory Xof(String algorithmName) => registry.create(algorithmName); - - /// - int doFinalRange(Uint8List out, int outOff, int outLen); - - int doOutput(Uint8List out, int outOff, int outLen); -} diff --git a/pointycastle/lib/src/ct.dart b/pointycastle/lib/src/ct.dart deleted file mode 100644 index bdf965b..0000000 --- a/pointycastle/lib/src/ct.dart +++ /dev/null @@ -1,16 +0,0 @@ -// See file LICENSE for more information. - -import 'dart:typed_data'; - -/// -/// Constant time XOR, use to replace if (condition) { xor(x,y);} -/// CT_xor, x <- x ^ y when b is true -/// asserts x length and y length are equal -/// -void CT_xor(Uint8List x, Uint8List y, bool b) { - assert(x.length == y.length, 'x length and y length must be same'); - var mask = b ? 0xFF : 0; // (-b) & 0xFF; - for (var i = 0; i < x.length; i++) { - x[i] = x[i] ^ (y[i] & mask); - } -} diff --git a/pointycastle/lib/src/ec_standard_curve_constructor.dart b/pointycastle/lib/src/ec_standard_curve_constructor.dart deleted file mode 100644 index d18dacf..0000000 --- a/pointycastle/lib/src/ec_standard_curve_constructor.dart +++ /dev/null @@ -1,20 +0,0 @@ -// See file LICENSE for more information. - -import 'package:pointycastle/ecc/ecc_base.dart'; -import 'package:pointycastle/ecc/ecc_fp.dart' as fp; -import 'package:pointycastle/src/utils.dart' as utils; - -ECDomainParametersImpl constructFpStandardCurve( - String name, Function constructor, - {BigInt? q, - BigInt? a, - BigInt? b, - BigInt? g, - BigInt? n, - BigInt? h, - BigInt? seed}) { - var curve = fp.ECCurve(q, a, b); - var seedBytes = (seed == null) ? null : utils.encodeBigInt(seed); - return constructor( - name, curve, curve.decodePoint(utils.encodeBigInt(g)), n, h, seedBytes); -} diff --git a/pointycastle/lib/src/impl/base_aead_block_cipher.dart b/pointycastle/lib/src/impl/base_aead_block_cipher.dart deleted file mode 100644 index bd022a1..0000000 --- a/pointycastle/lib/src/impl/base_aead_block_cipher.dart +++ /dev/null @@ -1,223 +0,0 @@ -import 'dart:math' show min; -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/utils.dart'; - -abstract class BaseAEADBlockCipher implements AEADBlockCipher { - final BlockCipher _underlyingCipher; - - BaseAEADBlockCipher(this._underlyingCipher); - - // These fields are set by init and not modified by processing - late bool _forEncryption; - late int _macSize; - Uint8List? _lastKey; - late Uint8List _nonce; - late Uint8List _initialAssociatedText; - - // These fields are modified during processing - Uint8List? _bufBlock; - int? _bufOff; - Uint8List? _lastMacSizeBytes; - late int _lastMacSizeBytesOff; - - @override - int get blockSize => underlyingCipher.blockSize; - - /// The underlying cipher - BlockCipher get underlyingCipher => _underlyingCipher; - - /// True if initialized for encryption - bool get forEncryption => _forEncryption; - - /// The nonce or iv as set by the initialization - Uint8List get nonce => _nonce; - - /// The additional authenticated data as set by the initialization - Uint8List? get aad => _initialAssociatedText; - - /// Any remaining input yet to be processed - Uint8List get remainingInput => - Uint8List.view(_bufBlock!.buffer, _bufBlock!.offsetInBytes, _bufOff); - - /// The length in bytes of the authentication tag - int get macSize => _macSize; - - /// The value of the authentication tag associated with the last processed - /// data - Uint8List get mac; - - /// Prepare for a stream of data. This method is called during - /// initialization and reset. - void prepare(KeyParameter keyParam); - - /// Processes the additional authentication data - void processAADBytes(Uint8List inp, int inpOff, int len); - - /// When decrypting, validates the generated authentication tag with the one - /// in the input stream. When not equal throws [InvalidCipherTextException]. - /// This method should be called from the [doFinal] method. - void validateMac() { - if (forEncryption) { - return; - } - if (_lastMacSizeBytesOff != macSize) { - throw InvalidCipherTextException('Input data too short'); - } - if (!constantTimeAreEqual(mac, _lastMacSizeBytes!)) { - throw InvalidCipherTextException('Authentication tag check failed'); - } - } - - @override - void init(bool forEncryption, CipherParameters? params) { - _forEncryption = forEncryption; - - KeyParameter keyParam; - Uint8List? newNonce; - - if (params is AEADParameters) { - var param = params; - - newNonce = param.nonce; - _initialAssociatedText = param.associatedData; - - var macSizeBits = param.macSize; - if (macSizeBits < 32 || macSizeBits > 256 || macSizeBits % 8 != 0) { - throw ArgumentError('Invalid value for MAC size: $macSizeBits'); - } - - _macSize = macSizeBits ~/ 8; - keyParam = param.parameters as KeyParameter; - } else if (params is ParametersWithIV) { - var param = params; - - newNonce = param.iv; - _initialAssociatedText = Uint8List(0); - _macSize = 16; - keyParam = param.parameters as KeyParameter; - } else { - throw ArgumentError('invalid parameters passed to AEADBlockCipher'); - } - - var bufLength = forEncryption ? blockSize : (blockSize + _macSize); - _bufBlock = Uint8List(bufLength); - - if (newNonce.isEmpty) { - throw ArgumentError('IV must be at least 1 byte'); - } - - _nonce = newNonce; - _lastKey = keyParam.key; - _lastMacSizeBytes = Uint8List(macSize); - - reset(); - } - - @override - Uint8List process(Uint8List data) { - var out = Uint8List(getOutputSize(data.length)); - - var len = processBytes(data, 0, data.length, out, 0); - - len += doFinal(out, len); - - return Uint8List.view(out.buffer, 0, len); - } - - @override - int processBytes( - Uint8List inp, int inpOff, int len, Uint8List out, int outOff) { - if (len == 0) return 0; - - if (forEncryption) { - // all bytes are plain text bytes - return _processCipherBytes(inp, inpOff, len, out, outOff); - } - - // last macSize bytes are possibly mac bytes and not cipher text bytes - // -> keep them in buffer - var cipherLen = _lastMacSizeBytesOff + len - macSize; - - var resultLen = 0; - - if (cipherLen > 0 && _lastMacSizeBytesOff > 0) { - // at least part of the buffer are actually cipher text bytes - // process them and update the buffer - - var l = min(_lastMacSizeBytesOff, cipherLen); - resultLen += _processCipherBytes(_lastMacSizeBytes!, 0, - min(_lastMacSizeBytesOff, cipherLen), out, outOff); - outOff += resultLen; - cipherLen -= l; - _lastMacSizeBytes!.setRange(0, macSize - l, _lastMacSizeBytes!.skip(l)); - _lastMacSizeBytesOff -= l; - } - - if (cipherLen > 0) { - // part of the input are cipher text bytes - resultLen += _processCipherBytes(inp, inpOff, cipherLen, out, outOff); - } - - _lastMacSizeBytes!.setRange(_lastMacSizeBytesOff, - _lastMacSizeBytesOff + len - cipherLen, inp.skip(inpOff + cipherLen)); - _lastMacSizeBytesOff += len - cipherLen; - - return resultLen; - } - - int _processCipherBytes( - Uint8List inp, int inpOff, int len, Uint8List out, int outOff) { - if (len == 0) return 0; - - var resultLen = 0; - - if (_bufOff != 0) { - // add to buffer until full - var end = blockSize < _bufOff! + len ? blockSize : _bufOff! + len; - _bufBlock!.setRange(_bufOff!, end, inp.skip(inpOff)); - len -= end - _bufOff!; - _bufOff = end; - - // if buffer full and has more data -> process buffer - if (_bufOff == blockSize && len > 0) { - processBlock(_bufBlock!, 0, out, outOff); - _bufOff = 0; - resultLen += blockSize; - } - } - - // process all full blocks - while (len > blockSize) { - processBlock(inp, inpOff, out, outOff + resultLen); - inpOff += blockSize; - len -= blockSize; - resultLen += blockSize; - } - - // keep last block in buffer - if (len > 0) { - _bufBlock!.setRange(0, len, inp.skip(inpOff)); - _bufOff = len; - } - - return resultLen; - } - - @override - void reset() { - _bufOff = 0; - _lastMacSizeBytesOff = 0; - - if (_lastKey == null) return; - - prepare(KeyParameter(_lastKey!)); - processAADBytes(_initialAssociatedText, 0, _initialAssociatedText.length); - } - - int getOutputSize(int length) => - (length + (forEncryption ? macSize : -macSize) + blockSize - 1) ~/ - blockSize * - blockSize; -} diff --git a/pointycastle/lib/src/impl/base_aead_cipher.dart b/pointycastle/lib/src/impl/base_aead_cipher.dart deleted file mode 100644 index a7477fb..0000000 --- a/pointycastle/lib/src/impl/base_aead_cipher.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'dart:typed_data'; - -import '../../api.dart'; - -abstract class BaseAEADCipher implements AEADCipher { - Uint8List process(Uint8List data) { - var out = Uint8List(data.length); - processBytes(data, 0, data.length, out, 0); - return out; - } -} diff --git a/pointycastle/lib/src/impl/base_asymmetric_block_cipher.dart b/pointycastle/lib/src/impl/base_asymmetric_block_cipher.dart deleted file mode 100644 index 46ebe98..0000000 --- a/pointycastle/lib/src/impl/base_asymmetric_block_cipher.dart +++ /dev/null @@ -1,15 +0,0 @@ -// See file LICENSE for more information. - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; - -/// Base implementation of [AsymmetricBlockCipher] which provides shared methods. -abstract class BaseAsymmetricBlockCipher implements AsymmetricBlockCipher { - @override - Uint8List process(Uint8List data) { - var out = Uint8List(outputBlockSize); - var len = processBlock(data, 0, data.length, out, 0); - return out.sublist(0, len); - } -} diff --git a/pointycastle/lib/src/impl/base_block_cipher.dart b/pointycastle/lib/src/impl/base_block_cipher.dart deleted file mode 100644 index bcf5075..0000000 --- a/pointycastle/lib/src/impl/base_block_cipher.dart +++ /dev/null @@ -1,15 +0,0 @@ -// See file LICENSE for more information. - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; - -/// Base implementation of [BlockCipher] which provides shared methods. -abstract class BaseBlockCipher implements BlockCipher { - @override - Uint8List process(Uint8List data) { - var out = Uint8List(blockSize); - var len = processBlock(data, 0, out, 0); - return out.sublist(0, len); - } -} diff --git a/pointycastle/lib/src/impl/base_digest.dart b/pointycastle/lib/src/impl/base_digest.dart deleted file mode 100644 index d332fc5..0000000 --- a/pointycastle/lib/src/impl/base_digest.dart +++ /dev/null @@ -1,16 +0,0 @@ -// See file LICENSE for more information. - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; - -/// Base implementation of [Digest] which provides shared methods. -abstract class BaseDigest implements Digest { - @override - Uint8List process(Uint8List data) { - update(data, 0, data.length); - var out = Uint8List(digestSize); - var len = doFinal(out, 0); - return out.sublist(0, len); - } -} diff --git a/pointycastle/lib/src/impl/base_key_derivator.dart b/pointycastle/lib/src/impl/base_key_derivator.dart deleted file mode 100644 index 45a4f67..0000000 --- a/pointycastle/lib/src/impl/base_key_derivator.dart +++ /dev/null @@ -1,15 +0,0 @@ -// See file LICENSE for more information. - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; - -/// Base implementation of [KeyDerivator] which provides shared methods. -abstract class BaseKeyDerivator implements KeyDerivator { - @override - Uint8List process(Uint8List data) { - var out = Uint8List(keySize); - var len = deriveKey(data, 0, out, 0); - return out.sublist(0, len); - } -} diff --git a/pointycastle/lib/src/impl/base_mac.dart b/pointycastle/lib/src/impl/base_mac.dart deleted file mode 100644 index 48f39d3..0000000 --- a/pointycastle/lib/src/impl/base_mac.dart +++ /dev/null @@ -1,16 +0,0 @@ -// See file LICENSE for more information. - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; - -/// Base implementation of [Mac] which provides shared methods. -abstract class BaseMac implements Mac { - @override - Uint8List process(Uint8List data) { - update(data, 0, data.length); - var out = Uint8List(macSize); - var len = doFinal(out, 0); - return out.sublist(0, len); - } -} diff --git a/pointycastle/lib/src/impl/base_padding.dart b/pointycastle/lib/src/impl/base_padding.dart deleted file mode 100644 index 33c95fb..0000000 --- a/pointycastle/lib/src/impl/base_padding.dart +++ /dev/null @@ -1,19 +0,0 @@ -// See file LICENSE for more information. - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; - -/// Base implementation of [Padding] which provides shared methods. -abstract class BasePadding implements Padding { - @override - Uint8List process(bool pad, Uint8List data) { - if (pad) { - throw StateError( - 'cannot add padding, use PaddedBlockCipher to add padding'); - } else { - var len = padCount(data); - return data.sublist(0, data.length - len); - } - } -} diff --git a/pointycastle/lib/src/impl/base_stream_cipher.dart b/pointycastle/lib/src/impl/base_stream_cipher.dart deleted file mode 100644 index 99d5540..0000000 --- a/pointycastle/lib/src/impl/base_stream_cipher.dart +++ /dev/null @@ -1,15 +0,0 @@ -// See file LICENSE for more information. - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; - -/// Base implementation of [StreamCipher] which provides shared methods. -abstract class BaseStreamCipher implements StreamCipher { - @override - Uint8List process(Uint8List data) { - var out = Uint8List(data.length); - processBytes(data, 0, data.length, out, 0); - return out; - } -} diff --git a/pointycastle/lib/src/impl/entropy.dart b/pointycastle/lib/src/impl/entropy.dart deleted file mode 100644 index 8956a3e..0000000 --- a/pointycastle/lib/src/impl/entropy.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'dart:typed_data'; - -/// Defines an entropy source, this is not to be confused with a rng. -/// Entropy sources are used to supply seed material. -abstract class EntropySource { - Uint8List getBytes(int len); -} diff --git a/pointycastle/lib/src/impl/keccak_engine.dart b/pointycastle/lib/src/impl/keccak_engine.dart deleted file mode 100644 index 9f6a9a6..0000000 --- a/pointycastle/lib/src/impl/keccak_engine.dart +++ /dev/null @@ -1,396 +0,0 @@ -// See file LICENSE for more information. - -import 'dart:math'; -import 'dart:typed_data'; - -import 'package:pointycastle/src/impl/base_digest.dart'; - -import '../ufixnum.dart'; - -// KeccakEngine -abstract class KeccakEngine extends BaseDigest { - static final _keccakRoundConstants = Register64List.from([ - [0x00000000, 0x00000001], - [0x00000000, 0x00008082], - [0x80000000, 0x0000808a], - [0x80000000, 0x80008000], - [0x00000000, 0x0000808b], - [0x00000000, 0x80000001], - [0x80000000, 0x80008081], - [0x80000000, 0x00008009], - [0x00000000, 0x0000008a], - [0x00000000, 0x00000088], - [0x00000000, 0x80008009], - [0x00000000, 0x8000000a], - [0x00000000, 0x8000808b], - [0x80000000, 0x0000008b], - [0x80000000, 0x00008089], - [0x80000000, 0x00008003], - [0x80000000, 0x00008002], - [0x80000000, 0x00000080], - [0x00000000, 0x0000800a], - [0x80000000, 0x8000000a], - [0x80000000, 0x80008081], - [0x80000000, 0x00008080], - [0x00000000, 0x80000001], - [0x80000000, 0x80008008] - ]); - - static final _keccakRhoOffsets = [ - 0x00000000, - 0x00000001, - 0x0000003e, - 0x0000001c, - 0x0000001b, - 0x00000024, - 0x0000002c, - 0x00000006, - 0x00000037, - 0x00000014, - 0x00000003, - 0x0000000a, - 0x0000002b, - 0x00000019, - 0x00000027, - 0x00000029, - 0x0000002d, - 0x0000000f, - 0x00000015, - 0x00000008, - 0x00000012, - 0x00000002, - 0x0000003d, - 0x00000038, - 0x0000000e - ]; - - final _state = Uint8List(200); - final _dataQueue = Uint8List(192); - - late int _rate; - late int fixedOutputLength; - late int _bitsInQueue; - late bool _squeezing; - - /// dataQueue intended for use by subclasses only. - Uint8List get dataQueue => _dataQueue; - - /// squeezing intended for use by subclasses only. - bool get squeezing => _squeezing; - - @override - int get byteLength => _rate ~/ 8; - - @override - int get digestSize => fixedOutputLength ~/ 8; - - int get rate => _rate; - - @override - void reset() { - init(fixedOutputLength); - } - - @override - void updateByte(int inp) { - absorb(inp); - } - - @override - void update(Uint8List inp, int inpOff, int len) { - _doUpdate(inp, inpOff, len); - } - - void absorb(int data) { - if ((_bitsInQueue % 8) != 0) { - throw StateError('attempt to absorb with odd length queue'); - } - if (_squeezing) { - throw StateError('attempt to absorb while squeezing'); - } - - _dataQueue[_bitsInQueue >> 3] = data; - if ((_bitsInQueue += 8) == _rate) { - _keccakAbsorb(_dataQueue, 0); - _bitsInQueue = 0; - } - } - - void absorbBits(int data, int bits) { - if (bits < 1 || bits > 7) { - throw StateError('"bits" must be in the range 1 to 7'); - } - if ((_bitsInQueue % 8) != 0) { - throw StateError('attempt to absorb with odd length queue'); - } - if (_squeezing) { - throw StateError('attempt to absorb while squeezing'); - } - var mask = (1 << bits) - 1; - _dataQueue[_bitsInQueue >> 3] = data & mask; - _bitsInQueue += bits; - } - - void absorbRange(Uint8List data, int off, int len) { - if ((_bitsInQueue % 8) != 0) { - throw StateError('attempt to absorb with odd length queue'); - } - if (squeezing) { - throw StateError('attempt to absorb while squeezing'); - } - - var bytesInQueue = _bitsInQueue >> 3; - var rateBytes = _rate >> 3; - - var available = rateBytes - bytesInQueue; - if (len < available) { - _dataQueue.setRange(bytesInQueue, bytesInQueue + len, data, off); - _bitsInQueue += len << 3; - return; - } - - var count = 0; - if (bytesInQueue > 0) { - _dataQueue.setRange( - bytesInQueue, bytesInQueue + available, data.sublist(off)); - count += available; - _keccakAbsorb(_dataQueue, 0); - } - - int remaining; - while ((remaining = len - count) >= rateBytes) { - _keccakAbsorb(data, off + count); - count += rateBytes; - } - - _dataQueue.setRange(0, remaining, data, off + count); - _bitsInQueue = remaining << 3; - } - - void _doUpdate(Uint8List data, int off, int len) { - absorbRange(data, off, len); - } - - void init(int bitlen) { - _initSponge(1600 - (bitlen << 1)); - } - - void _initSponge(int theRate) { - if ((theRate <= 0) || (theRate >= 1600) || ((theRate % 64) != 0)) { - throw StateError('invalid rate value'); - } - - _rate = theRate; - _state.fillRange(0, _state.length, 0); - _dataQueue.fillRange(0, _dataQueue.length, 0); - _bitsInQueue = 0; - _squeezing = false; - fixedOutputLength = (1600 - theRate) ~/ 2; - } - - void _keccakAbsorb(Uint8List? data, int off) { - var count = _rate >> 3; - for (var i = 0; i < count; ++i) { - _state[i] ^= data![off + i]; - } - _keccakPermutation(); - } - - void _keccakExtract() { - _keccakPermutation(); - - _dataQueue.setRange(0, _rate >> 3, _state); - _bitsInQueue = _rate; - } - - void squeeze(Uint8List? output, int? offset, int outputLength) { - if (!squeezing) { - _padAndSwitchToSqueezingPhase(); - } - - if ((outputLength % 8) != 0) { - throw StateError('outputLength not a multiple of 8'); - } - - var i = 0; - while (i < outputLength) { - if (_bitsInQueue == 0) { - _keccakExtract(); - } - - var partialBlock = min(_bitsInQueue, outputLength - i); - - output!.setRange( - offset! + (i ~/ 8), - offset + (i ~/ 8) + (partialBlock ~/ 8), - dataQueue.sublist((_rate - _bitsInQueue) ~/ 8)); - - //System.arraycopy(dataQueue, (rate - bitsInQueue) / 8, output, offset + (int)(i / 8), partialBlock / 8); - _bitsInQueue -= partialBlock; - i += partialBlock; - } - } - - void _padAndSwitchToSqueezingPhase() { - _dataQueue[_bitsInQueue >> 3] |= 1 << (_bitsInQueue & 7); - if (++_bitsInQueue == _rate) { - _keccakAbsorb(_dataQueue, 0); - } else { - var full = _bitsInQueue >> 6, partial = _bitsInQueue & 63; - for (var i = 0; i < full * 8; ++i) { - _state[i] ^= _dataQueue[i]; - } - - if (partial > 0) { - for (var k = 0; k != 8; k++) { - if (partial >= 8) { - _state[full * 8 + k] ^= dataQueue[full * 8 + k]; - } else { - _state[full * 8 + k] ^= - dataQueue[full * 8 + k] & ((1 << partial) - 1); - } - partial -= 8; - if (partial < 0) { - partial = 0; - } - } - } - } - - _state[((_rate - 1) >> 3)] ^= 1 << 7; - _bitsInQueue = 0; - _squeezing = true; - } - - void _fromBytesToWords(Register64List stateAsWords, Uint8List state) { - final r = Register64(); - - for (var i = 0; i < (1600 ~/ 64); i++) { - final index = i * (64 ~/ 8); - - stateAsWords[i].set(0); - - for (var j = 0; j < (64 ~/ 8); j++) { - r.set(state[index + j]); - r.shiftl(8 * j); - stateAsWords[i].or(r); - } - } - } - - void _fromWordsToBytes(Uint8List state, Register64List stateAsWords) { - final r = Register64(); - - for (var i = 0; i < (1600 ~/ 64); i++) { - final index = i * (64 ~/ 8); - - for (var j = 0; j < (64 ~/ 8); j++) { - r.set(stateAsWords[i]); - r.shiftr(8 * j); - state[index + j] = r.lo32; - } - } - } - - void _keccakPermutation() { - final longState = Register64List(_state.length ~/ 8); - - _fromBytesToWords(longState, _state); - _keccakPermutationOnWords(longState); - _fromWordsToBytes(_state, longState); - } - - void _keccakPermutationOnWords(Register64List state) { - for (var i = 0; i < 24; i++) { - theta(state); - rho(state); - pi(state); - chi(state); - _iota(state, i); - } - } - - void theta(Register64List A) { - final C = Register64List(5); - final r0 = Register64(); - final r1 = Register64(); - - for (var x = 0; x < 5; x++) { - C[x].set(0); - - for (var y = 0; y < 5; y++) { - C[x].xor(A[x + 5 * y]); - } - } - - for (var x = 0; x < 5; x++) { - r0.set(C[(x + 1) % 5]); - r0.shiftl(1); - - r1.set(C[(x + 1) % 5]); - r1.shiftr(63); - - r0.xor(r1); - r0.xor(C[(x + 4) % 5]); - - for (var y = 0; y < 5; y++) { - A[x + 5 * y].xor(r0); - } - } - } - - void rho(Register64List A) { - final r = Register64(); - - for (var x = 0; x < 5; x++) { - for (var y = 0; y < 5; y++) { - final index = x + 5 * y; - - if (_keccakRhoOffsets[index] != 0) { - r.set(A[index]); - r.shiftr(64 - _keccakRhoOffsets[index]); - - A[index].shiftl(_keccakRhoOffsets[index]); - A[index].xor(r); - } - } - } - } - - void pi(Register64List A) { - final tempA = Register64List(25); - - tempA.setRange(0, tempA.length, A); - - for (var x = 0; x < 5; x++) { - for (var y = 0; y < 5; y++) { - A[y + 5 * ((2 * x + 3 * y) % 5)].set(tempA[x + 5 * y]); - } - } - } - - void chi(Register64List A) { - final chiC = Register64List(5); - - for (var y = 0; y < 5; y++) { - for (var x = 0; x < 5; x++) { - chiC[x].set(A[((x + 1) % 5) + (5 * y)]); - chiC[x].not(); - chiC[x].and(A[((x + 2) % 5) + (5 * y)]); - chiC[x].xor(A[x + 5 * y]); - } - for (var x = 0; x < 5; x++) { - A[x + 5 * y].set(chiC[x]); - } - } - } - - void _iota(Register64List A, int indexRound) { - A[(((0) % 5) + 5 * ((0) % 5))].xor(_keccakRoundConstants[indexRound]); - } - - @override - int doFinal(Uint8List out, int outOff) { - throw UnimplementedError('Subclasses must implement this.'); - } -} diff --git a/pointycastle/lib/src/impl/long_sha2_family_digest.dart b/pointycastle/lib/src/impl/long_sha2_family_digest.dart deleted file mode 100644 index 4445104..0000000 --- a/pointycastle/lib/src/impl/long_sha2_family_digest.dart +++ /dev/null @@ -1,443 +0,0 @@ -// See file LICENSE for more information. - -import 'dart:typed_data'; - -import 'package:pointycastle/src/impl/base_digest.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Base implementation of SHA-2 family algorithms SHA-384 and SHA-512. -abstract class LongSHA2FamilyDigest extends BaseDigest { - static const _BYTE_LENGTH = 128; - - static final _maxByteCount1 = Register64(0x1fffffff, 0xffffffff); - - final h1 = Register64(); - final h2 = Register64(); - final h3 = Register64(); - final h4 = Register64(); - final h5 = Register64(); - final h6 = Register64(); - final h7 = Register64(); - final h8 = Register64(); - - final _wordBuffer = Uint8List(8); - int _wordBufferOffset = 0; - - final _w = Register64List(80); - int _wOff = 0; - - final _byteCount1 = Register64(); // TODO: convert to list - final _byteCount2 = Register64(); - - LongSHA2FamilyDigest() { - reset(); - } - - @override - int get byteLength => _BYTE_LENGTH; - - @override - void reset() { - _byteCount1.set(0); - _byteCount2.set(0); - - _wordBufferOffset = 0; - _wordBuffer.fillRange(0, _wordBuffer.length, 0); - - _wOff = 0; - _w.fillRange(0, _w.length, 0); - } - - @override - void updateByte(int inp) { - _wordBuffer[_wordBufferOffset++] = inp; - - if (_wordBufferOffset == _wordBuffer.length) { - _processWord(_wordBuffer, 0); - _wordBufferOffset = 0; - } - - _byteCount1.sum(1); - } - - @override - void update(Uint8List inp, int inpOff, int len) { - // fill the current word - while ((_wordBufferOffset != 0) && (len > 0)) { - updateByte(inp[inpOff]); - - inpOff++; - len--; - } - - // process whole words. - while (len > _wordBuffer.length) { - _processWord(inp, inpOff); - - inpOff += _wordBuffer.length; - len -= _wordBuffer.length; - _byteCount1.sum(_wordBuffer.length); - } - - // load in the remainder. - while (len > 0) { - updateByte(inp[inpOff]); - - inpOff++; - len--; - } - } - - void finish() { - _adjustByteCounts(); - - var lowBitLength = Register64(_byteCount1)..shiftl(3); - var hiBitLength = _byteCount2; - - // add the pad bytes. - updateByte(128); - - while (_wordBufferOffset != 0) { - updateByte(0); - } - - _processLength(lowBitLength, hiBitLength); - - _processBlock(); - } - - void _processWord(Uint8List inp, int inpOff) { - _w[_wOff++].unpack(inp, inpOff, Endian.big); - - if (_wOff == 16) { - _processBlock(); - } - } - - /// Adjust the byte counts so that byteCount2 represents the upper long (less 3 bits) word of the - /// byte count. - void _adjustByteCounts() { - if (_byteCount1 > _maxByteCount1) { - _byteCount2.sum(Register64(_byteCount1)..shiftr(61)); - _byteCount1.and(_maxByteCount1); - } - } - - void _processLength(Register64 lowW, Register64 hiW) { - if (_wOff > 14) { - _processBlock(); - } - - _w[14].set(hiW); - _w[15].set(lowW); - } - - void _processBlock() { - _adjustByteCounts(); - - // expand 16 word block into 80 word blocks. - for (var t = 16; t < 80; t++) { - // _w[t] = _sigma1(_w[t - 2]) + _w[t - 7] + _sigma0(_w[t - 15]) + _w[t - 16]; - _w[t].set(_sigma1(_w[t - 2]) - ..sum(_w[t - 7]) - ..sum(_sigma0(_w[t - 15])) - ..sum(_w[t - 16])); - } - - var a = Register64(h1); - var b = Register64(h2); - var c = Register64(h3); - var d = Register64(h4); - var e = Register64(h5); - var f = Register64(h6); - var g = Register64(h7); - var h = Register64(h8); - - var t = 0; - for (var i = 0; i < 10; i++) { - // t = 8 * i - h - ..sum(_sum1(e)) - ..sum(_ch(e, f, g)) - ..sum(_k[t]) - ..sum(_w[t++]); - d.sum(h); - h - ..sum(_sum0(a)) - ..sum(_maj(a, b, c)); - - // t = 8 * i + 1 - g - ..sum(_sum1(d)) - ..sum(_ch(d, e, f)) - ..sum(_k[t]) - ..sum(_w[t++]); - c.sum(g); - g - ..sum(_sum0(h)) - ..sum(_maj(h, a, b)); - - // t = 8 * i + 2 - f - ..sum(_sum1(c)) - ..sum(_ch(c, d, e)) - ..sum(_k[t]) - ..sum(_w[t++]); - b.sum(f); - f - ..sum(_sum0(g)) - ..sum(_maj(g, h, a)); - - // t = 8 * i + 3 - e - ..sum(_sum1(b)) - ..sum(_ch(b, c, d)) - ..sum(_k[t]) - ..sum(_w[t++]); - a.sum(e); - e - ..sum(_sum0(f)) - ..sum(_maj(f, g, h)); - - // t = 8 * i + 4 - d - ..sum(_sum1(a)) - ..sum(_ch(a, b, c)) - ..sum(_k[t]) - ..sum(_w[t++]); - h.sum(d); - d - ..sum(_sum0(e)) - ..sum(_maj(e, f, g)); - - // t = 8 * i + 5 - c - ..sum(_sum1(h)) - ..sum(_ch(h, a, b)) - ..sum(_k[t]) - ..sum(_w[t++]); - g.sum(c); - c - ..sum(_sum0(d)) - ..sum(_maj(d, e, f)); - - // t = 8 * i + 6 - b - ..sum(_sum1(g)) - ..sum(_ch(g, h, a)) - ..sum(_k[t]) - ..sum(_w[t++]); - f.sum(b); - b - ..sum(_sum0(c)) - ..sum(_maj(c, d, e)); - - // t = 8 * i + 7 - a - ..sum(_sum1(f)) - ..sum(_ch(f, g, h)) - ..sum(_k[t]) - ..sum(_w[t++]); - e.sum(a); - a - ..sum(_sum0(b)) - ..sum(_maj(b, c, d)); - } - - h1.sum(a); - h2.sum(b); - h3.sum(c); - h4.sum(d); - h5.sum(e); - h6.sum(f); - h7.sum(g); - h8.sum(h); - - // reset the offset and clean out the word buffer. - _wOff = 0; - _w.fillRange(0, 16, 0); - } - - Register64 _ch(Register64 x, Register64 y, Register64 z) { - // r += ((x & y) ^ ((~x) & z)); - var r0 = Register64(x); - r0.and(y); - - var r1 = Register64(x); - r1.not(); - r1.and(z); - - r0.xor(r1); - return r0; - } - - Register64 _maj(Register64 x, Register64 y, Register64 z) { - // r += ((x & y) ^ (x & z) ^ (y & z)); - var r0 = Register64(x); - r0.and(y); - - var r1 = Register64(x); - r1.and(z); - - var r2 = Register64(y); - r2.and(z); - - r0.xor(r1); - r0.xor(r2); - - return r0; - } - - Register64 _sum0(Register64 x) { - // r += ((x << 36)|(x >> 28)) ^ ((x << 30)|(x >> 34)) ^ ((x << 25)|(x >> 39)); - var r0 = Register64(x); - r0.rotl(36); - - var r1 = Register64(x); - r1.rotl(30); - - var r2 = Register64(x); - r2.rotl(25); - - r0.xor(r1); - r0.xor(r2); - - return r0; - } - - Register64 _sum1(Register64 x) { - // r += ((x << 50)|(x >> 14)) ^ ((x << 46)|(x >> 18)) ^ ((x << 23)|(x >> 41)); - var r0 = Register64(x); - r0.rotl(50); - - var r1 = Register64(x); - r1.rotl(46); - - var r2 = Register64(x); - r2.rotl(23); - - r0.xor(r1); - r0.xor(r2); - - return r0; - } - - Register64 _sigma0(Register64 x) { - // r = (((x << 63)|(x >> 1)) ^ ((x << 56)|(x >> 8)) ^ (x >> 7)); - var r0 = Register64(x); - r0.rotl(63); - - var r1 = Register64(x); - r1.rotl(56); - - var r2 = Register64(x); - r2.shiftr(7); - - r0.xor(r1); - r0.xor(r2); - - return r0; - } - - Register64 _sigma1(Register64 x) { - // r = (((x << 45)|(x >> 19)) ^ ((x << 3)|(x >> 61)) ^ (x >> 6)); - var r0 = Register64(x); - r0.rotl(45); - - var r1 = Register64(x); - r1.rotl(3); - - var r2 = Register64(x); - r2.shiftr(6); - - r0.xor(r1); - r0.xor(r2); - - return r0; - } - - /// SHA-384 and SHA-512 constants: represent the first 64 bits of the fractional parts of the cube - /// roots of the first sixty-four prime numbers) - static final _k = [ - Register64(0x428a2f98, 0xd728ae22), - Register64(0x71374491, 0x23ef65cd), - Register64(0xb5c0fbcf, 0xec4d3b2f), - Register64(0xe9b5dba5, 0x8189dbbc), - Register64(0x3956c25b, 0xf348b538), - Register64(0x59f111f1, 0xb605d019), - Register64(0x923f82a4, 0xaf194f9b), - Register64(0xab1c5ed5, 0xda6d8118), - Register64(0xd807aa98, 0xa3030242), - Register64(0x12835b01, 0x45706fbe), - Register64(0x243185be, 0x4ee4b28c), - Register64(0x550c7dc3, 0xd5ffb4e2), - Register64(0x72be5d74, 0xf27b896f), - Register64(0x80deb1fe, 0x3b1696b1), - Register64(0x9bdc06a7, 0x25c71235), - Register64(0xc19bf174, 0xcf692694), - Register64(0xe49b69c1, 0x9ef14ad2), - Register64(0xefbe4786, 0x384f25e3), - Register64(0x0fc19dc6, 0x8b8cd5b5), - Register64(0x240ca1cc, 0x77ac9c65), - Register64(0x2de92c6f, 0x592b0275), - Register64(0x4a7484aa, 0x6ea6e483), - Register64(0x5cb0a9dc, 0xbd41fbd4), - Register64(0x76f988da, 0x831153b5), - Register64(0x983e5152, 0xee66dfab), - Register64(0xa831c66d, 0x2db43210), - Register64(0xb00327c8, 0x98fb213f), - Register64(0xbf597fc7, 0xbeef0ee4), - Register64(0xc6e00bf3, 0x3da88fc2), - Register64(0xd5a79147, 0x930aa725), - Register64(0x06ca6351, 0xe003826f), - Register64(0x14292967, 0x0a0e6e70), - Register64(0x27b70a85, 0x46d22ffc), - Register64(0x2e1b2138, 0x5c26c926), - Register64(0x4d2c6dfc, 0x5ac42aed), - Register64(0x53380d13, 0x9d95b3df), - Register64(0x650a7354, 0x8baf63de), - Register64(0x766a0abb, 0x3c77b2a8), - Register64(0x81c2c92e, 0x47edaee6), - Register64(0x92722c85, 0x1482353b), - Register64(0xa2bfe8a1, 0x4cf10364), - Register64(0xa81a664b, 0xbc423001), - Register64(0xc24b8b70, 0xd0f89791), - Register64(0xc76c51a3, 0x0654be30), - Register64(0xd192e819, 0xd6ef5218), - Register64(0xd6990624, 0x5565a910), - Register64(0xf40e3585, 0x5771202a), - Register64(0x106aa070, 0x32bbd1b8), - Register64(0x19a4c116, 0xb8d2d0c8), - Register64(0x1e376c08, 0x5141ab53), - Register64(0x2748774c, 0xdf8eeb99), - Register64(0x34b0bcb5, 0xe19b48a8), - Register64(0x391c0cb3, 0xc5c95a63), - Register64(0x4ed8aa4a, 0xe3418acb), - Register64(0x5b9cca4f, 0x7763e373), - Register64(0x682e6ff3, 0xd6b2b8a3), - Register64(0x748f82ee, 0x5defb2fc), - Register64(0x78a5636f, 0x43172f60), - Register64(0x84c87814, 0xa1f0ab72), - Register64(0x8cc70208, 0x1a6439ec), - Register64(0x90befffa, 0x23631e28), - Register64(0xa4506ceb, 0xde82bde9), - Register64(0xbef9a3f7, 0xb2c67915), - Register64(0xc67178f2, 0xe372532b), - Register64(0xca273ece, 0xea26619c), - Register64(0xd186b8c7, 0x21c0c207), - Register64(0xeada7dd6, 0xcde0eb1e), - Register64(0xf57d4f7f, 0xee6ed178), - Register64(0x06f067aa, 0x72176fba), - Register64(0x0a637dc5, 0xa2c898a6), - Register64(0x113f9804, 0xbef90dae), - Register64(0x1b710b35, 0x131c471b), - Register64(0x28db77f5, 0x23047d84), - Register64(0x32caab7b, 0x40c72493), - Register64(0x3c9ebe0a, 0x15c9bebc), - Register64(0x431d67c4, 0x9c100d4c), - Register64(0x4cc5d4be, 0xcb3e42b6), - Register64(0x597f299c, 0xfc657e2a), - Register64(0x5fcb6fab, 0x3ad6faec), - Register64(0x6c44198c, 0x4a475817) - ]; -} diff --git a/pointycastle/lib/src/impl/md4_family_digest.dart b/pointycastle/lib/src/impl/md4_family_digest.dart deleted file mode 100644 index 49e297f..0000000 --- a/pointycastle/lib/src/impl/md4_family_digest.dart +++ /dev/null @@ -1,190 +0,0 @@ -// See file LICENSE for more information. - -import 'dart:typed_data'; - -import 'package:pointycastle/src/ufixnum.dart'; -import 'package:pointycastle/src/impl/base_digest.dart'; - -/// Base implementation of MD4 family style digest -abstract class MD4FamilyDigest extends BaseDigest { - final _byteCount = Register64(0); - - final _wordBuffer = Uint8List(4); - late int _wordBufferOffset; - - final Endian _endian; - final int _packedStateSize; - - final List state; - - final List buffer; - late int bufferOffset; - - MD4FamilyDigest(this._endian, int stateSize, int bufferSize, - [int? packedStateSize]) - : _packedStateSize = - (packedStateSize == null) ? stateSize : packedStateSize, - state = List.filled(stateSize, 0, growable: false), - buffer = List.filled(bufferSize, 0, growable: false) { - reset(); - } - - /// Reset state of digest. - void resetState(); - - /// Process a whole block of data in extender digest. - void processBlock(); - - @override - void reset() { - _byteCount.set(0); - - _wordBufferOffset = 0; - _wordBuffer.fillRange(0, _wordBuffer.length, 0); - - bufferOffset = 0; - buffer.fillRange(0, buffer.length, 0); - - resetState(); - } - - @override - void updateByte(int inp) { - _wordBuffer[_wordBufferOffset++] = clip8(inp); - _processWordIfBufferFull(); - _byteCount.sum(1); - } - - @override - void update(Uint8List inp, int inpOff, int len) { - int nbytes; - - nbytes = _processUntilNextWord(inp, inpOff, len); - inpOff += nbytes; - len -= nbytes; - - nbytes = _processWholeWords(inp, inpOff, len); - inpOff += nbytes; - len -= nbytes; - - _processBytes(inp, inpOff, len); - } - - @override - int doFinal(Uint8List out, int outOff) { - var bitLength = Register64(_byteCount)..shiftl(3); - - _processPadding(); - _processLength(bitLength); - _doProcessBlock(); - - _packState(out, outOff); - - reset(); - - return digestSize; - } - - /// Process a word (4 bytes) of data stored in [inp], starting at [inpOff]. - void _processWord(Uint8List inp, int inpOff) { - buffer[bufferOffset++] = unpack32(inp, inpOff, _endian); - - if (bufferOffset == 16) { - _doProcessBlock(); - } - } - - /// Process a block of data and reset the [buffer]. - void _doProcessBlock() { - processBlock(); - - // reset the offset and clean out the word buffer. - bufferOffset = 0; - buffer.fillRange(0, 16, 0); - } - - /// Process [len] bytes from [inp] starting at [inpOff] - void _processBytes(Uint8List inp, int inpOff, int len) { - while (len > 0) { - updateByte(inp[inpOff]); - - inpOff++; - len--; - } - } - - /// Process data word by word until no more words can be extracted from [inp] and return the number of bytes processed. - int _processWholeWords(Uint8List inp, int inpOff, int len) { - var processed = 0; - while (len > _wordBuffer.length) { - _processWord(inp, inpOff); - - inpOff += _wordBuffer.length; - len -= _wordBuffer.length; - _byteCount.sum(_wordBuffer.length); - processed += 4; - } - return processed; - } - - /// Process bytes from [inp] until the word buffer [_wordBuffer] is full and reset and return the number of bytes processed. - int _processUntilNextWord(Uint8List inp, int inpOff, int len) { - var processed = 0; - - while ((_wordBufferOffset != 0) && (len > 0)) { - updateByte(inp[inpOff]); - - inpOff++; - len--; - processed++; - } - - return processed; - } - - // ignore: comment_references - /// Process a word in [_xBuff] if it is already full and then reset it - void _processWordIfBufferFull() { - if (_wordBufferOffset == _wordBuffer.length) { - _processWord(_wordBuffer, 0); - _wordBufferOffset = 0; - } - } - - /// Add final padding to the digest - void _processPadding() { - updateByte(128); - while (_wordBufferOffset != 0) { - updateByte(0); - } - } - - // ignore: comment_references - /// Called from [finish] so that extender can process the number of bits processed. - void _processLength(Register64 bitLength) { - if (bufferOffset > 14) { - _doProcessBlock(); - } - - switch (_endian) { - case Endian.little: - buffer[14] = bitLength.lo32; - buffer[15] = bitLength.hi32; - break; - - case Endian.big: - buffer[14] = bitLength.hi32; - buffer[15] = bitLength.lo32; - break; - - default: - throw StateError('Invalid endianness: $_endian'); - } - } - - void _packState(Uint8List out, int outOff) { - for (var i = 0; i < _packedStateSize; i++) { - pack32(state[i], out, outOff + i * 4, _endian); - } - } -} diff --git a/pointycastle/lib/src/impl/secure_random_base.dart b/pointycastle/lib/src/impl/secure_random_base.dart deleted file mode 100644 index 316e890..0000000 --- a/pointycastle/lib/src/impl/secure_random_base.dart +++ /dev/null @@ -1,60 +0,0 @@ -// See file LICENSE for more information. - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/ufixnum.dart'; -import 'package:pointycastle/src/utils.dart' as utils; - -/// An utility base implementation of [SecureRandom] so that only [nextUint8] method needs to be -/// implemented. -abstract class SecureRandomBase implements SecureRandom { - @override - int nextUint16() { - var b0 = nextUint8(); - var b1 = nextUint8(); - return clip16((b1 << 8) | b0); - } - - @override - int nextUint32() { - var b0 = nextUint8(); - var b1 = nextUint8(); - var b2 = nextUint8(); - var b3 = nextUint8(); - return clip32((b3 << 24) | (b2 << 16) | (b1 << 8) | b0); - } - - @override - BigInt nextBigInteger(int bitLength) { - return utils.decodeBigIntWithSign(1, _randomBits(bitLength)); - } - - @override - Uint8List nextBytes(int count) { - var bytes = Uint8List(count); - for (var i = 0; i < count; i++) { - bytes[i] = nextUint8(); - } - return bytes; - } - - List _randomBits(int numBits) { - if (numBits < 0) { - throw ArgumentError('numBits must be non-negative'); - } - - var numBytes = (numBits + 7) ~/ 8; // avoid overflow - var randomBits = Uint8List(numBytes); - - // Generate random bytes and mask out any excess bits - if (numBytes > 0) { - for (var i = 0; i < numBytes; i++) { - randomBits[i] = nextUint8(); - } - var excessBits = 8 * numBytes - numBits; - randomBits[0] &= (1 << (8 - excessBits)) - 1; - } - return randomBits; - } -} diff --git a/pointycastle/lib/src/platform_check/abstract.dart b/pointycastle/lib/src/platform_check/abstract.dart deleted file mode 100644 index a92fe9d..0000000 --- a/pointycastle/lib/src/platform_check/abstract.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'dart:math'; -import 'dart:typed_data'; - -import 'package:pointycastle/src/impl/entropy.dart'; - -import 'platform_check.dart'; - -class PlatformGeneric extends Platform { - static final PlatformGeneric instance = PlatformGeneric(); - - const PlatformGeneric(); - - @override - bool get isNative => false; - - @override - String get platform => 'generic'; - - @override - EntropySource platformEntropySource() { - return _GenericEntropySource(); - } -} - -Platform getPlatform() => PlatformGeneric.instance; - -// Uses the built in entropy source -class _GenericEntropySource implements EntropySource { - final _src = Random.secure(); - - @override - Uint8List getBytes(int len) { - return Uint8List.fromList( - List.generate(len, (i) => _src.nextInt(256))); - } -} diff --git a/pointycastle/lib/src/platform_check/native.dart b/pointycastle/lib/src/platform_check/native.dart deleted file mode 100644 index 6d18028..0000000 --- a/pointycastle/lib/src/platform_check/native.dart +++ /dev/null @@ -1,45 +0,0 @@ -import 'dart:io' as io; -import 'dart:math'; -import 'dart:typed_data'; - -import 'package:pointycastle/src/impl/entropy.dart'; - -import 'platform_check.dart'; - -class PlatformIO extends Platform { - static final PlatformIO instance = PlatformIO(); - - const PlatformIO(); - - @override - String get platform { - if (io.Platform.isAndroid) return 'Android'; - if (io.Platform.isIOS) return 'iOS'; - if (io.Platform.isWindows) return 'Windows'; - if (io.Platform.isLinux) return 'Linux'; - if (io.Platform.isFuchsia) return 'Fuchsia'; - if (io.Platform.isMacOS) return 'MacOS'; - - return 'native'; - } - - @override - bool get isNative => true; - - @override - EntropySource platformEntropySource() { - return _NativeRngProvider(); - } -} - -class _NativeRngProvider implements EntropySource { - final _src = Random.secure(); - - @override - Uint8List getBytes(int len) { - return Uint8List.fromList( - List.generate(len, (i) => _src.nextInt(256))); - } -} - -Platform getPlatform() => PlatformIO.instance; diff --git a/pointycastle/lib/src/platform_check/node_crypto.dart b/pointycastle/lib/src/platform_check/node_crypto.dart deleted file mode 100644 index 5f798a8..0000000 --- a/pointycastle/lib/src/platform_check/node_crypto.dart +++ /dev/null @@ -1,17 +0,0 @@ -/// Wrapper for needed NodeJS Crypto library function and require. -library nodecryto; - -import 'dart:js_interop'; -import 'dart:js_interop_unsafe'; - -@JS() -external JSObject require(String id); - -@JS() -@staticInterop -class NodeCrypto { - static JSAny randomFillSync(JSAny buf) { - final crypto = require('crypto'); - return crypto.callMethod('randomFillSync'.toJS, buf); - } -} diff --git a/pointycastle/lib/src/platform_check/platform_check.dart b/pointycastle/lib/src/platform_check/platform_check.dart deleted file mode 100644 index 07e9965..0000000 --- a/pointycastle/lib/src/platform_check/platform_check.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'package:pointycastle/src/impl/entropy.dart'; - -import 'abstract.dart' - if (dart.library.io) 'native.dart' - if (dart.library.js) 'web.dart'; - -abstract class Platform { - static Platform get instance => getPlatform(); - static const bool _fwInteger = 9007199254740992 + 1 != 9007199254740992; - - const Platform(); - - String get platform; - - bool get isNative; - - bool get fullWidthInteger => _fwInteger; - - void assertFullWidthInteger() { - if (!_fwInteger) { - throw PlatformException( - 'full width integer not supported on this platform'); - } - } - - /// Platform dependent entropy source. - EntropySource platformEntropySource(); -} - -class PlatformException implements Exception { - String cause; - - PlatformException(this.cause); - - @override - String toString() => cause; -} diff --git a/pointycastle/lib/src/platform_check/web.dart b/pointycastle/lib/src/platform_check/web.dart deleted file mode 100644 index 59ef673..0000000 --- a/pointycastle/lib/src/platform_check/web.dart +++ /dev/null @@ -1,65 +0,0 @@ -@JS() -import 'dart:js_interop'; -import 'dart:math'; -import 'dart:typed_data'; - -import 'package:pointycastle/src/impl/entropy.dart'; - -import 'node_crypto.dart'; -import 'platform_check.dart'; - -class PlatformWeb extends Platform { - static final PlatformWeb instance = PlatformWeb(); - static bool useBuiltInRng = false; - - PlatformWeb() { - try { - Random.secure(); - useBuiltInRng = true; - } on UnsupportedError { - useBuiltInRng = false; - } - } - - @override - bool get isNative => false; - - @override - String get platform => 'web'; - - @override - EntropySource platformEntropySource() { - if (useBuiltInRng) { - return _JsBuiltInEntropySource(); - } else { - // - // Assume that if we cannot get a built in Secure RNG then we are - // probably on NodeJS. - // - return _JsNodeEntropySource(); - } - } -} - -// Uses the built in entropy source -class _JsBuiltInEntropySource implements EntropySource { - final _src = Random.secure(); - - @override - Uint8List getBytes(int len) { - return Uint8List.fromList( - List.generate(len, (i) => _src.nextInt(256))); - } -} - -/// -class _JsNodeEntropySource implements EntropySource { - @override - Uint8List getBytes(int len) { - var list = Uint8List(len); - NodeCrypto.randomFillSync(list.buffer.toJS); - return list; - } -} - -Platform getPlatform() => PlatformWeb.instance; diff --git a/pointycastle/lib/src/registration.dart b/pointycastle/lib/src/registration.dart deleted file mode 100644 index 827a889..0000000 --- a/pointycastle/lib/src/registration.dart +++ /dev/null @@ -1,44 +0,0 @@ -// See file LICENSE for more information. - -// -// -//TODO find out that these two methods are for! -//BlockCipher _cfbBlockCipherFactory(String algorithmName) { -// var parts = algorithmName.split("/"); -// -// if (parts.length != 2) return null; -// if (!parts[1].startsWith("CFB-")) return null; -// -// var blockSizeInBits = int.parse(parts[1].substring(4)); -// if ((blockSizeInBits % 8) != 0) { -// throw new ArgumentError("Bad CFB block size: $blockSizeInBits (must be a multiple of 8)"); -// } -// -// var underlyingCipher = _createOrNull(() => new BlockCipher(parts[0])); -// -// if (underlyingCipher != null) { -// return new CFBBlockCipher(underlyingCipher, blockSizeInBits ~/ 8); -// } -// -// return null; -//} -// -//BlockCipher _ofbBlockCipherFactory(String algorithmName) { -// var parts = algorithmName.split("/"); -// -// if (parts.length != 2) return null; -// if (!parts[1].startsWith("OFB-")) return null; -// -// var blockSizeInBits = int.parse(parts[1].substring(4)); -// if ((blockSizeInBits % 8) != 0) { -// throw new ArgumentError("Bad OFB block size: $blockSizeInBits (must be a multiple of 8)"); -// } -// -// var underlyingCipher = _createOrNull(() => new BlockCipher(parts[0])); -// -// if (underlyingCipher != null) { -// return new OFBBlockCipher(underlyingCipher, blockSizeInBits ~/ 8); -// } -// -// return null; -//} diff --git a/pointycastle/lib/src/registry/registration.dart b/pointycastle/lib/src/registry/registration.dart deleted file mode 100644 index 881be78..0000000 --- a/pointycastle/lib/src/registry/registration.dart +++ /dev/null @@ -1,171 +0,0 @@ -import 'package:pointycastle/export.dart'; -import 'package:pointycastle/key_derivators/concat_kdf.dart'; -import 'package:pointycastle/key_derivators/ecdh_kdf.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -void registerFactories(FactoryRegistry registry) { - _registerAsymmetricCiphers(registry); - _registerBlockCiphers(registry); - _registerDigests(registry); - _registerECCurves(registry); - _registerKeyDerivators(registry); - _registerKeyGenerators(registry); - _registerPbeParameterGenerators(registry); - _registerMacs(registry); - _registerPaddedBlockCiphers(registry); - _registerPaddings(registry); - _registerRandoms(registry); - _registerSigners(registry); - _registerStreamCiphers(registry); -} - -void _registerAsymmetricCiphers(FactoryRegistry registry) { - registry.register(OAEPEncoding.factoryConfig); - registry.register(PKCS1Encoding.factoryConfig); - registry.register(RSAEngine.factoryConfig); -} - -void _registerBlockCiphers(FactoryRegistry registry) { - registry.register(AESEngine.factoryConfig); - registry.register(RC2Engine.factoryConfig); - registry.register(DESedeEngine.factoryConfig); - // modes - registry.register(CBCBlockCipher.factoryConfig); - registry.register(CFBBlockCipher.factoryConfig); - registry.register(CTRBlockCipher.factoryConfig); - registry.register(ECBBlockCipher.factoryConfig); - registry.register(GCTRBlockCipher.factoryConfig); - registry.register(OFBBlockCipher.factoryConfig); - registry.register(SICBlockCipher.factoryConfig); - registry.register(GCMBlockCipher.factoryConfig); - registry.register(CCMBlockCipher.factoryConfig); - registry.register(IGEBlockCipher.factoryConfig); -} - -void _registerDigests(FactoryRegistry registry) { - registry.register(Blake2bDigest.factoryConfig); - registry.register(MD2Digest.factoryConfig); - registry.register(MD4Digest.factoryConfig); - registry.register(MD5Digest.factoryConfig); - registry.register(RIPEMD128Digest.factoryConfig); - registry.register(RIPEMD160Digest.factoryConfig); - registry.register(RIPEMD256Digest.factoryConfig); - registry.register(RIPEMD320Digest.factoryConfig); - registry.register(SHA1Digest.factoryConfig); - registry.register(SHA3Digest.factoryConfig); - registry.register(KeccakDigest.factoryConfig); - registry.register(SHA224Digest.factoryConfig); - registry.register(SHA256Digest.factoryConfig); - registry.register(SHA384Digest.factoryConfig); - registry.register(SHA512Digest.factoryConfig); - registry.register(SHA512tDigest.factoryConfig); - registry.register(TigerDigest.factoryConfig); - registry.register(WhirlpoolDigest.factoryConfig); - registry.register(SHAKEDigest.factoryConfig); - registry.register(CSHAKEDigest.factoryConfig); - registry.register(SM3Digest.factoryConfig); -} - -void _registerECCurves(FactoryRegistry registry) { - registry.register(ECCurve_brainpoolp160r1.factoryConfig); - registry.register(ECCurve_brainpoolp160t1.factoryConfig); - registry.register(ECCurve_brainpoolp192r1.factoryConfig); - registry.register(ECCurve_brainpoolp192t1.factoryConfig); - registry.register(ECCurve_brainpoolp224r1.factoryConfig); - registry.register(ECCurve_brainpoolp224t1.factoryConfig); - registry.register(ECCurve_brainpoolp256r1.factoryConfig); - registry.register(ECCurve_brainpoolp256t1.factoryConfig); - registry.register(ECCurve_brainpoolp320r1.factoryConfig); - registry.register(ECCurve_brainpoolp320t1.factoryConfig); - registry.register(ECCurve_brainpoolp384r1.factoryConfig); - registry.register(ECCurve_brainpoolp384t1.factoryConfig); - registry.register(ECCurve_brainpoolp512r1.factoryConfig); - registry.register(ECCurve_brainpoolp512t1.factoryConfig); - registry.register(ECCurve_gostr3410_2001_cryptopro_a.factoryConfig); - registry.register(ECCurve_gostr3410_2001_cryptopro_b.factoryConfig); - registry.register(ECCurve_gostr3410_2001_cryptopro_c.factoryConfig); - registry.register(ECCurve_gostr3410_2001_cryptopro_xcha.factoryConfig); - registry.register(ECCurve_gostr3410_2001_cryptopro_xchb.factoryConfig); - registry.register(ECCurve_prime192v1.factoryConfig); - registry.register(ECCurve_prime192v2.factoryConfig); - registry.register(ECCurve_prime192v3.factoryConfig); - registry.register(ECCurve_prime239v1.factoryConfig); - registry.register(ECCurve_prime239v2.factoryConfig); - registry.register(ECCurve_prime239v3.factoryConfig); - registry.register(ECCurve_prime256v1.factoryConfig); - registry.register(ECCurve_secp112r1.factoryConfig); - registry.register(ECCurve_secp112r2.factoryConfig); - registry.register(ECCurve_secp128r1.factoryConfig); - registry.register(ECCurve_secp128r2.factoryConfig); - registry.register(ECCurve_secp160k1.factoryConfig); - registry.register(ECCurve_secp160r1.factoryConfig); - registry.register(ECCurve_secp160r2.factoryConfig); - registry.register(ECCurve_secp192k1.factoryConfig); - registry.register(ECCurve_secp192r1.factoryConfig); - registry.register(ECCurve_secp224k1.factoryConfig); - registry.register(ECCurve_secp224r1.factoryConfig); - registry.register(ECCurve_secp256k1.factoryConfig); - registry.register(ECCurve_secp256r1.factoryConfig); - registry.register(ECCurve_secp384r1.factoryConfig); - registry.register(ECCurve_secp521r1.factoryConfig); -} - -void _registerKeyDerivators(FactoryRegistry registry) { - registry.register(PBKDF2KeyDerivator.factoryConfig); - registry.register(Scrypt.factoryConfig); - registry.register(HKDFKeyDerivator.factoryConfig); - registry.register(Argon2BytesGenerator.factoryConfig); - registry.register(ConcatKDFDerivator.factoryConfig); - registry.register(ECDHKeyDerivator.factoryConfig); - registry.register(ECDHKeyDerivator.factoryConfig); - registry.register(ECDHKeyDerivator.factoryConfig); -} - -void _registerKeyGenerators(FactoryRegistry registry) { - registry.register(ECKeyGenerator.factoryConfig); - registry.register(RSAKeyGenerator.factoryConfig); -} - -void _registerPbeParameterGenerators(FactoryRegistry registry) { - registry.register(PKCS12ParametersGenerator.factoryConfig); - registry.register(PKCS5S1ParameterGenerator.factoryConfig); -} - -void _registerMacs(FactoryRegistry registry) { - registry.register(HMac.factoryConfig); - registry.register(CMac.factoryConfig); - registry.register(CBCBlockCipherMac.factoryConfig); - registry.register(Poly1305.factoryConfig); -} - -void _registerPaddedBlockCiphers(FactoryRegistry registry) { - registry.register(PaddedBlockCipherImpl.factoryConfig); -} - -void _registerPaddings(FactoryRegistry registry) { - registry.register(PKCS7Padding.factoryConfig); - registry.register(ISO7816d4Padding.factoryConfig); -} - -void _registerRandoms(FactoryRegistry registry) { - registry.register(AutoSeedBlockCtrRandom.factoryConfig); - registry.register(BlockCtrRandom.factoryConfig); - registry.register(FortunaRandom.factoryConfig); -} - -void _registerSigners(FactoryRegistry registry) { - registry.register(ECDSASigner.factoryConfig); - registry.register(PSSSigner.factoryConfig); - registry.register(RSASigner.factoryConfig); -} - -void _registerStreamCiphers(FactoryRegistry registry) { - registry.register(CTRStreamCipher.factoryConfig); - registry.register(Salsa20Engine.factoryConfig); - registry.register(ChaCha20Engine.factoryConfig); - registry.register(ChaCha7539Engine.factoryConfig); - registry.register(ChaCha20Poly1305.factoryConfig); - registry.register(SICStreamCipher.factoryConfig); - registry.register(EAX.factoryConfig); - registry.register(RC4Engine.factoryConfig); -} diff --git a/pointycastle/lib/src/registry/registry.dart b/pointycastle/lib/src/registry/registry.dart deleted file mode 100644 index a168d0e..0000000 --- a/pointycastle/lib/src/registry/registry.dart +++ /dev/null @@ -1,165 +0,0 @@ -// See file LICENSE for more information. - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/registry/registration.dart'; - -final FactoryRegistry registry = _RegistryImpl(); - -abstract class FactoryRegistry { - T create(String registrableName); - - void register(FactoryConfig config); -} - -typedef /*Registrable*/ RegistrableConstructor = Function(); -typedef DynamicConstructorFactory = RegistrableConstructor Function( - String registrableName, Match match); - -abstract class FactoryConfig { - final Type type; - - FactoryConfig(this.type); -} - -class StaticFactoryConfig extends FactoryConfig { - final String algorithmName; - final RegistrableConstructor factory; - - StaticFactoryConfig(super.type, this.algorithmName, this.factory); -} - -// From the PatternCharacter rule here: -// http://ecma-international.org/ecma-262/5.1/#sec-15.10 -final _specialRegExpChars = RegExp(r'([\\\^\$\.\|\+\[\]\(\)\{\}])'); - -/// Escapes special regular expression characters in [str] so that it can be -/// used as a literal match inside of a [RegExp]. -/// -/// The special characters are: \ ^ $ . | + [ ] ( ) { } -/// as defined here: http://ecma-international.org/ecma-262/5.1/#sec-15.10 -String _escapeRegExp(String str) => str.splitMapJoin(_specialRegExpChars, - onMatch: (Match m) => '\\${m.group(0)}', onNonMatch: (s) => s); - -class DynamicFactoryConfig extends FactoryConfig { - final RegExp regExp; - final DynamicConstructorFactory factory; - - DynamicFactoryConfig(super.type, this.regExp, this.factory); - - DynamicFactoryConfig.regex( - Type type, String regexString, DynamicConstructorFactory factory) - : this(type, RegExp(regexString), factory); - - /// A dynamic registry that matches by prefix. - /// The part after the prefix will be in `match.group(1)`. - DynamicFactoryConfig.prefix( - Type type, String prefix, DynamicConstructorFactory factory) - : this.regex(type, '^${_escapeRegExp(prefix)}(.+)\$', factory); - - /// A dynamic registry that matches by suffix. - /// The part before the suffix will be in `match.group(1)`. - DynamicFactoryConfig.suffix( - Type type, String suffix, DynamicConstructorFactory factory) - : this.regex(type, '^(.+)${_escapeRegExp(suffix)}\$', factory); - - /// Invokes the factory when it matches. Else returns null. - RegistrableConstructor? tryFactory(String algorithmName) { - Match? match = regExp.firstMatch(algorithmName); - if (match == null) { - return null; - } - return factory(algorithmName, match); - } -} - -class _RegistryImpl implements FactoryRegistry { - static const int _CONSTRUCTOR_CACHE_SIZE = 25; - - final Map> _staticFactories; - final Map> _dynamicFactories; - - final Map _constructorCache = - {}; - - bool _initialized = false; - - _RegistryImpl() - : _staticFactories = >{}, - _dynamicFactories = >{}; - - @override - T create(String registrableName) { - var type = T; - var constructor = getConstructor(type, registrableName); - var result = constructor() as T; - return result; - } - - RegistrableConstructor getConstructor(Type type, String registrableName) { - var constructor = _constructorCache['$type.$registrableName']; - - if (constructor == null) { - constructor = _createConstructor(type, registrableName); - if (_constructorCache.length > _CONSTRUCTOR_CACHE_SIZE) { - _constructorCache.clear(); - } - _constructorCache['$type.$registrableName'] = constructor!; - } - return constructor; - } - - RegistrableConstructor? _createConstructor( - Type type, String registrableName) { - // Init lazily - _checkInit(); - - if (_staticFactories.containsKey(type) && - _staticFactories[type]!.containsKey(registrableName)) { - return _staticFactories[type]![registrableName]; - } - - if (_dynamicFactories.containsKey(type)) { - for (var factory in _dynamicFactories[type]!) { - var constructor = factory.tryFactory(registrableName); - if (constructor != null) { - return constructor; - } - } - } - - // No factory found - throw RegistryFactoryException.unknown(registrableName, type); - } - - void _checkInit() { - if (!_initialized) { - _initialize(); - } - } - - @override - void register(FactoryConfig config) { - if (config is StaticFactoryConfig) { - _addStaticFactoryConfig(config); - } else if (config is DynamicFactoryConfig) { - _addDynamicFactoryConfig(config); - } - } - - void _addStaticFactoryConfig(StaticFactoryConfig config) { - Map factories = _staticFactories.putIfAbsent( - config.type, () => {}); - factories[config.algorithmName] = config.factory; - } - - void _addDynamicFactoryConfig(DynamicFactoryConfig config) { - Set factories = _dynamicFactories.putIfAbsent( - config.type, () => {}); - factories.add(config); - } - - void _initialize() { - registerFactories(this); - _initialized = true; - } -} diff --git a/pointycastle/lib/src/ufixnum.dart b/pointycastle/lib/src/ufixnum.dart deleted file mode 100644 index 1b63b9c..0000000 --- a/pointycastle/lib/src/ufixnum.dart +++ /dev/null @@ -1,562 +0,0 @@ -// See file LICENSE for more information. - -import 'dart:typed_data'; - -const _MASK_3 = 0x07; -const _MASK_5 = 0x1F; -const _MASK_6 = 0x3F; -const _MASK_8 = 0xFF; -const _MASK_16 = 0xFFFF; -const _MASK_32 = 0xFFFFFFFF; - -// ignore: non_constant_identifier_names -final _MASK32_HI_BITS = [ - 0xFFFFFFFF, - 0x7FFFFFFF, - 0x3FFFFFFF, - 0x1FFFFFFF, - 0x0FFFFFFF, - 0x07FFFFFF, - 0x03FFFFFF, - 0x01FFFFFF, - 0x00FFFFFF, - 0x007FFFFF, - 0x003FFFFF, - 0x001FFFFF, - 0x000FFFFF, - 0x0007FFFF, - 0x0003FFFF, - 0x0001FFFF, - 0x0000FFFF, - 0x00007FFF, - 0x00003FFF, - 0x00001FFF, - 0x00000FFF, - 0x000007FF, - 0x000003FF, - 0x000001FF, - 0x000000FF, - 0x0000007F, - 0x0000003F, - 0x0000001F, - 0x0000000F, - 0x00000007, - 0x00000003, - 0x00000001, - 0x00000000 -]; - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// 8 bit operations -// -int clip8(int x) => x & _MASK_8; - -int csum8(int x, int y) => sum8(clip8(x), clip8(y)); -int sum8(int x, int y) { - assert((x >= 0) && (x <= _MASK_8)); - assert((y >= 0) && (y <= _MASK_8)); - return (x + y) & _MASK_8; -} - -int csub8(int x, int y) => sub8(clip8(x), clip8(y)); -int sub8(int x, int y) { - assert((x >= 0) && (x <= _MASK_8)); - assert((y >= 0) && (y <= _MASK_8)); - return (x - y) & _MASK_8; -} - -int cshiftl8(int x, int n) => shiftl8(clip8(x), n); -int shiftl8(int x, int n) { - assert((x >= 0) && (x <= _MASK_8)); - return (x << (n & _MASK_3)) & _MASK_8; -} - -int cshiftr8(int x, int n) => shiftr8(clip8(x), n); -int shiftr8(int x, int n) { - assert((x >= 0) && (x <= _MASK_8)); - return x >> (n & _MASK_3); -} - -int cneg8(int x) => neg8(clip8(x)); -int neg8(int x) { - assert((x >= 0) && (x <= _MASK_8)); - return -x & _MASK_8; -} - -int cnot8(int x) => not8(clip8(x)); -int not8(int x) { - assert((x >= 0) && (x <= _MASK_8)); - return ~x & _MASK_8; -} - -int crotl8(int x, int n) => rotl8(clip8(x), n); -int rotl8(int x, int n) { - assert(n >= 0); - assert((x >= 0) && (x <= _MASK_8)); - n &= _MASK_3; - return ((x << n) & _MASK_8) | (x >> (8 - n)); -} - -int crotr8(int x, int n) => rotr8(clip8(x), n); -int rotr8(int x, int n) { - assert(n >= 0); - assert((x >= 0) && (x <= _MASK_8)); - n &= _MASK_3; - return ((x >> n) & _MASK_8) | ((x << (8 - n)) & _MASK_8); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// 16 bit operations -// -int clip16(int x) => x & _MASK_16; - -/// Packs a 16 bit integer into a byte buffer. The [out] parameter can be an [Uint8List] or a -/// [ByteData] if you will run it several times against the same buffer and want faster execution. -void pack16(int x, dynamic out, int offset, Endian endian) { - assert((x >= 0) && (x <= _MASK_16)); - if (out is! ByteData) { - out = ByteData.view(out.buffer, out.offsetInBytes, out.length); - } - out.setUint16(offset, x, endian); -} - -/// Unpacks a 16 bit integer from a byte buffer. The [inp] parameter can be an [Uint8List] or a -/// [ByteData] if you will run it several times against the same buffer and want faster execution. -int unpack16(dynamic inp, int offset, Endian endian) { - if (inp is! ByteData) { - inp = ByteData.view( - inp.buffer as ByteBuffer, inp.offsetInBytes as int, inp.length as int?); - } - return inp.getUint16(offset, endian); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// 32 bit operations -// -int clip32(int x) => x & _MASK_32; - -int csum32(int x, int y) => sum32(clip32(x), clip32(y)); -int sum32(int x, int y) { - assert((x >= 0) && (x <= _MASK_32)); - assert((y >= 0) && (y <= _MASK_32)); - return (x + y) & _MASK_32; -} - -int csub32(int x, int y) => sub32(clip32(x), clip32(y)); -int sub32(int x, int y) { - assert((x >= 0) && (x <= _MASK_32)); - assert((y >= 0) && (y <= _MASK_32)); - return (x - y) & _MASK_32; -} - -int cshiftl32(int x, int n) => shiftl32(clip32(x), n); -int shiftl32(int x, int n) { - assert((x >= 0) && (x <= _MASK_32)); - n &= _MASK_5; - x &= _MASK32_HI_BITS[n]; - return (x << n) & _MASK_32; -} - -int cshiftr32(int x, int n) => shiftr32(clip32(x), n); -int shiftr32(int x, int n) { - assert((x >= 0) && (x <= _MASK_32)); - n &= _MASK_5; - return x >> n; -} - -int cneg32(int x) => neg32(clip32(x)); -int neg32(int x) { - assert((x >= 0) && (x <= _MASK_32)); - return -x & _MASK_32; -} - -int cnot32(int x) => not32(clip32(x)); -int not32(int x) { - assert((x >= 0) && (x <= _MASK_32)); - return ~x & _MASK_32; -} - -int crotl32(int x, int n) => rotl32(clip32(x), n); -int rotl32(int x, int n) { - assert(n >= 0); - assert((x >= 0) && (x <= _MASK_32)); - n &= _MASK_5; - return shiftl32(x, n) | (x >> (32 - n)); -} - -int crotr32(int x, int n) => rotr32(clip32(x), n); -int rotr32(int x, int n) { - assert(n >= 0); - assert((x >= 0) && (x <= _MASK_32)); - n &= _MASK_5; - return (x >> n) | shiftl32(x, 32 - n); -} - -/// Packs a 32 bit integer into a byte buffer. The [out] parameter can be an [Uint8List] or a -/// [ByteData] if you will run it several times against the same buffer and want faster execution. -void pack32(int x, dynamic out, int offset, Endian endian) { - assert((x >= 0) && (x <= _MASK_32)); - if (out is! ByteData) { - out = - ByteData.view(out.buffer as ByteBuffer, out.offsetInBytes, out.length); - } - out.setUint32(offset, x, endian); -} - -/// Unpacks a 32 bit integer from a byte buffer. The [inp] parameter can be an [Uint8List] or a -/// [ByteData] if you will run it several times against the same buffer and want faster execution. -int unpack32(dynamic inp, int offset, Endian endian) { - if (inp is! ByteData) { - inp = ByteData.view(inp.buffer, inp.offsetInBytes, inp.length); - } - return inp.getUint32(offset, endian); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// 64 bit operations -// -class Register64 { - late int _hi32; - late int _lo32; - - Register64([Object hiOrLo32OrY = 0, int? lo32]) { - set(hiOrLo32OrY, lo32); - } - - int get lo32 => _lo32; - int get hi32 => _hi32; - - @override - bool operator ==(Object other) => other is Register64 - ? (((_hi32 == other._hi32) && (_lo32 == other._lo32))) - : false; - bool operator <(Register64 y) => - (_hi32 < y._hi32) || ((_hi32 == y._hi32) && (_lo32 < y._lo32)); - bool operator <=(Register64 y) => (this < y) || (this == y); - bool operator >(Register64 y) => - (_hi32 > y._hi32) || ((_hi32 == y._hi32) && (_lo32 > y._lo32)); - bool operator >=(Register64 y) => (this > y) || (this == y); - - void set(dynamic hiOrLo32OrY, [int? lo32]) { - if (lo32 == null) { - if (hiOrLo32OrY is Register64) { - _hi32 = hiOrLo32OrY._hi32; - _lo32 = hiOrLo32OrY._lo32; - } else { - assert(hiOrLo32OrY as int <= _MASK_32); - _hi32 = 0; - _lo32 = hiOrLo32OrY as int; - } - } else { - assert(hiOrLo32OrY as int <= _MASK_32); - assert(lo32 <= _MASK_32); - _hi32 = hiOrLo32OrY as int; - _lo32 = lo32; - } - } - - void sum(dynamic y) { - if (y is int) { - y &= _MASK_32; - var slo32 = _lo32 + y; - _lo32 = slo32 & _MASK_32; - if (slo32 != _lo32) { - _hi32++; - _hi32 &= _MASK_32; - } - } else { - var slo32 = _lo32 + y._lo32 as int; - _lo32 = slo32 & _MASK_32; - var carry = ((slo32 != _lo32) ? 1 : 0); - _hi32 = ((_hi32 + y._hi32 + carry) as int) & _MASK_32; - } - } - - void sumReg(Register64 y) { - var slo32 = _lo32 + y._lo32; - _lo32 = slo32 & _MASK_32; - var carry = ((slo32 != _lo32) ? 1 : 0); - _hi32 = (_hi32 + y._hi32 + carry) & _MASK_32; - } - - void sub(dynamic y) { - // TODO: optimize sub() ??? - sum(Register64(y)..neg()); - } - - void mul(dynamic y) { - // Grab 16-bit chunks. - final a0 = _lo32 & _MASK_16; - final a1 = (_lo32 >> 16) & _MASK_16; - final a2 = _hi32 & _MASK_16; - final a3 = (_hi32 >> 16) & _MASK_16; - late int b0, b1, b2, b3; - if (y is int) { - // Assume it is a 32-bit integer. - y &= _MASK_32; - b0 = y & _MASK_16; - b1 = (y >> 16) & _MASK_16; - b2 = b3 = 0; - } else /* if (y is Register64) */ { - b0 = (y as Register64)._lo32 & _MASK_16; - b1 = (y._lo32 >> 16) & _MASK_16; - b2 = y._hi32 & _MASK_16; - b3 = (y._hi32 >> 16) & _MASK_16; - } - - // Compute partial products. - // Optimization: if b is small, avoid multiplying by parts that are 0. - var p0 = a0 * b0; // << 0 - var p1 = a1 * b0; // << 16 - var p2 = a2 * b0; // << 32 - var p3 = a3 * b0; // << 48 - - if (b1 != 0) { - p1 += a0 * b1; - p2 += a1 * b1; - p3 += a2 * b1; - } - if (b2 != 0) { - p2 += a0 * b2; - p3 += a1 * b2; - } - if (b3 != 0) { - p3 += a0 * b3; - } - - // Accumulate into 32-bit chunks: - // |................................|................................| - // |................................|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx| p0 - // |................................|................................| - // |................................|................................| - // |................xxxxxxxxxxxxxxxx|xxxxxxxxxxxxxxxx................| p1 - // |................................|................................| - // |................................|................................| - // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|................................| p2 - // |................................|................................| - // |................................|................................| - // |xxxxxxxxxxxxxxxx................|................................| p3 - var slo32 = p0 + ((p1 & _MASK_16) << 16); - _lo32 = slo32 & _MASK_32; - var carry = ((slo32 != _lo32) ? 1 : 0); - // p1 is a 33-bit integer, shiftr operation will ignore 33th-bit on js - var carry2 = ((p1 & _MASK_32) != p1) ? 0x10000 : 0; - var shi32 = - ((p1 & _MASK_32) >> 16) + p2 + ((p3 & _MASK_16) << 16) + carry + carry2; - _hi32 = shi32 & _MASK_32; - } - - void neg() { - not(); - sum(1); - } - - void not() { - _hi32 = ~_hi32 & _MASK_32; - _lo32 = ~_lo32 & _MASK_32; - } - - void and(Register64 y) { - _hi32 &= y._hi32; - _lo32 &= y._lo32; - } - - void or(Register64 y) { - _hi32 |= y._hi32; - _lo32 |= y._lo32; - } - - void xor(Register64 y) { - _hi32 ^= y._hi32; - _lo32 ^= y._lo32; - } - - void shiftl(int n) { - n &= _MASK_6; - if (n == 0) { - // do nothing - } else if (n >= 32) { - _hi32 = shiftl32(_lo32, n - 32); - _lo32 = 0; - } else { - _hi32 = shiftl32(_hi32, n); - _hi32 |= _lo32 >> (32 - n); - _lo32 = shiftl32(_lo32, n); - } - } - - void shiftr(int n) { - n &= _MASK_6; - if (n == 0) { - // do nothing - } else if (n >= 32) { - _lo32 = _hi32 >> (n - 32); - _hi32 = 0; - } else { - _lo32 = _lo32 >> n; - _lo32 |= shiftl32(_hi32, 32 - n); - _hi32 = _hi32 >> n; - } - } - - void rotl(int n) { - n &= _MASK_6; - if (n == 0) { - // do nothing - } else { - if (n >= 32) { - var swap = _hi32; - _hi32 = _lo32; - _lo32 = swap; - n -= 32; - } - if (n == 0) { - // do nothing - } else { - var hi32 = _hi32; - _hi32 = shiftl32(_hi32, n); - _hi32 |= _lo32 >> (32 - n); - _lo32 = shiftl32(_lo32, n); - _lo32 |= hi32 >> (32 - n); - } - } - } - - void rotr(int n) { - n &= _MASK_6; - if (n == 0) { - // do nothing - } else { - if (n >= 32) { - var swap = _hi32; - _hi32 = _lo32; - _lo32 = swap; - n -= 32; - } - if (n == 0) { - // do nothing - } else { - var hi32 = _hi32; - _hi32 = _hi32 >> n; - _hi32 |= shiftl32(_lo32, 32 - n); - _lo32 = _lo32 >> n; - _lo32 |= shiftl32(hi32, 32 - n); - } - } - } - - void mod(int n) { - if (_hi32 == 0) { - // hi32 is zero, so just caculate lo32. - _lo32 %= n; - } else { - // hi32 is not zero, use Horner's Method - const b = 0x10000; - final a0 = _lo32 & _MASK_16; - final a1 = (_lo32 >> 16) & _MASK_16; - final a2 = _hi32 & _MASK_16; - final a3 = (_hi32 >> 16) & _MASK_16; - _lo32 = ((((((a3 % n) * b + a2) % n) * b + a1) % n) * b + a0) % n; - // Assume that n is a 32-bit integer, so hi32 will always be zero - _hi32 = 0; - } - } - - /// Packs a 64 bit integer into a byte buffer. The [out] parameter can be an [Uint8List] or a - /// [ByteData] if you will run it several times against the same buffer and want faster execution. - void pack(dynamic out, int offset, Endian endian) { - switch (endian) { - case Endian.big: - pack32(hi32, out, offset, endian); - pack32(lo32, out, offset + 4, endian); - break; - - case Endian.little: - pack32(hi32, out, offset + 4, endian); - pack32(lo32, out, offset, endian); - break; - - default: - throw UnsupportedError('Invalid endianness: $endian'); - } - } - - /// Unpacks a 64 bit integer from a byte buffer. The [inp] parameter can be an [Uint8List] or a - /// [ByteData] if you will run it several times against the same buffer and want faster execution. - void unpack(dynamic inp, int offset, Endian endian) { - switch (endian) { - case Endian.big: - _hi32 = unpack32(inp, offset, endian); - _lo32 = unpack32(inp, offset + 4, endian); - break; - - case Endian.little: - _hi32 = unpack32(inp, offset + 4, endian); - _lo32 = unpack32(inp, offset, endian); - break; - - default: - throw UnsupportedError('Invalid endianness: $endian'); - } - } - - @override - String toString() { - var sb = StringBuffer(); - _padWrite(sb, _hi32); - _padWrite(sb, _lo32); - return sb.toString(); - } - - void _padWrite(StringBuffer sb, int value) { - var str = value.toRadixString(16); - for (var i = 8 - str.length; i > 0; i--) { - sb.write('0'); - } - sb.write(str); - } - - @override - int get hashCode => Object.hash(_hi32, _lo32); -} - -class Register64List { - final List _list; - - Register64List.from(List> values) - : _list = List.generate( - values.length, (i) => Register64(values[i][0], values[i][1])); - - Register64List(int length) - : _list = List.generate(length, (_) => Register64()); - - int get length => _list.length; - - Register64 operator [](int index) => _list[index]; - - void fillRange(int start, int end, dynamic hiOrLo32OrY, [int? lo32]) { - for (var i = start; i < end; i++) { - _list[i].set(hiOrLo32OrY, lo32); - } - } - - void setRange(int start, int end, Register64List list, [int skipCount = 0]) { - var length = end - start; - for (var i = 0; i < length; i++) { - _list[start + i].set(list[skipCount + i]); - } - } - - @override - String toString() { - var sb = StringBuffer('('); - for (var i = 0; i < _list.length; i++) { - if (i > 0) { - sb.write(', '); - } - sb.write(_list[i].toString()); - } - sb.write(')'); - return sb.toString(); - } -} diff --git a/pointycastle/lib/src/utils.dart b/pointycastle/lib/src/utils.dart deleted file mode 100644 index 0ba221d..0000000 --- a/pointycastle/lib/src/utils.dart +++ /dev/null @@ -1,336 +0,0 @@ -// See file LICENSE for more information. - -import 'dart:typed_data'; - -import 'package:pointycastle/src/platform_check/platform_check.dart'; - -void arrayCopy(Uint8List? sourceArr, int sourcePos, Uint8List? outArr, - int outPos, int len) { - for (var i = 0; i < len; i++) { - outArr![outPos + i] = sourceArr![sourcePos + i]; - } -} - -/// -///A constant time equals comparison - does not terminate early if -///test will fail. For best results always pass the expected value -///as the first parameter. -/// -/// @param expected first array -/// @param supplied second array -/// @return true if arrays equal, false otherwise. -/// -bool constantTimeAreEqual(Uint8List expected, Uint8List supplied) { - if (expected == supplied) { - return true; - } - - var len = - (expected.length < supplied.length) ? expected.length : supplied.length; - - var nonEqual = expected.length ^ supplied.length; - - for (var i = 0; i != len; i++) { - nonEqual |= expected[i] ^ supplied[i]; - } - for (var i = len; i < supplied.length; i++) { - nonEqual |= supplied[i] ^ ~supplied[i]; - } - - return nonEqual == 0; -} - -Uint8List concatUint8List(Iterable list) => - Uint8List.fromList(list.expand((element) => element).toList()); - -/// Decode a BigInt from bytes in big-endian encoding. -/// Twos compliment. -BigInt decodeBigInt(List bytes) { - var negative = bytes.isNotEmpty && bytes[0] & 0x80 == 0x80; - - BigInt result; - - if (bytes.length == 1) { - result = BigInt.from(bytes[0]); - } else { - result = BigInt.zero; - for (var i = 0; i < bytes.length; i++) { - var item = bytes[bytes.length - i - 1]; - result |= BigInt.from(item) << (8 * i); - } - } - return result != BigInt.zero - ? negative - ? result.toSigned(result.bitLength) - : result - : BigInt.zero; -} - -/// Decode a big integer with arbitrary sign. -/// When: -/// sign == 0: Zero regardless of magnitude -/// sign < 0: Negative -/// sign > 0: Positive -BigInt decodeBigIntWithSign(int sign, List magnitude) { - if (sign == 0) { - return BigInt.zero; - } - - BigInt result; - - if (magnitude.length == 1) { - result = BigInt.from(magnitude[0]); - } else { - result = BigInt.from(0); - for (var i = 0; i < magnitude.length; i++) { - var item = magnitude[magnitude.length - i - 1]; - result |= BigInt.from(item) << (8 * i); - } - } - - if (result != BigInt.zero) { - if (sign < 0) { - result = result.toSigned(result.bitLength); - } else { - result = result.toUnsigned(result.bitLength); - } - } - return result; -} - -var _byteMask = BigInt.from(0xff); -final negativeFlag = BigInt.from(0x80); - -/// Encode a BigInt into bytes using big-endian encoding. -/// It encodes the integer to a minimal twos-compliment integer as defined by -/// ASN.1 -Uint8List encodeBigInt(BigInt? number) { - if (number == BigInt.zero) { - return Uint8List.fromList([0]); - } - - int needsPaddingByte; - int rawSize; - - if (number! > BigInt.zero) { - rawSize = (number.bitLength + 7) >> 3; - needsPaddingByte = - ((number >> (rawSize - 1) * 8) & negativeFlag) == negativeFlag ? 1 : 0; - } else { - needsPaddingByte = 0; - rawSize = (number.bitLength + 8) >> 3; - } - - final size = rawSize + needsPaddingByte; - var result = Uint8List(size); - for (var i = 0; i < rawSize; i++) { - result[size - i - 1] = (number! & _byteMask).toInt(); - number = number >> 8; - } - return result; -} - -/// Encode as Big Endian unsigned byte array. -Uint8List encodeBigIntAsUnsigned(BigInt number) { - if (number == BigInt.zero) { - return Uint8List.fromList([0]); - } - var size = number.bitLength + (number.isNegative ? 8 : 7) >> 3; - var result = Uint8List(size); - for (var i = 0; i < size; i++) { - result[size - i - 1] = (number & _byteMask).toInt(); - number = number >> 8; - } - return result; -} - -bool constantTimeAreEqualOffset( - int len, Uint8List a, int aOff, Uint8List b, int bOff) { - if (len < 0) { - throw ArgumentError('"len" cannot be negative'); - } - if (aOff > (a.length - len)) { - throw ArgumentError('"aOff" value invalid for specified length'); - } - if (bOff > (b.length - len)) { - throw ArgumentError('"bOff" value invalid for specified length'); - } - - var d = 0; - for (var i = 0; i < len; ++i) { - d |= a[aOff + i] ^ b[bOff + i]; - } - return 0 == d; -} - -abstract class Pack { - static int littleEndianToLong(Uint8List bs, int off) { - var data = ByteData.view(bs.buffer); - return data.getInt64(off, Endian.little); - } - - static void littleEndianToLongAtList(Uint8List bs, int off, Uint64List ns) { - for (var i = 0; i < ns.length; ++i) { - ns[i] = littleEndianToLong(bs, off); - off += 8; - } - } - - static void littleEndianToInt32AtList(Uint8List bs, int off, Uint32List ns) { - for (var i = 0; i < ns.length; ++i) { - ns[i] = littleEndianToInt(bs, off); - off += 4; - } - } - - static void intToLittleEndian(int n, Uint8List bs, int off) { - var data = ByteData.view(bs.buffer); - data.setInt32(off, n, Endian.little); - } - - static Uint8List longToLittleEndianList(int n) { - var bs = Uint8List(8); - longToLittleEndianAtList(n, bs, 0); - return bs; - } - - static void longToLittleEndianAtList(int n, Uint8List bs, int off) { - var data = ByteData.view(bs.buffer); - data.setInt64(off, n, Endian.little); - } - - static Uint8List longListToLittleEndianList(Uint64List ns) { - var bs = Uint8List(8 * ns.length); - longListToLittleEndianAtList(ns, bs, 0); - return bs; - } - - static void longListToLittleEndianAtList( - Uint64List ns, Uint8List bs, int off) { - for (var i = 0; i < ns.length; ++i) { - longToLittleEndianAtList(ns[i], bs, off); - off += 8; - } - } - - static int littleEndianToInt(Uint8List bs, int off) { - var data = ByteData.view(bs.buffer); - return data.getInt32(off, Endian.little); - } - - static Uint8List intToLittleEndianList(int n) { - var bs = Uint8List(4); - intToLittleEndianAtList(n, bs, 0); - return bs; - } - - static void intToLittleEndianAtList(int n, Uint8List bs, int off) { - var data = ByteData.view(bs.buffer); - data.setInt32(off, n, Endian.little); - } - - static Uint8List intListToLittleEndian(Uint32List ns) { - var bs = Uint8List(4 * ns.length); - intListToLittleEndianAtList(ns, bs, 0); - return bs; - } - - static void intListToLittleEndianAtList( - Uint32List ns, Uint8List bs, int off) { - for (var i = 0; i < ns.length; ++i) { - intToLittleEndianAtList(ns[i], bs, off); - off += 4; - } - } -} - -abstract class Longs { - static const _MASK_32 = 0xFFFFFFFF; - - static const _MASK32_HI_BITS = [ - 0xFFFFFFFF, - 0x7FFFFFFF, - 0x3FFFFFFF, - 0x1FFFFFFF, - 0x0FFFFFFF, - 0x07FFFFFF, - 0x03FFFFFF, - 0x01FFFFFF, - 0x00FFFFFF, - 0x007FFFFF, - 0x003FFFFF, - 0x001FFFFF, - 0x000FFFFF, - 0x0007FFFF, - 0x0003FFFF, - 0x0001FFFF, - 0x0000FFFF, - 0x00007FFF, - 0x00003FFF, - 0x00001FFF, - 0x00000FFF, - 0x000007FF, - 0x000003FF, - 0x000001FF, - 0x000000FF, - 0x0000007F, - 0x0000003F, - 0x0000001F, - 0x0000000F, - 0x00000007, - 0x00000003, - 0x00000001, - 0x00000000 - ]; - - static int rotateRight(int n, int distance) { - if (distance == 0) { - // do nothing: - return n; - } - - var hi32 = (n >> 32) & 0xFFFFFFFF; - var lo32 = n & 0xFFFFFFFF; - - if (distance >= 32) { - var swap = hi32; - hi32 = lo32; - lo32 = swap; - distance -= 32; - - if (distance == 0) { - return (hi32 << 32) | lo32; - } - } - - final distance32 = 32 - distance; - final m = _MASK32_HI_BITS[distance32]; - - final hi32cp = hi32; - - hi32 = hi32 >> distance; - hi32 |= ((lo32 & m) << distance32) & _MASK_32; - - lo32 = lo32 >> distance; - lo32 |= ((hi32cp & m) << distance32) & _MASK_32; - - return (hi32 << 32) | lo32; - } - - static int toInt32(int n) => n & 0xFFFFFFFF; -} - -const mask64 = (0xFFFFFFFF << 32) + 0xFFFFFFFF; - -int unsignedShiftRight64(int n, int count) { - if (Platform.instance.isNative) { - return (n >> count) & ~(-1 << (64 - count)); - } else { - count &= 0x1f; - if (n >= 0) { - return n >> count; - } else { - return (n >> count) ^ (mask64 ^ ((1 << (64 - count)) - 1)); - } - } -} diff --git a/pointycastle/lib/srp/srp6_client.dart b/pointycastle/lib/srp/srp6_client.dart deleted file mode 100644 index 4ed9dc7..0000000 --- a/pointycastle/lib/srp/srp6_client.dart +++ /dev/null @@ -1,104 +0,0 @@ -library impl.srp_client; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/srp/srp6_standard_groups.dart'; -import 'package:pointycastle/srp/srp6_util.dart'; - -class SRP6Client implements SRPClient { - late BigInt N; - late BigInt g; - - BigInt? a; - BigInt? A; - - BigInt? B; - - BigInt? x; - BigInt? u; - BigInt? S; - - BigInt? M1; - BigInt? M2; - BigInt? Key; - - Digest digest; - SecureRandom random; - SRP6GroupParameters group; - - SRP6Client( - {required this.group, required this.digest, required this.random}) { - g = group.g; - N = group.N; - } - - @override - BigInt? calculateClientEvidenceMessage() { - // Verify pre-requirements - if (A == null || B == null || S == null) { - throw Exception( - 'Impossible to compute M1: some data are missing from the previous operations (A,B,S)'); - } - // compute the client evidence message 'M1' - M1 = SRP6Util.calculateM1(digest, N, A, B, S); - return M1; - } - - ///S = (B - kg^x) ^ (a + ux) - BigInt? calculateS() { - var k = SRP6Util.calculateK(digest, N, g); - var exp = (u! * x!) + a!; - var tmp = g.modPow(x!, N) * (k % N); - - return (B! - (tmp % N)).modPow(exp, N); - } - - @override - BigInt? calculateSecret(BigInt serverB) { - B = SRP6Util.validatePublicValue(N, serverB); - u = SRP6Util.calculateU(digest, N, A, B); - S = calculateS(); - return S; - } - - @override - BigInt? calculateSessionKey() { - // Verify pre-requirements (here we enforce a previous calculation of M1 and M2) - if (S == null || M1 == null || M2 == null) { - throw Exception( - 'Impossible to compute Key: some data are missing from the previous operations (S,M1,M2)'); - } - Key = SRP6Util.calculateKey(digest, N, S!); - return Key; - } - - @override - BigInt? generateClientCredentials( - Uint8List salt, Uint8List identity, Uint8List password) { - x = SRP6Util.calculateX(digest, N, salt, identity, password); - a = selectPrivateValue(); - A = g.modPow(a!, N); - return A; - } - - BigInt? selectPrivateValue() { - return SRP6Util.generatePrivateValue(digest, N, g, random); - } - - @override - bool verifyServerEvidenceMessage(BigInt serverM2) { - // Verify pre-requirements - if (A == null || M1 == null || S == null) { - throw Exception('Impossible to compute and verify M2: ' - 'some data are missing from the previous operations (A,M1,S)'); - } - // Compute the own server evidence message 'M2' - var computedM2 = SRP6Util.calculateM2(digest, N, A, M1, S); - if (computedM2.compareTo(serverM2) == 0) { - M2 = serverM2; - return true; - } - return false; - } -} diff --git a/pointycastle/lib/srp/srp6_server.dart b/pointycastle/lib/srp/srp6_server.dart deleted file mode 100644 index 6387751..0000000 --- a/pointycastle/lib/srp/srp6_server.dart +++ /dev/null @@ -1,101 +0,0 @@ -library impl.srp_server; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/srp/srp6_standard_groups.dart'; -import 'package:pointycastle/srp/srp6_util.dart'; - -class SRP6Server implements SRPServer { - late BigInt N; - late BigInt g; - - BigInt v; - SecureRandom random; - Digest digest; - - BigInt? A; - - BigInt? b; - BigInt? B; - - BigInt? u; - BigInt? S; - BigInt? M1; - BigInt? M2; - BigInt? Key; - - SRP6Server( - {required SRP6GroupParameters group, - required this.v, - required this.digest, - required this.random}) { - g = group.g; - N = group.N; - } - - @override - BigInt? calculateSecret(BigInt clientA) { - A = SRP6Util.validatePublicValue(N, clientA); - u = SRP6Util.calculateU(digest, N, A, B); - S = _calculateS(); - - return S; - } - - @override - BigInt? calculateServerEvidenceMessage() { - // Verify pre-requirements - if (A == null || M1 == null || S == null) { - throw Exception( - 'Impossible to compute M2: some data are missing from the previous operations (A,M1,S)'); - } - - // Compute the server evidence message 'M2' - M2 = SRP6Util.calculateM2(digest, N, A!, M1!, S!); - return M2; - } - - @override - BigInt? calculateSessionKey() { - // Verify pre-requirements - if (S == null || M1 == null || M2 == null) { - throw Exception( - 'Impossible to compute Key: some data are missing from the previous operations (S,M1,M2)'); - } - Key = SRP6Util.calculateKey(digest, N, S); - return Key; - } - - @override - BigInt? generateServerCredentials() { - var k = SRP6Util.calculateK(digest, N, g); - b = selectPrivateValue(); - B = (k * v + g.modPow(b!, N)) % N; - - return B; - } - - BigInt? selectPrivateValue() { - return SRP6Util.generatePrivateValue(digest, N, g, random); - } - - @override - bool verifyClientEvidenceMessage(BigInt clientM1) { - // Verify pre-requirements - if (A == null || B == null || S == null) { - throw Exception( - 'Impossible to compute and verify M1: some data are missing from the previous operations (A,B,S)'); - } - - // Compute the own client evidence message 'M1' - var computedM1 = SRP6Util.calculateM1(digest, N, A, B, S); - if (computedM1.compareTo(clientM1) == 0) { - M1 = clientM1; - return true; - } - return false; - } - - BigInt _calculateS() { - return ((v.modPow(u!, N) * A!) % N).modPow(b!, N); - } -} diff --git a/pointycastle/lib/srp/srp6_standard_groups.dart b/pointycastle/lib/srp/srp6_standard_groups.dart deleted file mode 100644 index 2ae92ae..0000000 --- a/pointycastle/lib/srp/srp6_standard_groups.dart +++ /dev/null @@ -1,176 +0,0 @@ -library src.srp_standard_groups; - -class SRP6GroupParameters { - BigInt N, g; - - SRP6GroupParameters({required this.N, required this.g}); -} - -class SRP6StandardGroups { - static final String rfc5054_1024_N = - 'EEAF0AB9ADB38DD69C33F80AFA8FC5E86072618775FF3C0B9EA2314C' - '9C256576D674DF7496EA81D3383B4813D692C6E0E0D5D8E250B98BE4' - '8E495C1D6089DAD15DC7D7B46154D6B6CE8EF4AD69B15D4982559B29' - '7BCF1885C529F566660E57EC68EDBC3C05726CC02FD4CBF4976EAA9A' - 'FD5138FE8376435B9FC61D2FC0EB06E3'; - - static final String rfc5054_1024_g = '02'; - - /* - * * RFC 5054 - * */ - static final SRP6GroupParameters rfc5054_1024 = - fromNG(rfc5054_1024_N, rfc5054_1024_g); - static final String rfc5054_1536_N = - '9DEF3CAFB939277AB1F12A8617A47BBBDBA51DF499AC4C80BEEEA961' - '4B19CC4D5F4F5F556E27CBDE51C6A94BE4607A291558903BA0D0F843' - '80B655BB9A22E8DCDF028A7CEC67F0D08134B1C8B97989149B609E0B' - 'E3BAB63D47548381DBC5B1FC764E3F4B53DD9DA1158BFD3E2B9C8CF5' - '6EDF019539349627DB2FD53D24B7C48665772E437D6C7F8CE442734A' - 'F7CCB7AE837C264AE3A9BEB87F8A2FE9B8B5292E5A021FFF5E91479E' - '8CE7A28C2442C6F315180F93499A234DCF76E3FED135F9BB'; - static final String rfc5054_1536_g = '02'; - - static final SRP6GroupParameters rfc5054_1536 = - fromNG(rfc5054_1536_N, rfc5054_1536_g); - static final String rfc5054_2048_N = - 'AC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC319294' - '3DB56050A37329CBB4A099ED8193E0757767A13DD52312AB4B03310D' - 'CD7F48A9DA04FD50E8083969EDB767B0CF6095179A163AB3661A05FB' - 'D5FAAAE82918A9962F0B93B855F97993EC975EEAA80D740ADBF4FF74' - '7359D041D5C33EA71D281E446B14773BCA97B43A23FB801676BD207A' - '436C6481F1D2B9078717461A5B9D32E688F87748544523B524B0D57D' - '5EA77A2775D2ECFA032CFBDBF52FB3786160279004E57AE6AF874E73' - '03CE53299CCC041C7BC308D82A5698F3A8D0C38271AE35F8E9DBFBB6' - '94B5C803D89F7AE435DE236D525F54759B65E372FCD68EF20FA7111F' - '9E4AFF73'; - static final String rfc5054_2048_g = '02'; - - static final SRP6GroupParameters rfc5054_2048 = - fromNG(rfc5054_2048_N, rfc5054_2048_g); - static final String rfc5054_3072_N = - 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E08' - '8A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B' - '302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9' - 'A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE6' - '49286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8' - 'FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D' - '670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C' - '180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' - '3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D' - '04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7D' - 'B3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D226' - '1AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200C' - 'BBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFC' - 'E0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF'; - static final String rfc5054_3072_g = '05'; - - static final SRP6GroupParameters rfc5054_3072 = - fromNG(rfc5054_3072_N, rfc5054_3072_g); - static final String rfc5054_4096_N = - 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E08' - '8A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B' - '302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9' - 'A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE6' - '49286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8' - 'FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D' - '670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C' - '180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' - '3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D' - '04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7D' - 'B3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D226' - '1AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200C' - 'BBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFC' - 'E0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B26' - '99C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB' - '04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2' - '233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127' - 'D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199' - 'FFFFFFFFFFFFFFFF'; - static final String rfc5054_4096_g = '05'; - - static final SRP6GroupParameters rfc5054_4096 = - fromNG(rfc5054_4096_N, rfc5054_4096_g); - static final String rfc5054_6144_N = - 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E08' - '8A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B' - '302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9' - 'A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE6' - '49286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8' - 'FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D' - '670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C' - '180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' - '3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D' - '04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7D' - 'B3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D226' - '1AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200C' - 'BBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFC' - 'E0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B26' - '99C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB' - '04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2' - '233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127' - 'D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934028492' - '36C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406' - 'AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918' - 'DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B33205151' - '2BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03' - 'F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97F' - 'BEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA' - 'CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58B' - 'B7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632' - '387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E' - '6DCC4024FFFFFFFFFFFFFFFF'; - static final String rfc5054_6144_g = '05'; - - static final SRP6GroupParameters rfc5054_6144 = - fromNG(rfc5054_6144_N, rfc5054_6144_g); - static final String rfc5054_8192_N = - 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E08' - '8A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B' - '302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9' - 'A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE6' - '49286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8' - 'FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D' - '670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C' - '180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' - '3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D' - '04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7D' - 'B3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D226' - '1AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200C' - 'BBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFC' - 'E0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B26' - '99C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB' - '04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2' - '233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127' - 'D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934028492' - '36C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406' - 'AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918' - 'DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B33205151' - '2BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03' - 'F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97F' - 'BEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA' - 'CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58B' - 'B7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632' - '387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E' - '6DBE115974A3926F12FEE5E438777CB6A932DF8CD8BEC4D073B931BA' - '3BC832B68D9DD300741FA7BF8AFC47ED2576F6936BA424663AAB639C' - '5AE4F5683423B4742BF1C978238F16CBE39D652DE3FDB8BEFC848AD9' - '22222E04A4037C0713EB57A81A23F0C73473FC646CEA306B4BCBC886' - '2F8385DDFA9D4B7FA2C087E879683303ED5BDD3A062B3CF5B3A278A6' - '6D2A13F83F44F82DDF310EE074AB6A364597E899A0255DC164F31CC5' - '0846851DF9AB48195DED7EA1B1D510BD7EE74D73FAF36BC31ECFA268' - '359046F4EB879F924009438B481C6CD7889A002ED5EE382BC9190DA6' - 'FC026E479558E4475677E9AA9E3050E2765694DFC81F56E880B96E71' - '60C980DD98EDD3DFFFFFFFFFFFFFFFFF'; - static final String rfc5054_8192_g = '13'; - - static final SRP6GroupParameters rfc5054_8192 = - fromNG(rfc5054_8192_N, rfc5054_8192_g); - static BigInt fromHex(String hex) { - return BigInt.parse(hex, radix: 16); - } - - static SRP6GroupParameters fromNG(String hexN, String hexG) { - return SRP6GroupParameters(N: fromHex(hexN), g: fromHex(hexG)); - } -} diff --git a/pointycastle/lib/srp/srp6_util.dart b/pointycastle/lib/srp/srp6_util.dart deleted file mode 100644 index f5d53a9..0000000 --- a/pointycastle/lib/srp/srp6_util.dart +++ /dev/null @@ -1,167 +0,0 @@ -library src.srp_util; - -import 'dart:math' as math; -import 'dart:typed_data'; - -import 'package:pointycastle/pointycastle.dart'; - -class SRP6Util { - static final _byteMask = BigInt.from(0xff); - - static BigInt calculateK(Digest digest, BigInt N, BigInt g) { - return hashPaddedPair(digest, N, N, g); - } - - static BigInt calculateU(Digest digest, BigInt N, BigInt? A, BigInt? B) { - return hashPaddedPair(digest, N, A, B); - } - - static BigInt calculateX(Digest digest, BigInt N, Uint8List salt, - Uint8List identity, Uint8List password) { - var output = Uint8List(digest.digestSize); - - digest.update(identity, 0, identity.length); - digest.updateByte(':'.codeUnitAt(0)); - digest.update(password, 0, password.length); - digest.doFinal(output, 0); - - digest.update(salt, 0, salt.length); - digest.update(output, 0, output.length); - digest.doFinal(output, 0); - - return decodeBigInt(output); - } - - /// Decode a BigInt from bytes in big-endian encoding. - static BigInt decodeBigInt(List bytes) { - var result = BigInt.from(0); - for (var i = 0; i < bytes.length; i++) { - result += BigInt.from(bytes[bytes.length - i - 1]) << (8 * i); - } - return result; - } - - /// Encode a BigInt into bytes using big-endian encoding. - static Uint8List encodeBigInt(BigInt number) { - // Not handling negative numbers. Decide how you want to do that. - var size = (number.bitLength + 7) >> 3; - var result = Uint8List(size); - for (var i = 0; i < size; i++) { - result[size - i - 1] = (number & _byteMask).toInt(); - number = number >> 8; - } - return result; - } - - static BigInt? generatePrivateValue( - Digest digest, BigInt N, BigInt g, SecureRandom random) { - var minBits = math.min(256, N.bitLength ~/ 2); - var min = BigInt.one << (minBits - 1); - var max = N - BigInt.one; - - BigInt result; - do { - result = random.nextBigInteger(minBits); - } while (result > max || result < min); - return result; - } - - static BigInt validatePublicValue(BigInt N, BigInt val) { - val = val % N; - - // Check that val % N != 0 - if (val == BigInt.zero) { - throw Exception('Invalid public value: 0'); - } - - return val; - } - - /// Computes the client evidence message (M1) according to the standard routine: - /// M1 = H( A | B | S ) - /// [digest] The Digest used as the hashing function H - /// [N] Modulus used to get the pad length - /// [A] The public client value - /// [B] The public server value - /// [S] The secret calculated by both sides - /// [M1] The calculated client evidence message - static BigInt calculateM1( - Digest digest, BigInt N, BigInt? A, BigInt? B, BigInt? S) { - return hashPaddedTriplet(digest, N, A, B, S); - } - - /// Computes the server evidence message (M2) according to the standard routine: - /// M2 = H( A | M1 | S ) - /// [digest] The Digest used as the hashing function H - /// [N] Modulus used to get the pad length - /// [A] The public client value - /// [M1] The client evidence message - /// [S] The secret calculated by both sides - /// @return M2 The calculated server evidence message - static BigInt calculateM2( - Digest digest, BigInt N, BigInt? A, BigInt? M1, BigInt? S) { - return hashPaddedTriplet(digest, N, A, M1, S); - } - - /// Computes the final Key according to the standard routine: Key = H(S) - /// [digest] The Digest used as the hashing function H - /// [N] Modulus used to get the pad length - /// [S] The secret calculated by both sides - /// @return the final Key value. - static BigInt calculateKey(Digest digest, BigInt N, BigInt? S) { - var padLength = (N.bitLength + 7) ~/ 8; - var S0 = getPadded(S!, padLength); - digest.update(S0, 0, S0.length); - - var output = Uint8List(digest.digestSize); - digest.doFinal(output, 0); - return decodeBigInt(output); - } - - static BigInt hashPaddedTriplet( - Digest digest, BigInt N, BigInt? n1, BigInt? n2, BigInt? n3) { - var padLength = (N.bitLength + 7) ~/ 8; - - var n1Bytes = getPadded(n1!, padLength); - var n2Bytes = getPadded(n2!, padLength); - var n3Bytes = getPadded(n3!, padLength); - - digest.update(n1Bytes, 0, n1Bytes.length); - digest.update(n2Bytes, 0, n2Bytes.length); - digest.update(n3Bytes, 0, n3Bytes.length); - - var output = Uint8List(digest.digestSize); - digest.doFinal(output, 0); - - return decodeBigInt(output); - } - - static Uint8List getPadded(BigInt n, int length) { - var bs = encodeBigInt(n); - if (bs.length < length) { - var tmp = Uint8List(length); - var start = length - bs.length; - for (var i = 0; start < length; i++, start++) { - tmp[start] = bs[i]; - } - bs = tmp; - } - return bs; - } - - static BigInt hashPaddedPair( - Digest digest, BigInt N, BigInt? n1, BigInt? n2) { - var padLength = (N.bitLength + 7) ~/ 8; - - var n1Bytes = getPadded(n1!, padLength); - var n2Bytes = getPadded(n2!, padLength); - - digest.update(n1Bytes, 0, n1Bytes.length); - digest.update(n2Bytes, 0, n2Bytes.length); - - var output = Uint8List(digest.digestSize); - digest.doFinal(output, 0); - - return decodeBigInt(output); - } -} diff --git a/pointycastle/lib/srp/srp6_verifier_generator.dart b/pointycastle/lib/srp/srp6_verifier_generator.dart deleted file mode 100644 index d7fa558..0000000 --- a/pointycastle/lib/srp/srp6_verifier_generator.dart +++ /dev/null @@ -1,32 +0,0 @@ -library src.srp_verifier_generator; - -import 'dart:typed_data'; - -import 'package:pointycastle/srp/srp6_standard_groups.dart'; -import 'package:pointycastle/srp/srp6_util.dart'; -import 'package:pointycastle/pointycastle.dart'; - -/// Generates new SRP verifier for user -class SRP6VerifierGenerator { - late BigInt N; - late BigInt g; - Digest digest; - - SRP6VerifierGenerator( - {required SRP6GroupParameters group, required this.digest}) { - N = group.N; - g = group.g; - } - - /// Creates a new SRP verifier - /// [salt] The salt to use, generally should be large and random - /// [identity] The user's identifying information (eg. username) - /// [password] The user's password - /// returns A new verifier for use in future SRP authentication - BigInt generateVerifier( - Uint8List salt, Uint8List identity, Uint8List password) { - var x = SRP6Util.calculateX(digest, N, salt, identity, password); - - return g.modPow(x, N); - } -} diff --git a/pointycastle/lib/stream/chacha20.dart b/pointycastle/lib/stream/chacha20.dart deleted file mode 100644 index 57b4f79..0000000 --- a/pointycastle/lib/stream/chacha20.dart +++ /dev/null @@ -1,314 +0,0 @@ -library impl.stream_cipher.chacha20; - -import 'dart:typed_data'; - -import 'package:pointycastle/export.dart'; - -import '../api.dart'; -import '../src/impl/base_stream_cipher.dart'; -import '../src/registry/registry.dart'; -import '../src/ufixnum.dart'; - -// ignore_for_file: omit_local_variable_types, prefer_single_quotes -// ignore_for_file: non_constant_identifier_names, directives_ordering -// ignore_for_file: prefer_typing_uninitialized_variables, camel_case_types -// ignore_for_file: annotate_overrides - -/// Implementation of Daniel J. Bernstein's ChaCha20 stream cipher, Snuffle 2005. -class ChaCha20Engine extends BaseStreamCipher { - static final FactoryConfig factoryConfig = DynamicFactoryConfig.prefix( - StreamCipher, - 'ChaCha20/', - (_, final Match match) => () { - var rounds = int.parse(match.group(1)!); - return ChaCha20Engine.fromRounds(rounds); - }); - - static const STATE_SIZE = 16; - - int rounds = 20; - - static final _sigma = Uint8List.fromList([ - 101, - 120, - 112, - 97, - 110, - 100, - 32, - 51, - 50, - 45, - 98, - 121, - 116, - 101, - 32, - 107 - ]); - static final _tau = Uint8List.fromList([ - 101, - 120, - 112, - 97, - 110, - 100, - 32, - 49, - 54, - 45, - 98, - 121, - 116, - 101, - 32, - 107 - ]); - - Uint8List? _workingKey; - late Uint8List _workingIV; - - final _state = List.filled(STATE_SIZE, 0, growable: false); - final _buffer = List.filled(STATE_SIZE, 0, growable: false); - - final _keyStream = Uint8List(STATE_SIZE * 4); - var _keyStreamOffset = 0; - - var _initialised = false; - - @override - String get algorithmName => 'ChaCha20/$rounds'; - - ChaCha20Engine() { - rounds = 20; - } - - ChaCha20Engine.fromRounds(this.rounds); - - @override - void reset() { - if (_workingKey != null) { - _setKey(_workingKey!, _workingIV); - } - } - - @override - void init( - bool forEncryption, covariant ParametersWithIV params) { - var uparams = params.parameters; - var iv = params.iv; - if (iv.length != 8) { - throw ArgumentError('ChaCha20 requires exactly 8 bytes of IV'); - } - - _workingIV = iv; - _workingKey = uparams!.key; - - _setKey(_workingKey!, _workingIV); - } - - @override - int returnByte(int inp) { - if (_keyStreamOffset == 0) { - generateKeyStream(_keyStream); - - if (++_state[12] == 0) { - ++_state[13]; - } - } - - var out = clip8(_keyStream[_keyStreamOffset] ^ inp); - _keyStreamOffset = (_keyStreamOffset + 1) & 63; - - return out; - } - - @override - void processBytes( - Uint8List inp, int inpOff, int len, Uint8List out, int outOff) { - if (!_initialised) { - throw StateError('ChaCha20 not initialized: please call init() first'); - } - - if ((inpOff + len) > inp.length) { - throw ArgumentError( - 'Input buffer too short or requested length too long'); - } - - if ((outOff + len) > out.length) { - throw ArgumentError( - 'Output buffer too short or requested length too long'); - } - - for (var i = 0; i < len; i++) { - if (_keyStreamOffset == 0) { - generateKeyStream(_keyStream); - - if (++_state[12] == 0) { - ++_state[13]; - } - } - - out[i + outOff] = clip8(_keyStream[_keyStreamOffset] ^ inp[i + inpOff]); - _keyStreamOffset = (_keyStreamOffset + 1) & 63; - } - } - - void _setKey(Uint8List keyBytes, Uint8List ivBytes) { - _workingKey = keyBytes; - _workingIV = ivBytes; - - _keyStreamOffset = 0; - var offset = 0; - Uint8List constants; - - // Key - _state[4] = unpack32(_workingKey, 0, Endian.little); - _state[5] = unpack32(_workingKey, 4, Endian.little); - _state[6] = unpack32(_workingKey, 8, Endian.little); - _state[7] = unpack32(_workingKey, 12, Endian.little); - - if (_workingKey!.length == 32) { - constants = _sigma; - offset = 16; - } else { - constants = _tau; - } - - _state[8] = unpack32(_workingKey, offset, Endian.little); - _state[9] = unpack32(_workingKey, offset + 4, Endian.little); - _state[10] = unpack32(_workingKey, offset + 8, Endian.little); - _state[11] = unpack32(_workingKey, offset + 12, Endian.little); - _state[0] = unpack32(constants, 0, Endian.little); - _state[1] = unpack32(constants, 4, Endian.little); - _state[2] = unpack32(constants, 8, Endian.little); - _state[3] = unpack32(constants, 12, Endian.little); - - // IV - _state[14] = unpack32(_workingIV, 0, Endian.little); - _state[15] = unpack32(_workingIV, 4, Endian.little); - _state[12] = _state[13] = 0; - - _initialised = true; - } - - void generateKeyStream(Uint8List output) { - _core(rounds, _state, _buffer); - var outOff = 0; - for (var x in _buffer) { - pack32(x, output, outOff, Endian.little); - outOff += 4; - } - } - - /// The ChaCha20 core function - void _core(int rounds, List input, List x) { - var x00 = input[0]; - var x01 = input[1]; - var x02 = input[2]; - var x03 = input[3]; - var x04 = input[4]; - var x05 = input[5]; - var x06 = input[6]; - var x07 = input[7]; - var x08 = input[8]; - var x09 = input[9]; - var x10 = input[10]; - var x11 = input[11]; - var x12 = input[12]; - var x13 = input[13]; - var x14 = input[14]; - var x15 = input[15]; - - for (var i = rounds; i > 0; i -= 2) { - x00 += x04; - x12 = crotl32(x12 ^ x00, 16); - x08 += x12; - x04 = crotl32(x04 ^ x08, 12); - x00 += x04; - x12 = crotl32(x12 ^ x00, 8); - x08 += x12; - x04 = crotl32(x04 ^ x08, 7); - x01 += x05; - x13 = crotl32(x13 ^ x01, 16); - x09 += x13; - x05 = crotl32(x05 ^ x09, 12); - x01 += x05; - x13 = crotl32(x13 ^ x01, 8); - x09 += x13; - x05 = crotl32(x05 ^ x09, 7); - x02 += x06; - x14 = crotl32(x14 ^ x02, 16); - x10 += x14; - x06 = crotl32(x06 ^ x10, 12); - x02 += x06; - x14 = crotl32(x14 ^ x02, 8); - x10 += x14; - x06 = crotl32(x06 ^ x10, 7); - x03 += x07; - x15 = crotl32(x15 ^ x03, 16); - x11 += x15; - x07 = crotl32(x07 ^ x11, 12); - x03 += x07; - x15 = crotl32(x15 ^ x03, 8); - x11 += x15; - x07 = crotl32(x07 ^ x11, 7); - x00 += x05; - x15 = crotl32(x15 ^ x00, 16); - x10 += x15; - x05 = crotl32(x05 ^ x10, 12); - x00 += x05; - x15 = crotl32(x15 ^ x00, 8); - x10 += x15; - x05 = crotl32(x05 ^ x10, 7); - x01 += x06; - x12 = crotl32(x12 ^ x01, 16); - x11 += x12; - x06 = crotl32(x06 ^ x11, 12); - x01 += x06; - x12 = crotl32(x12 ^ x01, 8); - x11 += x12; - x06 = crotl32(x06 ^ x11, 7); - x02 += x07; - x13 = crotl32(x13 ^ x02, 16); - x08 += x13; - x07 = crotl32(x07 ^ x08, 12); - x02 += x07; - x13 = crotl32(x13 ^ x02, 8); - x08 += x13; - x07 = crotl32(x07 ^ x08, 7); - x03 += x04; - x14 = crotl32(x14 ^ x03, 16); - x09 += x14; - x04 = crotl32(x04 ^ x09, 12); - x03 += x04; - x14 = crotl32(x14 ^ x03, 8); - x09 += x14; - x04 = crotl32(x04 ^ x09, 7); - } - var xup = [ - x00, - x01, - x02, - x03, - x04, - x05, - x06, - x07, - x08, - x09, - x10, - x11, - x12, - x13, - x14, - x15 - ]; - for (var i = 0; i < STATE_SIZE; ++i) { - x[i] = csum32(xup[i], input[i]); - } - } - - @override - dynamic noSuchMethod(Invocation invocation); -} diff --git a/pointycastle/lib/stream/chacha20poly1305.dart b/pointycastle/lib/stream/chacha20poly1305.dart deleted file mode 100644 index b096ca0..0000000 --- a/pointycastle/lib/stream/chacha20poly1305.dart +++ /dev/null @@ -1,503 +0,0 @@ -library impl.stream_cipher.chacha20poly1305; - -import 'dart:math'; -import 'dart:typed_data'; - -import 'package:pointycastle/src/registry/registry.dart'; -import '../export.dart'; -import '../src/impl/base_aead_cipher.dart'; -import '../src/ufixnum.dart'; - -import '../src/utils.dart' as utils; - -// ignore_for_file: non_constant_identifier_names - -class ChaCha20Poly1305 extends BaseAEADCipher { - static final FactoryConfig factoryConfig = StaticFactoryConfig( - AEADCipher, - 'ChaCha20-Poly1305', - () => ChaCha20Poly1305(ChaCha7539Engine(), Poly1305())); - static const BUF_SIZE = 64; - static const KEY_SIZE = 32; - static const NONCE_SIZE = 12; - static const MAC_SIZE = 16; - static final MAX = pow(2, 63) - 1; - static final MIN = -pow(2, 63); - static final Uint8List ZEROES = Uint8List(MAC_SIZE - 1); - - static final int AADLimit = (MAX - MIN).toInt(); - static const DATA_LIMIT = (1 << 32 - 1) * 64; - final ChaCha7539Engine chacha20; - final Poly1305 poly1305; - - final Uint8List _key = Uint8List(KEY_SIZE); - final Uint8List _nonce = Uint8List(NONCE_SIZE); - final Uint8List _buf = Uint8List(MAC_SIZE + BUF_SIZE); - final Uint8List _mac = Uint8List(MAC_SIZE); - - @override - String get algorithmName => 'ChaCha20-Poly1305'; - - @override - Uint8List get mac => _mac; - - Uint8List? _initialAAD; - late int _aadCount; - late int _dataCount; - int _state = State.UNINITIALIZED; - late int _bufPos; - - ChaCha20Poly1305(this.chacha20, this.poly1305); - - @override - void init(bool forEncryption, CipherParameters params) { - KeyParameter initKeyParam; - Uint8List? initNonce; - CipherParameters chacha20Params; - - if (params is AEADParameters) { - var aeadParams = params; - - var macSizeBits = aeadParams.macSize; - if ((MAC_SIZE * 8) != macSizeBits) { - throw ArgumentError('Invalid value for MAC size: $macSizeBits'); - } - - initKeyParam = aeadParams.parameters as KeyParameter; - initNonce = aeadParams.nonce; - chacha20Params = ParametersWithIV(initKeyParam, initNonce); - - _initialAAD = aeadParams.associatedData; - } else if (params is ParametersWithIV) { - var ivParams = params; - - initKeyParam = ivParams.parameters as KeyParameter; - initNonce = ivParams.iv; - chacha20Params = ivParams; - - _initialAAD = null; - } else { - throw ArgumentError('invalid parameters passed to ChaCha20Poly1305'); - } - - // Validate key - if (KEY_SIZE != initKeyParam.key.length) { - throw ArgumentError('Key must be 256 bits'); - } - - // Validate nonce - if (NONCE_SIZE != initNonce.length) { - throw ArgumentError('Nonce must be 96 bits'); - } - - utils.arrayCopy(initKeyParam.key, 0, _key, 0, KEY_SIZE); - - utils.arrayCopy(initNonce, 0, _nonce, 0, NONCE_SIZE); - - chacha20.init(true, chacha20Params as ParametersWithIV); - - _state = forEncryption ? State.ENC_INIT : State.DEC_INIT; - - resetBool(true, false); - } - - @override - // ignore: missing_return - int getOutputSize(int len) { - var total = max(0, len) + _bufPos; - - switch (_state) { - case State.DEC_INIT: - case State.DEC_AAD: - case State.DEC_DATA: - return max(0, total - MAC_SIZE); - case State.ENC_INIT: - case State.ENC_AAD: - case State.ENC_DATA: - return total + MAC_SIZE; - default: - throw StateError('state = $_state'); - } - } - - @override - int getUpdateOutputSize(int len) { - var total = max(0, len) + _bufPos; - - switch (_state) { - case State.DEC_INIT: - case State.DEC_AAD: - case State.DEC_DATA: - total = max(0, total - MAC_SIZE); - break; - case State.ENC_INIT: - case State.ENC_AAD: - case State.ENC_DATA: - break; - default: - throw StateError(''); - } - - return total - (total % BUF_SIZE); - } - - @override - void processAADByte(int inp) { - checkAAD(); - - _aadCount = incrementCount(_aadCount, 1, AADLimit); - poly1305.updateByte(inp); - } - - @override - void processAADBytes(Uint8List inp, int inOff, int len) { - if (inOff < 0) { - throw ArgumentError('\'inOff\' cannot be negative'); - } - if (len < 0) { - throw ArgumentError('\'len\' cannot be negative'); - } - if (inOff > (inp.length - len)) { - throw ArgumentError('Input buffer too short'); - } - - checkAAD(); - - if (len > 0) { - _aadCount = incrementCount(_aadCount, len, AADLimit); - poly1305.update(inp, inOff, len); - } - } - - @override - int processByte(int inp, Uint8List out, int outOff) { - checkData(); - - switch (_state) { - case State.DEC_DATA: - { - _buf[_bufPos] = inp; - if (++_bufPos == _buf.length) { - poly1305.update(_buf, 0, BUF_SIZE); - processData(_buf, 0, BUF_SIZE, out, outOff); - utils.arrayCopy(_buf, BUF_SIZE, _buf, 0, MAC_SIZE); - _bufPos = MAC_SIZE; - return BUF_SIZE; - } - - return 0; - } - case State.ENC_DATA: - { - _buf[_bufPos] = inp; - if (++_bufPos == BUF_SIZE) { - processData(_buf, 0, BUF_SIZE, out, outOff); - poly1305.update(out, outOff, BUF_SIZE); - _bufPos = 0; - return BUF_SIZE; - } - - return 0; - } - default: - throw StateError(''); - } - } - - @override - int processBytes( - Uint8List inp, int inOff, int len, Uint8List out, int outOff) { - if (inOff < 0) { - throw ArgumentError('\'inOff\' cannot be negative'); - } - if (len < 0) { - throw ArgumentError('\'len\' cannot be negative'); - } - if (inOff > (inp.length - len)) { - throw ArgumentError('Input buffer too short'); - } - if (outOff < 0) { - throw ArgumentError('\'outOff\' cannot be negative'); - } - - checkData(); - - var resultLen = 0; - - switch (_state) { - case State.DEC_DATA: - { - for (var i = 0; i < len; ++i) { - _buf[_bufPos] = inp[inOff + i]; - if (++_bufPos == _buf.length) { - poly1305.update(_buf, 0, BUF_SIZE); - processData(_buf, 0, BUF_SIZE, out, outOff + resultLen); - utils.arrayCopy(_buf, BUF_SIZE, _buf, 0, MAC_SIZE); - _bufPos = MAC_SIZE; - resultLen += BUF_SIZE; - } - } - break; - } - case State.ENC_DATA: - { - if (_bufPos != 0) { - while (len > 0) { - --len; - _buf[_bufPos] = inp[inOff++]; - if (++_bufPos == BUF_SIZE) { - processData(_buf, 0, BUF_SIZE, out, outOff); - poly1305.update(out, outOff, BUF_SIZE); - _bufPos = 0; - resultLen = BUF_SIZE; - break; - } - } - } - - while (len >= BUF_SIZE) { - processData(inp, inOff, BUF_SIZE, out, outOff + resultLen); - poly1305.update(out, outOff + resultLen, BUF_SIZE); - inOff += BUF_SIZE; - len -= BUF_SIZE; - resultLen += BUF_SIZE; - } - - if (len > 0) { - utils.arrayCopy(inp, inOff, _buf, 0, len); - _bufPos = len; - } - break; - } - default: - throw StateError(''); - } - - return resultLen; - } - - @override - int doFinal(Uint8List out, int outOff) { - if (outOff < 0) { - throw ArgumentError('\'outOff\' cannot be negative'); - } - - checkData(); - - for (var i = 0; i < _mac.length; i++) { - _mac[i] = 0x00; - } - - var resultLen = 0; - - switch (_state) { - case State.DEC_DATA: - { - if (_bufPos < MAC_SIZE) { - throw ArgumentError('data too short'); - } - - resultLen = _bufPos - MAC_SIZE; - - if (outOff > (out.length - resultLen)) { - throw ArgumentError('Output buffer too short'); - } - - if (resultLen > 0) { - poly1305.update(_buf, 0, resultLen); - processData(_buf, 0, resultLen, out, outOff); - } - - finishData(State.DEC_FINAL); - - if (!utils.constantTimeAreEqualOffset( - MAC_SIZE, _mac, 0, _buf, resultLen)) { - throw ArgumentError('mac check in ChaCha20Poly1305 failed'); - } - - break; - } - case State.ENC_DATA: - { - resultLen = _bufPos + MAC_SIZE; - - // ignore: invariant_booleans - if (outOff > (out.length - resultLen)) { - throw ArgumentError('Output buffer too short'); - } - - if (_bufPos > 0) { - processData(_buf, 0, _bufPos, out, outOff); - poly1305.update(out, outOff, _bufPos); - } - - finishData(State.ENC_FINAL); - - utils.arrayCopy(_mac, 0, out, outOff + _bufPos, MAC_SIZE); - break; - } - default: - throw StateError(''); - } - - resetBool(false, true); - - return resultLen; - } - - @override - void reset() { - resetBool(true, true); - } - - void resetBool(bool clearMac, bool resetCipher) { - for (var i = 0; i < _buf.length; i++) { - _buf[i] = 0; - } - - if (clearMac) { - for (var i = 0; i < _mac.length; i++) { - _mac[i] = 0x00; - } - } - - _aadCount = 0; - _dataCount = 0; - _bufPos = 0; - - switch (_state) { - case State.DEC_INIT: - case State.ENC_INIT: - break; - case State.DEC_AAD: - case State.DEC_DATA: - case State.DEC_FINAL: - _state = State.DEC_INIT; - break; - case State.ENC_AAD: - case State.ENC_DATA: - case State.ENC_FINAL: - _state = State.ENC_FINAL; - return; - default: - throw StateError(''); - } - - if (resetCipher) { - chacha20.reset(); - } - - initMAC(); - - if (_initialAAD != null) { - processAADBytes(_initialAAD!, 0, _initialAAD!.length); - } - } - - void checkAAD() { - switch (_state) { - case State.DEC_INIT: - _state = State.DEC_AAD; - break; - case State.ENC_INIT: - _state = State.ENC_AAD; - break; - case State.DEC_AAD: - case State.ENC_AAD: - break; - case State.ENC_FINAL: - throw StateError('ChaCha20Poly1305 cannot be reused for encryption'); - default: - throw StateError(''); - } - } - - void checkData() { - switch (_state) { - case State.DEC_INIT: - case State.DEC_AAD: - finishAAD(State.DEC_DATA); - break; - case State.ENC_INIT: - case State.ENC_AAD: - finishAAD(State.ENC_DATA); - break; - case State.DEC_DATA: - case State.ENC_DATA: - break; - case State.ENC_FINAL: - throw StateError('ChaCha20Poly1305 cannot be reused for encryption'); - default: - throw StateError(''); - } - } - - void finishAAD(int nextState) { - padMAC(_aadCount); - - _state = nextState; - } - - void finishData(int nextState) { - padMAC(_dataCount); - - var lengths = Uint8List(16); - pack32(_aadCount, lengths, 0, Endian.little); - pack32(_dataCount, lengths, 8, Endian.little); - poly1305.update(lengths, 0, 16); - - poly1305.doFinal(_mac, 0); - - _state = nextState; - } - - int incrementCount(int count, int increment, int limit) { - if (count + MIN > (limit - increment) + MIN) { - throw StateError('Limit exceeded'); - } - - return count + increment; - } - - void initMAC() { - var firstBlock = Uint8List(64); - try { - chacha20.processBytes(firstBlock, 0, 64, firstBlock, 0); - poly1305.init(KeyParameter.offset(firstBlock, 0, 32)); - } finally { - for (var i = 0; i < firstBlock.length; i++) { - firstBlock[i] = 0; - } - } - } - - void padMAC(int count) { - var partial = (count & 4294967295) & (MAC_SIZE - 1); - if (0 != partial) { - poly1305.update(ZEROES, 0, MAC_SIZE - partial); - } - } - - void processData( - Uint8List inp, int inOff, int inLen, Uint8List out, int outOff) { - if (outOff > (out.length - inLen)) { - throw ArgumentError('Output buffer too short'); - } - - chacha20.processBytes(inp, inOff, inLen, out, outOff); - - _dataCount = incrementCount(_dataCount, inLen, DATA_LIMIT); - } -} - -class State { - static const UNINITIALIZED = 0; - static const ENC_INIT = 1; - static const ENC_AAD = 2; - static const ENC_DATA = 3; - static const ENC_FINAL = 4; - static const DEC_INIT = 5; - static const DEC_AAD = 6; - static const DEC_DATA = 7; - static const DEC_FINAL = 8; -} diff --git a/pointycastle/lib/stream/chacha7539.dart b/pointycastle/lib/stream/chacha7539.dart deleted file mode 100644 index 8c074d4..0000000 --- a/pointycastle/lib/stream/chacha7539.dart +++ /dev/null @@ -1,315 +0,0 @@ -library impl.stream_cipher.chacha7539; - -import 'dart:typed_data'; - -import '../export.dart'; -import '../api.dart'; -import '../src/impl/base_stream_cipher.dart'; -import '../src/registry/registry.dart'; -import '../src/ufixnum.dart'; - -// ignore_for_file: omit_local_variable_types, prefer_single_quotes -// ignore_for_file: non_constant_identifier_names, directives_ordering -// ignore_for_file: prefer_typing_uninitialized_variables, camel_case_types -// ignore_for_file: annotate_overrides - -/// RFC version of Daniel J. Bernstein's ChaCha20. This uses a 12 byte IV, among -/// other changes. -class ChaCha7539Engine extends BaseStreamCipher { - static final FactoryConfig factoryConfig = DynamicFactoryConfig.prefix( - StreamCipher, - 'ChaCha7539/', - (_, final Match match) => () { - var rounds = int.parse(match.group(1)!); - return ChaCha7539Engine.fromRounds(rounds); - }); - - ChaCha7539Engine() { - rounds = 20; - } - - ChaCha7539Engine.fromRounds(this.rounds); - - int rounds = 20; - - static const STATE_SIZE = 16; - - static final _sigma = Uint8List.fromList([ - 101, - 120, - 112, - 97, - 110, - 100, - 32, - 51, - 50, - 45, - 98, - 121, - 116, - 101, - 32, - 107 - ]); - static final _tau = Uint8List.fromList([ - 101, - 120, - 112, - 97, - 110, - 100, - 32, - 49, - 54, - 45, - 98, - 121, - 116, - 101, - 32, - 107 - ]); - - Uint8List? _workingKey; - late Uint8List _workingIV; - - final _state = List.filled(STATE_SIZE, 0, growable: false); - final _buffer = List.filled(STATE_SIZE, 0, growable: false); - - final _keyStream = Uint8List(STATE_SIZE * 4); - var _keyStreamOffset = 0; - - var _initialised = false; - - @override - String get algorithmName => 'ChaCha7539/$rounds'; - - @override - void reset() { - _state[12] = 0; - if (_workingKey != null) { - _setKey(_workingKey!, _workingIV); - } - } - - @override - void init( - bool forEncryption, covariant ParametersWithIV params) { - var uparams = params.parameters; - var iv = params.iv; - if (iv.length != 12) { - throw ArgumentError('ChaCha20-7539 requires exactly 12 bytes of IV'); - } - - _workingIV = iv; - _workingKey = uparams!.key; - - _setKey(_workingKey!, _workingIV); - } - - @override - int returnByte(int inp) { - if (_keyStreamOffset == 0) { - generateKeyStream(_keyStream); - - if (++_state[12] == 0) { - ++_state[13]; - } - } - - var out = clip8(_keyStream[_keyStreamOffset] ^ inp); - _keyStreamOffset = (_keyStreamOffset + 1) & 63; - - return out; - } - - @override - void processBytes( - Uint8List inp, int inpOff, int len, Uint8List out, int outOff) { - if (!_initialised) { - throw StateError('ChaCha20 not initialized: please call init() first'); - } - - if ((inpOff + len) > inp.length) { - throw ArgumentError( - 'Input buffer too short or requested length too long'); - } - - if ((outOff + len) > out.length) { - throw ArgumentError( - 'Output buffer too short or requested length too long'); - } - - for (var i = 0; i < len; i++) { - if (_keyStreamOffset == 0) { - generateKeyStream(_keyStream); - - if (++_state[12] == 0) throw StateError('Illegal increase of counter'); - } - - out[i + outOff] = clip8(_keyStream[_keyStreamOffset] ^ inp[i + inpOff]); - _keyStreamOffset = (_keyStreamOffset + 1) & 63; - } - } - - void _setKey(Uint8List keyBytes, Uint8List ivBytes) { - _workingKey = keyBytes; - _workingIV = ivBytes; - - _keyStreamOffset = 0; - Uint8List constants; - - if (_workingKey!.length == 32) { - constants = _sigma; - } else { - constants = _tau; - } - - //Key - _state[4] = unpack32(_workingKey, 0, Endian.little); - _state[5] = unpack32(_workingKey, 4, Endian.little); - _state[6] = unpack32(_workingKey, 8, Endian.little); - _state[7] = unpack32(_workingKey, 12, Endian.little); - _state[8] = unpack32(_workingKey, 16, Endian.little); - _state[9] = unpack32(_workingKey, 20, Endian.little); - _state[10] = unpack32(_workingKey, 24, Endian.little); - _state[11] = unpack32(_workingKey, 28, Endian.little); - - _state[0] = unpack32(constants, 0, Endian.little); - _state[1] = unpack32(constants, 4, Endian.little); - _state[2] = unpack32(constants, 8, Endian.little); - _state[3] = unpack32(constants, 12, Endian.little); - - _state[12] = 0; - - // IV - var off = 0; - for (var i = 0; i < 3; ++i) { - _state[13 + i] = unpack32(_workingIV, off, Endian.little); - off += 4; - } - - _initialised = true; - } - - void generateKeyStream(Uint8List output) { - _core(rounds, _state, _buffer); - var outOff = 0; - for (var x in _buffer) { - pack32(x, output, outOff, Endian.little); - outOff += 4; - } - } - - /// The ChaCha20 core function - void _core(int rounds, List input, List x) { - var x00 = input[0]; - var x01 = input[1]; - var x02 = input[2]; - var x03 = input[3]; - var x04 = input[4]; - var x05 = input[5]; - var x06 = input[6]; - var x07 = input[7]; - var x08 = input[8]; - var x09 = input[9]; - var x10 = input[10]; - var x11 = input[11]; - var x12 = input[12]; - var x13 = input[13]; - var x14 = input[14]; - var x15 = input[15]; - - for (var i = rounds; i > 0; i -= 2) { - x00 += x04; - x12 = crotl32(x12 ^ x00, 16); - x08 += x12; - x04 = crotl32(x04 ^ x08, 12); - x00 += x04; - x12 = crotl32(x12 ^ x00, 8); - x08 += x12; - x04 = crotl32(x04 ^ x08, 7); - x01 += x05; - x13 = crotl32(x13 ^ x01, 16); - x09 += x13; - x05 = crotl32(x05 ^ x09, 12); - x01 += x05; - x13 = crotl32(x13 ^ x01, 8); - x09 += x13; - x05 = crotl32(x05 ^ x09, 7); - x02 += x06; - x14 = crotl32(x14 ^ x02, 16); - x10 += x14; - x06 = crotl32(x06 ^ x10, 12); - x02 += x06; - x14 = crotl32(x14 ^ x02, 8); - x10 += x14; - x06 = crotl32(x06 ^ x10, 7); - x03 += x07; - x15 = crotl32(x15 ^ x03, 16); - x11 += x15; - x07 = crotl32(x07 ^ x11, 12); - x03 += x07; - x15 = crotl32(x15 ^ x03, 8); - x11 += x15; - x07 = crotl32(x07 ^ x11, 7); - x00 += x05; - x15 = crotl32(x15 ^ x00, 16); - x10 += x15; - x05 = crotl32(x05 ^ x10, 12); - x00 += x05; - x15 = crotl32(x15 ^ x00, 8); - x10 += x15; - x05 = crotl32(x05 ^ x10, 7); - x01 += x06; - x12 = crotl32(x12 ^ x01, 16); - x11 += x12; - x06 = crotl32(x06 ^ x11, 12); - x01 += x06; - x12 = crotl32(x12 ^ x01, 8); - x11 += x12; - x06 = crotl32(x06 ^ x11, 7); - x02 += x07; - x13 = crotl32(x13 ^ x02, 16); - x08 += x13; - x07 = crotl32(x07 ^ x08, 12); - x02 += x07; - x13 = crotl32(x13 ^ x02, 8); - x08 += x13; - x07 = crotl32(x07 ^ x08, 7); - x03 += x04; - x14 = crotl32(x14 ^ x03, 16); - x09 += x14; - x04 = crotl32(x04 ^ x09, 12); - x03 += x04; - x14 = crotl32(x14 ^ x03, 8); - x09 += x14; - x04 = crotl32(x04 ^ x09, 7); - } - var xup = [ - x00, - x01, - x02, - x03, - x04, - x05, - x06, - x07, - x08, - x09, - x10, - x11, - x12, - x13, - x14, - x15 - ]; - for (var i = 0; i < STATE_SIZE; ++i) { - x[i] = csum32(xup[i], input[i]); - } - } - - @override - dynamic noSuchMethod(Invocation invocation); -} diff --git a/pointycastle/lib/stream/ctr.dart b/pointycastle/lib/stream/ctr.dart deleted file mode 100644 index 76adefe..0000000 --- a/pointycastle/lib/stream/ctr.dart +++ /dev/null @@ -1,23 +0,0 @@ -// See file LICENSE for more information. - -library impl.stream_cipher.ctr; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/stream/sic.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// Just an alias to be able to create SIC as CTR -class CTRStreamCipher extends SICStreamCipher { - /// Intended for internal use. - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - StreamCipher, - '/CTR', - (_, final Match match) => () { - var digestName = match.group(1); - return CTRStreamCipher(BlockCipher(digestName!)); - }); - - CTRStreamCipher(super.underlyingCipher); - @override - String get algorithmName => '${underlyingCipher.algorithmName}/CTR'; -} diff --git a/pointycastle/lib/stream/eax.dart b/pointycastle/lib/stream/eax.dart deleted file mode 100644 index 30eb17e..0000000 --- a/pointycastle/lib/stream/eax.dart +++ /dev/null @@ -1,311 +0,0 @@ -// See file LICENSE for more information. - -library impl.stream_cipher.eax; - -import 'dart:core'; -import 'dart:math'; -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/macs/cmac.dart'; -import 'package:pointycastle/src/impl/base_aead_cipher.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/utils.dart'; -import 'package:pointycastle/stream/ctr.dart'; - -/// EAX mode based on CTR and CMAC/OMAC1. -/// -/// Encrypts plaintext and outputs the ciphertext with the concatenated mac. -/// Decrypts and verifies ciphertext with the concatenated mac and returns the plaintext. -/// Ported from BouncyCastle's Java impl: https://github.com/bcgit/bc-java/blob/master/core/src/main/java/org/bouncycastle/crypto/modes/EAXBlockCipher.java -class EAX extends BaseAEADCipher { - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - AEADCipher, - '/EAX', - (_, final Match match) => () { - var digestName = match.group(1); - return EAX(BlockCipher(digestName!)); - }); - - static const _nonceTAG = 0x0; - static const _aadTAG = 0x1; - static const _cipherTAG = 0x2; - - final CTRStreamCipher _ctr; - final CMac _cMac; - late bool _forEncryption; - late KeyParameter _keyParam; - late CipherParameters _initParams; - late Uint8List _nonceMac; - late Uint8List _aadMac; - late Uint8List _cipherMac; - late Uint8List _bufBlock; - late int _bufOff; - late bool _bufFull; - late bool _aadFinished; - - int get _blockSize => underlyingCipher.blockSize; - - /// The cipher used in CTR and CMAC - final BlockCipher underlyingCipher; - - int _macSize; - - /// The byte size that the [mac] calculated by [doFinal] must be. - int get macSize => _macSize; - - /// The MAC (also known as Tag), calculated and cached by [doFinal]. - /// - /// Will not be cleared on [reset] or [init]. - @override - late Uint8List mac; - - @override - String get algorithmName => '${underlyingCipher.algorithmName}/EAX'; - - EAX(this.underlyingCipher) - : _ctr = CTRStreamCipher(underlyingCipher), - _cMac = CMac(underlyingCipher, underlyingCipher.blockSize * 8), - _macSize = underlyingCipher.blockSize ~/ 2; - - /// Initializes this for addition of AAD and en/decryption of data. - @override - void init(bool forEncryption, CipherParameters params) { - _forEncryption = forEncryption; - _initParams = params; - Uint8List initNonce; - Uint8List? initAAD; - - if (params is AEADParameters) { - _macSize = params.macSize ~/ 8; - _keyParam = params.parameters as KeyParameter; - initNonce = params.nonce; - initAAD = params.associatedData; - } else if (params is ParametersWithIV) { - _keyParam = params.parameters as KeyParameter; - initNonce = params.iv; - } else { - throw ArgumentError( - '${params.runtimeType} is not ParametersWithIV or AEADParameters', - 'params'); - } - - _nonceMac = Uint8List(_blockSize); - _cMac - ..init(_keyParam) - ..update( - Uint8List(_blockSize)..[_blockSize - 1] = _nonceTAG, 0, _blockSize) - ..update(initNonce, 0, initNonce.length) - ..doFinal(_nonceMac, 0); - - _aadFinished = false; - _aadMac = Uint8List(_blockSize); - _cMac - ..init(_keyParam) - ..update( - Uint8List(_blockSize)..[_blockSize - 1] = _aadTAG, 0, _blockSize); - if (initAAD != null) processAADBytes(initAAD, 0, initAAD.length); - - _cipherMac = Uint8List(_blockSize); - _ctr.init(_forEncryption, ParametersWithIV(_keyParam, _nonceMac)); - - _bufBlock = Uint8List(_macSize); - _bufOff = 0; - _bufFull = false; - } - - /// Calculates, caches and if used as decrypter also verifies this [mac], - /// calls [reset] and returns the number of bytes written. - @override - int doFinal(Uint8List out, int outOff) { - _cMac.doFinal(_cipherMac, 0); - _calculateMac(); - - if (_forEncryption) { - if (out.length < outOff + _macSize) { - throw ArgumentError( - 'actual length: ${out.length}, ' - 'min: ${outOff + _macSize}', - 'out'); - } - out.setAll(outOff, mac); - - reset(); - return _macSize; - } else { - if (!_bufFull) { - throw StateError('Did not process enough data ' - 'for MAC to be collected from input.'); - } - if (!_verifyMac(_inMac, 0)) { - throw StateError('MAC does not match.'); - } - - reset(); - return 0; - } - } - - /// Initializes this with the parameters last given to [init]. - @override - void reset() { - init(_forEncryption, _initParams); - } - - /// Processes further AAD. - /// - /// Must not be used when en-/decryption of data had begun. - @override - void processAADByte(int inp) { - if (_aadFinished) { - throw StateError('Must not be used when en-/decryption ' - 'of data had begun.'); - } - _cMac.updateByte(inp); - } - - /// Processes further AAD. - /// - /// Must not be used after en-/decryption of data has begun. - @override - void processAADBytes(Uint8List inp, int inpOff, int len) { - if (_aadFinished) { - throw StateError('Must not be used when en-/decryption ' - 'of data had begun.'); - } - _cMac.update(inp, inpOff, len); - } - - /// Processes the input and returns the amount of bytes written. - @override - int processByte(int inp, Uint8List out, int outOff) { - _ensureAadMacFinished(); - - var r = out[outOff] = _ctr.returnByte(inp); - - if (_forEncryption) { - _cMac.updateByte(r); - return 1; - } - return _bufByte(inp); - } - - /// Processes the input and returns the amount of bytes written. - @override - int processBytes( - Uint8List inp, int inOff, int len, Uint8List out, int outOff) { - _ensureAadMacFinished(); - - if (_forEncryption) { - _ctr.processBytes(inp, inOff, len, out, outOff); - _cMac.update(out, outOff, len); - return len; - } else { - return _buf(inp, inOff, len, out, outOff); - } - } - - /// Returns the amount of bytes being outputted - /// by the next [processBytes] and [doFinal] for [len] bytes input. - @override - int getOutputSize(int len) { - if (_forEncryption) { - return len + _macSize; - } else if (_bufFull) { - return len; - } else { - return max(0, len + _bufOff - _macSize); - } - } - - /// Returns the amount of bytes being outputted - /// by the next [processBytes] for [len] bytes input. - @override - int getUpdateOutputSize(int len) { - if (_forEncryption) { - return len; - } else if (_bufFull) { - return len; - } else { - return max(0, len + _bufOff - _macSize); - } - } - - /// Returns true if provided [match] is equal to this [mac]. - bool _verifyMac(Uint8List match, int off) { - return constantTimeAreEqualOffset(_macSize, mac, 0, match, off); - } - - void _ensureAadMacFinished() { - if (!_aadFinished) { - _cMac - ..doFinal(_aadMac, 0) - ..init(_keyParam) - ..update(Uint8List(_blockSize)..[_blockSize - 1] = _cipherTAG, 0, - _blockSize); - _aadFinished = true; - } - } - - Uint8List get _inMac { - var inMac = Uint8List(_macSize); - for (var i = 0; i < _macSize; i++) { - inMac[i] = _bufBlock[_bufOff + i]; - } - return inMac; - } - - int _buf(Uint8List inp, int inOff, int len, Uint8List out, int outOff) { - var macLen = min(_macSize, len); - var macOff = inOff + len - macLen; - var processed = len - macLen; - - _cMac.update(inp, inOff, processed); - _ctr.processBytes(inp, inOff, processed, out, outOff); - - for (var i = 0; i < macLen; i++) { - if (_bufFull) { - _cMac.updateByte(_bufBlock[_bufOff]); - out[outOff + processed + i] = _ctr.returnByte(_bufBlock[_bufOff]); - processed++; - } - - _bufBlock[_bufOff] = inp[macOff + i]; - - if (_bufOff == _macSize - 1) { - _bufOff = 0; - _bufFull = true; - } else { - _bufOff++; - } - } - return processed; - } - - int _bufByte(int inp) { - var r = 1; - if (_bufFull) { - _cMac.updateByte(_bufBlock[_bufOff]); - _ctr.returnByte(_bufBlock[_bufOff]); - } else { - r = 0; - } - - _bufBlock[_bufOff] = inp; - - if (_bufOff == 15) { - _bufOff = 0; - _bufFull = true; - } else { - _bufOff++; - } - return r; - } - - void _calculateMac() { - mac = Uint8List(_macSize); - for (var i = 0; i < _macSize; i++) { - mac[i] = _nonceMac[i] ^ _aadMac[i] ^ _cipherMac[i]; - } - } -} diff --git a/pointycastle/lib/stream/rc4_engine.dart b/pointycastle/lib/stream/rc4_engine.dart deleted file mode 100644 index dd72c43..0000000 --- a/pointycastle/lib/stream/rc4_engine.dart +++ /dev/null @@ -1,114 +0,0 @@ -library impl.stream_cipher.rc4_engine; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_stream_cipher.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -class RC4Engine extends BaseStreamCipher { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(StreamCipher, 'RC4', () => RC4Engine()); - - static int STATE_LENGTH = 256; - - Uint8List? _engineState; - int _x = 0; - int _y = 0; - late Uint8List _workingKey; - - @override - String get algorithmName => 'RC4'; - - @override - void init(bool forEncryption, CipherParameters? params) { - if (params != null) { - if (params is KeyParameter) { - _workingKey = params.key; - setKey(params.key); - } else { - throw ArgumentError('Parameters of invalid type'); - } - } else { - throw ArgumentError('Missing parameter'); - } - } - - @override - Uint8List process(Uint8List data) { - var out = Uint8List(data.length); - processBytes(data, 0, data.length, out, 0); - return out; - } - - @override - void processBytes( - Uint8List inp, int inpOff, int len, Uint8List out, int outOff) { - if ((inpOff + len) > inp.length) { - throw ArgumentError('input buffer too short'); - } - - if ((outOff + len) > out.length) { - throw ArgumentError('output buffer too short'); - } - - for (var i = 0; i < len; i++) { - _x = (_x + 1) & 0xff; - _y = (_engineState![_x] + _y) & 0xff; - - // swap - var tmp = _engineState![_x]; - _engineState![_x] = _engineState![_y]; - _engineState![_y] = tmp; - - // xor - out[i + outOff] = inp[i + inpOff] ^ - _engineState![(_engineState![_x] + _engineState![_y]) & 0xff]; - } - } - - @override - void reset() { - setKey(_workingKey); - } - - @override - int returnByte(int inp) { - _x = (_x + 1) & 0xff; - _y = (_engineState![_x] + _y) & 0xff; - - // swap - var tmp = _engineState![_x]; - _engineState![_x] = _engineState![_y]; - _engineState![_y] = tmp; - - // xor - return inp ^ _engineState![(_engineState![_x] + _engineState![_y]) & 0xff]; - } - - void setKey(Uint8List keyBytes) { - _workingKey = keyBytes; - - _x = 0; - _y = 0; - - _engineState ??= Uint8List(STATE_LENGTH); - - // reset the state of the engine - for (var i = 0; i < STATE_LENGTH; i++) { - _engineState![i] = i; - } - - var i1 = 0; - var i2 = 0; - - for (var i = 0; i < STATE_LENGTH; i++) { - i2 = ((keyBytes[i1] & 0xff) + _engineState![i] + i2) & 0xff; - // do the byte-swap inline - var tmp = _engineState![i]; - _engineState![i] = _engineState![i2]; - _engineState![i2] = tmp; - i1 = (i1 + 1) % keyBytes.length; - } - } -} diff --git a/pointycastle/lib/stream/salsa20.dart b/pointycastle/lib/stream/salsa20.dart deleted file mode 100644 index d81aa1c..0000000 --- a/pointycastle/lib/stream/salsa20.dart +++ /dev/null @@ -1,195 +0,0 @@ -// See file LICENSE for more information. - -library impl.stream_cipher.salsa20; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_stream_cipher.dart'; -import 'package:pointycastle/src/registry/registry.dart'; -import 'package:pointycastle/src/ufixnum.dart'; - -/// Implementation of Daniel J. Bernstein's Salsa20 stream cipher, Snuffle 2005. -class Salsa20Engine extends BaseStreamCipher { - static final FactoryConfig factoryConfig = - StaticFactoryConfig(StreamCipher, 'Salsa20', () => Salsa20Engine()); - - static const _STATE_SIZE = 16; - - static final _sigma = Uint8List.fromList('expand 32-byte k'.codeUnits); - static final _tau = Uint8List.fromList('expand 16-byte k'.codeUnits); - - Uint8List? _workingKey; - late Uint8List _workingIV; - - final _state = List.filled(_STATE_SIZE, 0, growable: false); - final _buffer = List.filled(_STATE_SIZE, 0, growable: false); - - final _keyStream = Uint8List(_STATE_SIZE * 4); - var _keyStreamOffset = 0; - - var _initialised = false; - - @override - final String algorithmName = 'Salsa20'; - - @override - void reset() { - if (_workingKey != null) { - _setKey(_workingKey!, _workingIV); - } - } - - @override - void init( - bool forEncryption, covariant ParametersWithIV params) { - var uparams = params.parameters; - var iv = params.iv; - if (iv.length != 8) { - throw ArgumentError('Salsa20 requires exactly 8 bytes of IV'); - } - - _workingIV = iv; - _workingKey = uparams!.key; - - _setKey(_workingKey!, _workingIV); - } - - @override - int returnByte(int inp) { - if (_keyStreamOffset == 0) { - _generateKeyStream(_keyStream); - - if (++_state[8] == 0) { - ++_state[9]; - } - } - - var out = clip8(_keyStream[_keyStreamOffset] ^ inp); - _keyStreamOffset = (_keyStreamOffset + 1) & 63; - - return out; - } - - @override - void processBytes( - Uint8List? inp, int inpOff, int len, Uint8List? out, int outOff) { - if (!_initialised) { - throw StateError('Salsa20 not initialized: please call init() first'); - } - - if ((inpOff + len) > inp!.length) { - throw ArgumentError( - 'Input buffer too short or requested length too long'); - } - - if ((outOff + len) > out!.length) { - throw ArgumentError( - 'Output buffer too short or requested length too long'); - } - - for (var i = 0; i < len; i++) { - if (_keyStreamOffset == 0) { - _generateKeyStream(_keyStream); - - if (++_state[8] == 0) { - ++_state[9]; - } - } - - out[i + outOff] = clip8(_keyStream[_keyStreamOffset] ^ inp[i + inpOff]); - _keyStreamOffset = (_keyStreamOffset + 1) & 63; - } - } - - void _setKey(Uint8List keyBytes, Uint8List ivBytes) { - _workingKey = keyBytes; - _workingIV = ivBytes; - - _keyStreamOffset = 0; - var offset = 0; - Uint8List constants; - - // Key - _state[1] = unpack32(_workingKey, 0, Endian.little); - _state[2] = unpack32(_workingKey, 4, Endian.little); - _state[3] = unpack32(_workingKey, 8, Endian.little); - _state[4] = unpack32(_workingKey, 12, Endian.little); - - if (_workingKey!.length == 32) { - constants = _sigma; - offset = 16; - } else { - constants = _tau; - } - - _state[11] = unpack32(_workingKey, offset, Endian.little); - _state[12] = unpack32(_workingKey, offset + 4, Endian.little); - _state[13] = unpack32(_workingKey, offset + 8, Endian.little); - _state[14] = unpack32(_workingKey, offset + 12, Endian.little); - _state[0] = unpack32(constants, 0, Endian.little); - _state[5] = unpack32(constants, 4, Endian.little); - _state[10] = unpack32(constants, 8, Endian.little); - _state[15] = unpack32(constants, 12, Endian.little); - - // IV - _state[6] = unpack32(_workingIV, 0, Endian.little); - _state[7] = unpack32(_workingIV, 4, Endian.little); - _state[8] = _state[9] = 0; - - _initialised = true; - } - - void _generateKeyStream(Uint8List output) { - _salsa20Core(20, _state, _buffer); - var outOff = 0; - for (var x in _buffer) { - pack32(x, output, outOff, Endian.little); - outOff += 4; - } - } - - /// The Salsa20 core function - void _salsa20Core(int rounds, List input, List x) { - x.setAll(0, input); - - for (var i = rounds; i > 0; i -= 2) { - x[4] ^= crotl32(x[0] + x[12], 7); - x[8] ^= crotl32(x[4] + x[0], 9); - x[12] ^= crotl32(x[8] + x[4], 13); - x[0] ^= crotl32(x[12] + x[8], 18); - x[9] ^= crotl32(x[5] + x[1], 7); - x[13] ^= crotl32(x[9] + x[5], 9); - x[1] ^= crotl32(x[13] + x[9], 13); - x[5] ^= crotl32(x[1] + x[13], 18); - x[14] ^= crotl32(x[10] + x[6], 7); - x[2] ^= crotl32(x[14] + x[10], 9); - x[6] ^= crotl32(x[2] + x[14], 13); - x[10] ^= crotl32(x[6] + x[2], 18); - x[3] ^= crotl32(x[15] + x[11], 7); - x[7] ^= crotl32(x[3] + x[15], 9); - x[11] ^= crotl32(x[7] + x[3], 13); - x[15] ^= crotl32(x[11] + x[7], 18); - x[1] ^= crotl32(x[0] + x[3], 7); - x[2] ^= crotl32(x[1] + x[0], 9); - x[3] ^= crotl32(x[2] + x[1], 13); - x[0] ^= crotl32(x[3] + x[2], 18); - x[6] ^= crotl32(x[5] + x[4], 7); - x[7] ^= crotl32(x[6] + x[5], 9); - x[4] ^= crotl32(x[7] + x[6], 13); - x[5] ^= crotl32(x[4] + x[7], 18); - x[11] ^= crotl32(x[10] + x[9], 7); - x[8] ^= crotl32(x[11] + x[10], 9); - x[9] ^= crotl32(x[8] + x[11], 13); - x[10] ^= crotl32(x[9] + x[8], 18); - x[12] ^= crotl32(x[15] + x[14], 7); - x[13] ^= crotl32(x[12] + x[15], 9); - x[14] ^= crotl32(x[13] + x[12], 13); - x[15] ^= crotl32(x[14] + x[13], 18); - } - - for (var i = 0; i < _STATE_SIZE; ++i) { - x[i] = sum32(x[i], input[i]); - } - } -} diff --git a/pointycastle/lib/stream/sic.dart b/pointycastle/lib/stream/sic.dart deleted file mode 100644 index b89c9bb..0000000 --- a/pointycastle/lib/stream/sic.dart +++ /dev/null @@ -1,99 +0,0 @@ -// See file LICENSE for more information. - -library impl.stream_cipher.sic; - -import 'dart:typed_data'; - -import 'package:pointycastle/api.dart'; -import 'package:pointycastle/src/impl/base_stream_cipher.dart'; -import 'package:pointycastle/src/ufixnum.dart'; -import 'package:pointycastle/src/registry/registry.dart'; - -/// Implementation of SIC mode of operation as a [StreamCipher]. This implementation uses the IV as the initial nonce value and -/// keeps incrementing it by 1 for every block. The counter may overflow and rotate, and that would cause a two-time-pad -/// error, but this is so unlikely to happen for usual block sizes that we don't check for that event. It is the responsibility -/// of the caller to make sure the counter does not overflow. -class SICStreamCipher extends BaseStreamCipher { - /// Intended for internal use. - // ignore: non_constant_identifier_names - static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( - StreamCipher, - '/SIC', - (_, final Match match) => () { - var digestName = match.group(1); - return SICStreamCipher(BlockCipher(digestName!)); - }); - - final BlockCipher underlyingCipher; - - late Uint8List _iv; - late Uint8List _counter; - late Uint8List _counterOut; - late int _consumed; - - SICStreamCipher(this.underlyingCipher) { - _iv = Uint8List(underlyingCipher.blockSize); - _counter = Uint8List(underlyingCipher.blockSize); - _counterOut = Uint8List(underlyingCipher.blockSize); - } - - @override - String get algorithmName => '${underlyingCipher.algorithmName}/SIC'; - - @override - void reset() { - underlyingCipher.reset(); - _counter.setAll(0, _iv); - _counterOut.fillRange(0, _counterOut.length, 0); - _consumed = _counterOut.length; - } - - @override - void init(bool forEncryption, covariant ParametersWithIV params) { - _iv.setAll(0, params.iv); - reset(); - underlyingCipher.init(true, params.parameters); - } - - @override - void processBytes( - Uint8List? inp, int inpOff, int len, Uint8List? out, int outOff) { - for (var i = 0; i < len; i++) { - out![outOff + i] = returnByte(inp![inpOff + i]); - } - } - - @override - int returnByte(int inp) { - _feedCounterIfNeeded(); - return clip8(inp) ^ _counterOut[_consumed++]; - } - - /// Calls [_feedCounter] if all [_counterOut] bytes have been consumed - void _feedCounterIfNeeded() { - if (_consumed >= _counterOut.length) { - _feedCounter(); - } - } - - // ignore: slash_for_doc_comments - /// Fills [_counterOut] with a value got from encrypting [_counter] with - /// the _underlyingCipher, resets [_consumed] to 0 and increments the - /// [_counter]. - void _feedCounter() { - underlyingCipher.processBlock(_counter, 0, _counterOut, 0); - _incrementCounter(); - _consumed = 0; - } - - /// Increments [_counter] by 1 - void _incrementCounter() { - int i; - for (i = _counter.lengthInBytes - 1; i >= 0; i--) { - var val = _counter[i]; - val++; - _counter[i] = val; - if (_counter[i] != 0) break; - } - } -} diff --git a/pointycastle/pubspec.yaml b/pointycastle/pubspec.yaml deleted file mode 100644 index c4571de..0000000 --- a/pointycastle/pubspec.yaml +++ /dev/null @@ -1,21 +0,0 @@ -name: pointycastle -version: 4.0.0 -description: A Dart library implementing cryptographic algorithms and primitives, modeled on the BouncyCastle library. -homepage: https://github.com/bcgit/pc-dart -topics: - - crypto - - rsa - - ecc - - asn1 - -environment: - sdk: ^3.2.0 - -dependencies: - collection: ^1.15.0 - convert: ^3.0.0 - -dev_dependencies: - benchmark_harness: ^2.0.0 - lints: ^3.0.0 - test: ^1.16.0 diff --git a/x25519/LICENSE b/x25519/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/x25519/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/x25519/lib/src/curve25519.dart b/x25519/lib/src/curve25519.dart deleted file mode 100644 index d18fb24..0000000 --- a/x25519/lib/src/curve25519.dart +++ /dev/null @@ -1,944 +0,0 @@ -import 'package:adaptive_number/adaptive_number.dart'; -import 'package:x25519/src/numbers.dart'; - -class FieldElement { - late List innerList; - FieldElement() { - innerList = List.generate(10, (index) => Number.zero); - } - FieldElement.fromList(List list) { - innerList = list; - } - - Number operator [](int index) { - return innerList[index]; - } - - void operator []=(int index, Number value) { - innerList[index] = value; - } - - int get length => innerList.length; -} - -void fieldElementCopy( - FieldElement src, int srcPos, FieldElement dest, int destPos, int length) { - dest.innerList.setRange(destPos, length + destPos, src.innerList, srcPos); -} - -void fieldElementFullCopy(FieldElement src, FieldElement dest) { - fieldElementCopy(src, 0, dest, 0, dest.length); -} - -var zero = FieldElement(); - -void FeZero(FieldElement fe) { - fieldElementFullCopy(zero, fe); -} - -void FeOne(FieldElement fe) { - FeZero(fe); - fe[0] = Number.one; -} - -void FeAdd(FieldElement dst, FieldElement a, FieldElement b) { - dst[0] = a[0] + b[0]; - dst[1] = a[1] + b[1]; - dst[2] = a[2] + b[2]; - dst[3] = a[3] + b[3]; - dst[4] = a[4] + b[4]; - dst[5] = a[5] + b[5]; - dst[6] = a[6] + b[6]; - dst[7] = a[7] + b[7]; - dst[8] = a[8] + b[8]; - dst[9] = a[9] + b[9]; -} - -void FeSub(FieldElement dst, FieldElement a, FieldElement b) { - dst[0] = a[0] - b[0]; - dst[1] = a[1] - b[1]; - dst[2] = a[2] - b[2]; - dst[3] = a[3] - b[3]; - dst[4] = a[4] - b[4]; - dst[5] = a[5] - b[5]; - dst[6] = a[6] - b[6]; - dst[7] = a[7] - b[7]; - dst[8] = a[8] - b[8]; - dst[9] = a[9] - b[9]; -} - -void FeCopy(FieldElement dst, FieldElement src) { - fieldElementFullCopy(src, dst); -} - -// feCSwap replaces (f,g) with (g,f) if b == 1; replaces (f,g) with (f,g) if b == 0. -// -// Preconditions: b in {0,1}. -void feCSwap(FieldElement f, FieldElement g, Number b) { - b = -b; - for (var i = 0; i < f.length; i++) { - var t = b & (f[i] ^ g[i]); - f[i] ^= t; - g[i] ^= t; - } -} - -// load3 reads a 24-bit, little-endian value from in. -Number load3(List input) { - var r; - r = input[0]; - r |= input[1] << 8; - r |= input[2] << 16; - return Number(r); -} - -// load4 reads a 32-bit, little-endian value from in. -Number load4(List input) { - int r; - r = input[0]; - r |= input[1] << 8; - r |= input[2] << 16; - r |= input[3] << 24; - return Number(r); -} - -void feFromBytes(FieldElement dst, List src) { - var h0 = load4(src.sublist(0, src.length)); - var h1 = load3(src.sublist(4, src.length)) << 6; - var h2 = load3(src.sublist(7, src.length)) << 5; - var h3 = load3(src.sublist(10, src.length)) << 3; - var h4 = load3(src.sublist(13, src.length)) << 2; - var h5 = load4(src.sublist(16, src.length)); - var h6 = load3(src.sublist(20, src.length)) << 7; - var h7 = load3(src.sublist(23, src.length)) << 5; - var h8 = load3(src.sublist(26, src.length)) << 4; - var h9 = (load3(src.sublist(29, src.length)) & Numbers.v0x7fffff) << 2; - - var carry = List.filled(10, Number.zero); - carry[9] = (h9 + (Number.one << 24)) >> 25; - h0 += carry[9] * Numbers.v19; - h9 -= carry[9] << 25; - carry[1] = (h1 + (Number.one << 24)) >> 25; - h2 += carry[1]; - h1 -= carry[1] << 25; - carry[3] = (h3 + (Number.one << 24)) >> 25; - h4 += carry[3]; - h3 -= carry[3] << 25; - carry[5] = (h5 + (Number.one << 24)) >> 25; - h6 += carry[5]; - h5 -= carry[5] << 25; - carry[7] = (h7 + (Number.one << 24)) >> 25; - h8 += carry[7]; - h7 -= carry[7] << 25; - - carry[0] = (h0 + (Number.one << 25)) >> 26; - h1 += carry[0]; - h0 -= carry[0] << 26; - carry[2] = (h2 + (Number.one << 25)) >> 26; - h3 += carry[2]; - h2 -= carry[2] << 26; - carry[4] = (h4 + (Number.one << 25)) >> 26; - h5 += carry[4]; - h4 -= carry[4] << 26; - carry[6] = (h6 + (Number.one << 25)) >> 26; - h7 += carry[6]; - h6 -= carry[6] << 26; - carry[8] = (h8 + (Number.one << 25)) >> 26; - h9 += carry[8]; - h8 -= carry[8] << 26; - - dst[0] = h0; - dst[1] = h1; - dst[2] = h2; - dst[3] = h3; - dst[4] = h4; - dst[5] = h5; - dst[6] = h6; - dst[7] = h7; - dst[8] = h8; - dst[9] = h9; -} - -/// FeToBytes marshals h to s. -/// Preconditions: -/// |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. -/// -/// Write p=2^255-19; q=floor(h/p). -/// Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))). -/// -/// Proof: -/// Have |h|<=p so |q|<=1 so |19^2 2^(-255) q|<1/4. -/// Also have |h-2^230 h9|<2^230 so |19 2^(-255)(h-2^230 h9)|<1/4. -/// -/// Write y=2^(-1)-19^2 2^(-255)q-19 2^(-255)(h-2^230 h9). -/// Then 0 s, FieldElement h) { - var carry = List.filled(10, Number.zero); - - var q = (Numbers.v19 * h[9] + (Number.one << 24)) >> 25; - q = (h[0] + q) >> 26; - q = (h[1] + q) >> 25; - q = (h[2] + q) >> 26; - q = (h[3] + q) >> 25; - q = (h[4] + q) >> 26; - q = (h[5] + q) >> 25; - q = (h[6] + q) >> 26; - q = (h[7] + q) >> 25; - q = (h[8] + q) >> 26; - q = (h[9] + q) >> 25; - - // Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20. - h[0] += Numbers.v19 * q; - // Goal: Output h-2^255 q, which is between 0 and 2^255-20. - - carry[0] = h[0] >> 26; - h[1] += carry[0]; - h[0] -= carry[0] << 26; - carry[1] = h[1] >> 25; - h[2] += carry[1]; - h[1] -= carry[1] << 25; - carry[2] = h[2] >> 26; - h[3] += carry[2]; - h[2] -= carry[2] << 26; - carry[3] = h[3] >> 25; - h[4] += carry[3]; - h[3] -= carry[3] << 25; - carry[4] = h[4] >> 26; - h[5] += carry[4]; - h[4] -= carry[4] << 26; - carry[5] = h[5] >> 25; - h[6] += carry[5]; - h[5] -= carry[5] << 25; - carry[6] = h[6] >> 26; - h[7] += carry[6]; - h[6] -= carry[6] << 26; - carry[7] = h[7] >> 25; - h[8] += carry[7]; - h[7] -= carry[7] << 25; - carry[8] = h[8] >> 26; - h[9] += carry[8]; - h[8] -= carry[8] << 26; - carry[9] = h[9] >> 25; - h[9] -= carry[9] << 25; - // h10 = carry9 - - // Goal: Output h[0]+...+2^255 h10-2^255 q, which is between 0 and 2^255-20. - // Have h[0]+...+2^230 h[9] between 0 and 2^255-1; - // evidently 2^255 h10-2^255 q = 0. - // Goal: Output h[0]+...+2^230 h[9]. - - s[0] = (h[0] >> 0).intValue; - s[1] = (h[0] >> 8).intValue; - s[2] = (h[0] >> 16).intValue; - s[3] = ((h[0] >> 24) | (h[1] << 2)).intValue; - s[4] = (h[1] >> 6).intValue; - s[5] = (h[1] >> 14).intValue; - s[6] = ((h[1] >> 22) | (h[2] << 3)).intValue; - s[7] = (h[2] >> 5).intValue; - s[8] = (h[2] >> 13).intValue; - s[9] = ((h[2] >> 21) | (h[3] << 5)).intValue; - s[10] = (h[3] >> 3).intValue; - s[11] = (h[3] >> 11).intValue; - s[12] = ((h[3] >> 19) | (h[4] << 6)).intValue; - s[13] = (h[4] >> 2).intValue; - s[14] = (h[4] >> 10).intValue; - s[15] = (h[4] >> 18).intValue; - s[16] = (h[5] >> 0).intValue; - s[17] = (h[5] >> 8).intValue; - s[18] = (h[5] >> 16).intValue; - s[19] = ((h[5] >> 24) | (h[6] << 1)).intValue; - s[20] = (h[6] >> 7).intValue; - s[21] = (h[6] >> 15).intValue; - s[22] = ((h[6] >> 23) | (h[7] << 3)).intValue; - s[23] = (h[7] >> 5).intValue; - s[24] = (h[7] >> 13).intValue; - s[25] = ((h[7] >> 21) | (h[8] << 4)).intValue; - s[26] = (h[8] >> 4).intValue; - s[27] = (h[8] >> 12).intValue; - s[28] = ((h[8] >> 20) | (h[9] << 6)).intValue; - s[29] = (h[9] >> 2).intValue; - s[30] = (h[9] >> 10).intValue; - s[31] = (h[9] >> 18).intValue; -} - -/// feMul calculates h = f * g -/// Can overlap h with f or g. -/// -/// Preconditions: -/// |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. -/// |g| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. -/// -/// Postconditions: -/// |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. -/// -/// Notes on implementation strategy: -/// -/// Using schoolbook multiplication. -/// Karatsuba would save a little in some cost models. -/// -/// Most multiplications by 2 and 19 are 32-bit precomputations; -/// cheaper than 64-bit postcomputations. -/// -/// There is one remaining multiplication by 19 in the carry chain; -/// one *19 precomputation can be merged into this, -/// but the resulting data flow is considerably less clean. -/// -/// There are 12 carries below. -/// 10 of them are 2-way parallelizable and vectorizable. -/// Can get away with 11 carries, but then data flow is much deeper. -/// -/// With tighter constraints on inputs can squeeze carries into int32. -void feMul(FieldElement h, FieldElement f, FieldElement g) { - var f0 = f[0]; - var f1 = f[1]; - var f2 = f[2]; - var f3 = f[3]; - var f4 = f[4]; - var f5 = f[5]; - var f6 = f[6]; - var f7 = f[7]; - var f8 = f[8]; - var f9 = f[9]; - var g0 = g[0]; - var g1 = g[1]; - var g2 = g[2]; - var g3 = g[3]; - var g4 = g[4]; - var g5 = g[5]; - var g6 = g[6]; - var g7 = g[7]; - var g8 = g[8]; - var g9 = g[9]; - var g1_19 = Numbers.v19 * g[1]; /* 1.4*2^29 */ - var g2_19 = Numbers.v19 * g[2]; /* 1.4*2^30; still ok */ - var g3_19 = Numbers.v19 * g[3]; - var g4_19 = Numbers.v19 * g[4]; - var g5_19 = Numbers.v19 * g[5]; - var g6_19 = Numbers.v19 * g[6]; - var g7_19 = Numbers.v19 * g[7]; - var g8_19 = Numbers.v19 * g[8]; - var g9_19 = Numbers.v19 * g[9]; - var f1_2 = Number.two * f[1]; - var f3_2 = Number.two * f[3]; - var f5_2 = Number.two * f[5]; - var f7_2 = Number.two * f[7]; - var f9_2 = Number.two * f[9]; - var f0g0 = f0 * g0; - var f0g1 = f0 * g1; - var f0g2 = f0 * g2; - var f0g3 = f0 * g3; - var f0g4 = f0 * g4; - var f0g5 = f0 * g5; - var f0g6 = f0 * g6; - var f0g7 = f0 * g7; - var f0g8 = f0 * g8; - var f0g9 = f0 * g9; - var f1g0 = f1 * g0; - var f1g1_2 = f1_2 * g1; - var f1g2 = f1 * g2; - var f1g3_2 = f1_2 * g3; - var f1g4 = f1 * g4; - var f1g5_2 = f1_2 * g5; - var f1g6 = f1 * g6; - var f1g7_2 = f1_2 * g7; - var f1g8 = f1 * g8; - var f1g9_38 = f1_2 * g9_19; - var f2g0 = f2 * g0; - var f2g1 = f2 * g1; - var f2g2 = f2 * g2; - var f2g3 = f2 * g3; - var f2g4 = f2 * g4; - var f2g5 = f2 * g5; - var f2g6 = f2 * g6; - var f2g7 = f2 * g7; - var f2g8_19 = f2 * g8_19; - var f2g9_19 = f2 * g9_19; - var f3g0 = f3 * g0; - var f3g1_2 = f3_2 * g1; - var f3g2 = f3 * g2; - var f3g3_2 = f3_2 * g3; - var f3g4 = f3 * g4; - var f3g5_2 = f3_2 * g5; - var f3g6 = f3 * g6; - var f3g7_38 = f3_2 * g7_19; - var f3g8_19 = f3 * g8_19; - var f3g9_38 = f3_2 * g9_19; - var f4g0 = f4 * g0; - var f4g1 = f4 * g1; - var f4g2 = f4 * g2; - var f4g3 = f4 * g3; - var f4g4 = f4 * g4; - var f4g5 = f4 * g5; - var f4g6_19 = f4 * g6_19; - var f4g7_19 = f4 * g7_19; - var f4g8_19 = f4 * g8_19; - var f4g9_19 = f4 * g9_19; - var f5g0 = f5 * g0; - var f5g1_2 = f5_2 * g1; - var f5g2 = f5 * g2; - var f5g3_2 = f5_2 * g3; - var f5g4 = f5 * g4; - var f5g5_38 = f5_2 * g5_19; - var f5g6_19 = f5 * g6_19; - var f5g7_38 = f5_2 * g7_19; - var f5g8_19 = f5 * g8_19; - var f5g9_38 = f5_2 * g9_19; - var f6g0 = f6 * g0; - var f6g1 = f6 * g1; - var f6g2 = f6 * g2; - var f6g3 = f6 * g3; - var f6g4_19 = f6 * g4_19; - var f6g5_19 = f6 * g5_19; - var f6g6_19 = f6 * g6_19; - var f6g7_19 = f6 * g7_19; - var f6g8_19 = f6 * g8_19; - var f6g9_19 = f6 * g9_19; - var f7g0 = f7 * g0; - var f7g1_2 = f7_2 * g1; - var f7g2 = f7 * g2; - var f7g3_38 = f7_2 * g3_19; - var f7g4_19 = f7 * g4_19; - var f7g5_38 = f7_2 * g5_19; - var f7g6_19 = f7 * g6_19; - var f7g7_38 = f7_2 * g7_19; - var f7g8_19 = f7 * g8_19; - var f7g9_38 = f7_2 * g9_19; - var f8g0 = f8 * g0; - var f8g1 = f8 * g1; - var f8g2_19 = f8 * g2_19; - var f8g3_19 = f8 * g3_19; - var f8g4_19 = f8 * g4_19; - var f8g5_19 = f8 * g5_19; - var f8g6_19 = f8 * g6_19; - var f8g7_19 = f8 * g7_19; - var f8g8_19 = f8 * g8_19; - var f8g9_19 = f8 * g9_19; - var f9g0 = f9 * g0; - var f9g1_38 = f9_2 * g1_19; - var f9g2_19 = f9 * g2_19; - var f9g3_38 = f9_2 * g3_19; - var f9g4_19 = f9 * g4_19; - var f9g5_38 = f9_2 * g5_19; - var f9g6_19 = f9 * g6_19; - var f9g7_38 = f9_2 * g7_19; - var f9g8_19 = f9 * g8_19; - var f9g9_38 = f9_2 * g9_19; - var h0 = f0g0 + - f1g9_38 + - f2g8_19 + - f3g7_38 + - f4g6_19 + - f5g5_38 + - f6g4_19 + - f7g3_38 + - f8g2_19 + - f9g1_38; - var h1 = f0g1 + - f1g0 + - f2g9_19 + - f3g8_19 + - f4g7_19 + - f5g6_19 + - f6g5_19 + - f7g4_19 + - f8g3_19 + - f9g2_19; - var h2 = f0g2 + - f1g1_2 + - f2g0 + - f3g9_38 + - f4g8_19 + - f5g7_38 + - f6g6_19 + - f7g5_38 + - f8g4_19 + - f9g3_38; - var h3 = f0g3 + - f1g2 + - f2g1 + - f3g0 + - f4g9_19 + - f5g8_19 + - f6g7_19 + - f7g6_19 + - f8g5_19 + - f9g4_19; - var h4 = f0g4 + - f1g3_2 + - f2g2 + - f3g1_2 + - f4g0 + - f5g9_38 + - f6g8_19 + - f7g7_38 + - f8g6_19 + - f9g5_38; - var h5 = f0g5 + - f1g4 + - f2g3 + - f3g2 + - f4g1 + - f5g0 + - f6g9_19 + - f7g8_19 + - f8g7_19 + - f9g6_19; - var h6 = f0g6 + - f1g5_2 + - f2g4 + - f3g3_2 + - f4g2 + - f5g1_2 + - f6g0 + - f7g9_38 + - f8g8_19 + - f9g7_38; - var h7 = - f0g7 + f1g6 + f2g5 + f3g4 + f4g3 + f5g2 + f6g1 + f7g0 + f8g9_19 + f9g8_19; - var h8 = f0g8 + - f1g7_2 + - f2g6 + - f3g5_2 + - f4g4 + - f5g3_2 + - f6g2 + - f7g1_2 + - f8g0 + - f9g9_38; - var h9 = f0g9 + f1g8 + f2g7 + f3g6 + f4g5 + f5g4 + f6g3 + f7g2 + f8g1 + f9g0; - - var carry = List.filled(10, Number.zero); - -// |h0| <= (1.1*1.1*2^52*(1+19+19+19+19)+1.1*1.1*2^50*(38+38+38+38+38)) -// i.e. |h0| <= 1.2*2^59; narrower ranges for h2, h4, h6, h8 -// |h1| <= (1.1*1.1*2^51*(1+1+19+19+19+19+19+19+19+19)) -// i.e. |h1| <= 1.5*2^58; narrower ranges for h3, h5, h7, h9 - - carry[0] = (h0 + (Number.one << 25)) >> 26; - h1 += carry[0]; - h0 -= carry[0] << 26; - carry[4] = (h4 + (Number.one << 25)) >> 26; - h5 += carry[4]; - h4 -= carry[4] << 26; -// |h0| <= 2^25 -// |h4| <= 2^25 -// |h1| <= 1.51*2^58 -// |h5| <= 1.51*2^58 - - carry[1] = (h1 + (Number.one << 24)) >> 25; - h2 += carry[1]; - h1 -= carry[1] << 25; - carry[5] = (h5 + (Number.one << 24)) >> 25; - h6 += carry[5]; - h5 -= carry[5] << 25; -// |h1| <= 2^24; from now on fits into int32 -// |h5| <= 2^24; from now on fits into int32 -// |h2| <= 1.21*2^59 -// |h6| <= 1.21*2^59 - - carry[2] = (h2 + (Number.one << 25)) >> 26; - h3 += carry[2]; - h2 -= carry[2] << 26; - carry[6] = (h6 + (Number.one << 25)) >> 26; - h7 += carry[6]; - h6 -= carry[6] << 26; -// |h2| <= 2^25; from now on fits into int32 unchanged -// |h6| <= 2^25; from now on fits into int32 unchanged -// |h3| <= 1.51*2^58 -// |h7| <= 1.51*2^58 - - carry[3] = (h3 + (Number.one << 24)) >> 25; - h4 += carry[3]; - h3 -= carry[3] << 25; - carry[7] = (h7 + (Number.one << 24)) >> 25; - h8 += carry[7]; - h7 -= carry[7] << 25; -// |h3| <= 2^24; from now on fits into int32 unchanged -// |h7| <= 2^24; from now on fits into int32 unchanged -// |h4| <= 1.52*2^33 -// |h8| <= 1.52*2^33 - - carry[4] = (h4 + (Number.one << 25)) >> 26; - h5 += carry[4]; - h4 -= carry[4] << 26; - carry[8] = (h8 + (Number.one << 25)) >> 26; - h9 += carry[8]; - h8 -= carry[8] << 26; -// |h4| <= 2^25; from now on fits into int32 unchanged -// |h8| <= 2^25; from now on fits into int32 unchanged -// |h5| <= 1.01*2^24 -// |h9| <= 1.51*2^58 - - carry[9] = (h9 + (Number.one << 24)) >> 25; - h0 += carry[9] * Numbers.v19; - h9 -= carry[9] << 25; -// |h9| <= 2^24; from now on fits into int32 unchanged -// |h0| <= 1.8*2^37 - - carry[0] = (h0 + (Number.one << 25)) >> 26; - h1 += carry[0]; - h0 -= carry[0] << 26; -// |h0| <= 2^25; from now on fits into int32 unchanged -// |h1| <= 1.01*2^24 - - h[0] = h0; - h[1] = h1; - h[2] = h2; - h[3] = h3; - h[4] = h4; - h[5] = h5; - h[6] = h6; - h[7] = h7; - h[8] = h8; - h[9] = h9; -} - -/// feSquare calculates h = f*f. Can overlap h with f. -/// -/// Preconditions: -/// |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. -/// -/// Postconditions: -/// |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. -void feSquare(FieldElement h, FieldElement f) { - var f0 = f[0]; - var f1 = f[1]; - var f2 = f[2]; - var f3 = f[3]; - var f4 = f[4]; - var f5 = f[5]; - var f6 = f[6]; - var f7 = f[7]; - var f8 = f[8]; - var f9 = f[9]; - var f0_2 = Number.two * f0; - var f1_2 = Number.two * f1; - var f2_2 = Number.two * f2; - var f3_2 = Number.two * f3; - var f4_2 = Number.two * f4; - var f5_2 = Number.two * f5; - var f6_2 = Number.two * f6; - var f7_2 = Number.two * f7; - var f5_38 = Numbers.v38 * f5; // 1.31*2^30 - var f6_19 = Numbers.v19 * f6; // 1.31*2^30 - var f7_38 = Numbers.v38 * f7; // 1.31*2^30 - var f8_19 = Numbers.v19 * f8; // 1.31*2^30 - var f9_38 = Numbers.v38 * f9; // 1.31*2^30 - var f0f0 = f0 * f0; - var f0f1_2 = f0_2 * f1; - var f0f2_2 = f0_2 * f2; - var f0f3_2 = f0_2 * f3; - var f0f4_2 = f0_2 * f4; - var f0f5_2 = f0_2 * f5; - var f0f6_2 = f0_2 * f6; - var f0f7_2 = f0_2 * f7; - var f0f8_2 = f0_2 * f8; - var f0f9_2 = f0_2 * f9; - var f1f1_2 = f1_2 * f1; - var f1f2_2 = f1_2 * f2; - var f1f3_4 = f1_2 * f3_2; - var f1f4_2 = f1_2 * f4; - var f1f5_4 = f1_2 * f5_2; - var f1f6_2 = f1_2 * f6; - var f1f7_4 = f1_2 * f7_2; - var f1f8_2 = f1_2 * f8; - var f1f9_76 = f1_2 * f9_38; - var f2f2 = f2 * f2; - var f2f3_2 = f2_2 * f3; - var f2f4_2 = f2_2 * f4; - var f2f5_2 = f2_2 * f5; - var f2f6_2 = f2_2 * f6; - var f2f7_2 = f2_2 * f7; - var f2f8_38 = f2_2 * f8_19; - var f2f9_38 = f2 * f9_38; - var f3f3_2 = f3_2 * f3; - var f3f4_2 = f3_2 * f4; - var f3f5_4 = f3_2 * f5_2; - var f3f6_2 = f3_2 * f6; - var f3f7_76 = f3_2 * f7_38; - var f3f8_38 = f3_2 * f8_19; - var f3f9_76 = f3_2 * f9_38; - var f4f4 = f4 * f4; - var f4f5_2 = f4_2 * f5; - var f4f6_38 = f4_2 * f6_19; - var f4f7_38 = f4 * f7_38; - var f4f8_38 = f4_2 * f8_19; - var f4f9_38 = f4 * f9_38; - var f5f5_38 = f5 * f5_38; - var f5f6_38 = f5_2 * f6_19; - var f5f7_76 = f5_2 * f7_38; - var f5f8_38 = f5_2 * f8_19; - var f5f9_76 = f5_2 * f9_38; - var f6f6_19 = f6 * f6_19; - var f6f7_38 = f6 * f7_38; - var f6f8_38 = f6_2 * f8_19; - var f6f9_38 = f6 * f9_38; - var f7f7_38 = f7 * f7_38; - var f7f8_38 = f7_2 * f8_19; - var f7f9_76 = f7_2 * f9_38; - var f8f8_19 = f8 * f8_19; - var f8f9_38 = f8 * f9_38; - var f9f9_38 = f9 * f9_38; - var h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38; - var h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38; - var h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19; - var h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38; - var h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38; - var h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38; - var h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19; - var h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38; - var h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38; - var h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2; - var carry = List.filled(10, Number.zero); - - carry[0] = (h0 + (Number.one << 25)) >> 26; - h1 += carry[0]; - h0 -= carry[0] << 26; - carry[4] = (h4 + (Number.one << 25)) >> 26; - h5 += carry[4]; - h4 -= carry[4] << 26; - - carry[1] = (h1 + (Number.one << 24)) >> 25; - h2 += carry[1]; - h1 -= carry[1] << 25; - carry[5] = (h5 + (Number.one << 24)) >> 25; - h6 += carry[5]; - h5 -= carry[5] << 25; - - carry[2] = (h2 + (Number.one << 25)) >> 26; - h3 += carry[2]; - h2 -= carry[2] << 26; - carry[6] = (h6 + (Number.one << 25)) >> 26; - h7 += carry[6]; - h6 -= carry[6] << 26; - - carry[3] = (h3 + (Number.one << 24)) >> 25; - h4 += carry[3]; - h3 -= carry[3] << 25; - carry[7] = (h7 + (Number.one << 24)) >> 25; - h8 += carry[7]; - h7 -= carry[7] << 25; - - carry[4] = (h4 + (Number.one << 25)) >> 26; - h5 += carry[4]; - h4 -= carry[4] << 26; - carry[8] = (h8 + (Number.one << 25)) >> 26; - h9 += carry[8]; - h8 -= carry[8] << 26; - - carry[9] = (h9 + (Number.one << 24)) >> 25; - h0 += carry[9] * Numbers.v19; - h9 -= carry[9] << 25; - - carry[0] = (h0 + (Number.one << 25)) >> 26; - h1 += carry[0]; - h0 -= carry[0] << 26; - - h[0] = h0; - h[1] = h1; - h[2] = h2; - h[3] = h3; - h[4] = h4; - h[5] = h5; - h[6] = h6; - h[7] = h7; - h[8] = h8; - h[9] = h9; -} - -/// feMul121666 calculates h = f * 121666. Can overlap h with f. -/// -/// Preconditions: -/// |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. -/// -/// Postconditions: -/// |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. -void feMul121666(FieldElement h, FieldElement f) { - var h0 = f[0] * Numbers.v121666; - var h1 = f[1] * Numbers.v121666; - var h2 = f[2] * Numbers.v121666; - var h3 = f[3] * Numbers.v121666; - var h4 = f[4] * Numbers.v121666; - var h5 = f[5] * Numbers.v121666; - var h6 = f[6] * Numbers.v121666; - var h7 = f[7] * Numbers.v121666; - var h8 = f[8] * Numbers.v121666; - var h9 = f[9] * Numbers.v121666; - var carry = List.filled(10, Number.zero); - - carry[9] = (h9 + (Number.one << 24)) >> 25; - h0 += carry[9] * Numbers.v19; - h9 -= carry[9] << 25; - carry[1] = (h1 + (Number.one << 24)) >> 25; - h2 += carry[1]; - h1 -= carry[1] << 25; - carry[3] = (h3 + (Number.one << 24)) >> 25; - h4 += carry[3]; - h3 -= carry[3] << 25; - carry[5] = (h5 + (Number.one << 24)) >> 25; - h6 += carry[5]; - h5 -= carry[5] << 25; - carry[7] = (h7 + (Number.one << 24)) >> 25; - h8 += carry[7]; - h7 -= carry[7] << 25; - - carry[0] = (h0 + (Number.one << 25)) >> 26; - h1 += carry[0]; - h0 -= carry[0] << 26; - carry[2] = (h2 + (Number.one << 25)) >> 26; - h3 += carry[2]; - h2 -= carry[2] << 26; - carry[4] = (h4 + (Number.one << 25)) >> 26; - h5 += carry[4]; - h4 -= carry[4] << 26; - carry[6] = (h6 + (Number.one << 25)) >> 26; - h7 += carry[6]; - h6 -= carry[6] << 26; - carry[8] = (h8 + (Number.one << 25)) >> 26; - h9 += carry[8]; - h8 -= carry[8] << 26; - - h[0] = h0; - h[1] = h1; - h[2] = h2; - h[3] = h3; - h[4] = h4; - h[5] = h5; - h[6] = h6; - h[7] = h7; - h[8] = h8; - h[9] = h9; -} - -/// feInvert sets out = z^-1. -void feInvert(FieldElement out, FieldElement z) { - var t0 = FieldElement(); - var t1 = FieldElement(); - var t2 = FieldElement(); - var t3 = FieldElement(); - var i = 0; - - feSquare(t0, z); - for (i = 1; i < 1; i++) { - feSquare(t0, t0); - } - feSquare(t1, t0); - for (i = 1; i < 2; i++) { - feSquare(t1, t1); - } - feMul(t1, z, t1); - feMul(t0, t0, t1); - feSquare(t2, t0); - for (i = 1; i < 1; i++) { - feSquare(t2, t2); - } - feMul(t1, t1, t2); - feSquare(t2, t1); - for (i = 1; i < 5; i++) { - feSquare(t2, t2); - } - feMul(t1, t2, t1); - feSquare(t2, t1); - for (i = 1; i < 10; i++) { - feSquare(t2, t2); - } - feMul(t2, t2, t1); - feSquare(t3, t2); - for (i = 1; i < 20; i++) { - feSquare(t3, t3); - } - feMul(t2, t3, t2); - feSquare(t2, t2); - for (i = 1; i < 10; i++) { - feSquare(t2, t2); - } - feMul(t1, t2, t1); - feSquare(t2, t1); - for (i = 1; i < 50; i++) { - feSquare(t2, t2); - } - feMul(t2, t2, t1); - feSquare(t3, t2); - for (i = 1; i < 100; i++) { - feSquare(t3, t3); - } - feMul(t2, t3, t2); - feSquare(t2, t2); - for (i = 1; i < 50; i++) { - feSquare(t2, t2); - } - feMul(t1, t2, t1); - feSquare(t1, t1); - for (i = 1; i < 5; i++) { - feSquare(t1, t1); - } - feMul(out, t1, t0); -} - -void scalarMultGeneric(List out, List input, List base) { - var e = List.filled(32, Number.zero); - - e.setRange(0, e.length, input.map((e) => Number(e)).toList()); - e[0] &= Numbers.v248; - e[31] &= Numbers.v127; - e[31] |= Numbers.v64; - - var x1 = FieldElement(); - var x2 = FieldElement(); - var z2 = FieldElement(); - var x3 = FieldElement(); - var z3 = FieldElement(); - var tmp0 = FieldElement(); - var tmp1 = FieldElement(); - - feFromBytes(x1, base); - FeOne(x2); - FeCopy(x3, x1); - FeOne(z3); - - var swap = Number.zero; - for (var pos = 254; pos >= 0; pos--) { - var b = e[pos ~/ 8] >> (pos & 7); - b &= Number.one; - swap ^= b; - feCSwap(x2, x3, swap); - feCSwap(z2, z3, swap); - swap = b; - - FeSub(tmp0, x3, z3); - FeSub(tmp1, x2, z2); - FeAdd(x2, x2, z2); - FeAdd(z2, x3, z3); - feMul(z3, tmp0, x2); - feMul(z2, z2, tmp1); - feSquare(tmp0, tmp1); - feSquare(tmp1, x2); - FeAdd(x3, z3, z2); - FeSub(z2, z3, z2); - feMul(x2, tmp1, tmp0); - FeSub(tmp1, tmp1, tmp0); - feSquare(z2, z2); - feMul121666(z3, tmp1); - feSquare(x3, x3); - FeAdd(tmp0, tmp0, z3); - feMul(z3, x1, z2); - feMul(z2, tmp1, tmp0); - } - - feCSwap(x2, x3, swap); - feCSwap(z2, z3, swap); - - feInvert(z2, z2); - feMul(x2, x2, z2); - FeToBytes(out, x2); -} diff --git a/x25519/lib/src/numbers.dart b/x25519/lib/src/numbers.dart deleted file mode 100644 index 43f36a7..0000000 --- a/x25519/lib/src/numbers.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:adaptive_number/adaptive_number.dart'; - -abstract class Numbers { - static Number v19 = Number(19); - static Number v38 = Number(38); - static Number v64 = Number(64); - static Number v127 = Number(127); - static Number v248 = Number(248); - static Number v121666 = Number(121666); - static Number v0x7fffff = Number(0x7fffff); -} diff --git a/x25519/lib/x25519.dart b/x25519/lib/x25519.dart deleted file mode 100644 index 5ea48d1..0000000 --- a/x25519/lib/x25519.dart +++ /dev/null @@ -1,180 +0,0 @@ -/// Package curve25519 provides an implementation of the X25519 function, which -/// performs scalar multiplication on the elliptic curve known as Curve25519. -/// See RFC 7748. -library x25519; - -import 'dart:math'; -import 'dart:typed_data'; - -import 'package:collection/collection.dart'; -import 'package:x25519/src/curve25519.dart' as curve; - -/// ScalarSize is the size of the scalar input to X25519. -const ScalarSize = 32; - -/// PointSize is the size of the point input to X25519. -const PointSize = 32; - -final _random = Random.secure(); - -/// KeyPair is the type of Curve25519 public/private key pair. -class KeyPair { - final List privateKey; - - final List publicKey; - - KeyPair({required this.privateKey, required this.publicKey}); - - @override - int get hashCode => publicKey.hashCode; - - @override - bool operator ==(other) => - other is KeyPair && - publicKey == other.publicKey && - privateKey == other.privateKey; -} - -/// GenerateKey generates a public/private key pair using entropy from secure random. -KeyPair generateKeyPair() { - var private = List.generate(ScalarSize, (i) => _random.nextInt(256)); - var public = List.filled(32, 0); - - private[0] &= 248; - private[31] &= 127; - private[31] |= 64; - - ScalarBaseMult(public, private); - - return KeyPair(privateKey: private, publicKey: Uint8List.fromList(public)); -} - -/// ScalarMult sets dst to the product scalar * point. -/// -/// Deprecated: when provided a low-order point, ScalarMult will set dst to all -/// zeroes, irrespective of the scalar. Instead, use the X25519 function, which -/// will return an error. -void ScalarMult(List dst, List scalar, List point) { - curve.scalarMultGeneric(dst, scalar, point); -} - -/// ScalarBaseMult sets dst to the product scalar * base where base is the -/// standard generator. -/// -/// It is recommended to use the X25519 function with Basepoint instead, as -/// copying into fixed size arrays can lead to unexpected bugs. -void ScalarBaseMult(List dst, List scalar) { - curve.scalarMultGeneric(dst, scalar, basePoint); -} - -var basePoint = List.from([ - 9, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 -]); - -void checkBasepoint() { - ListEquality().equals(basePoint, [ - 0x09, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - ]); -} - -/// X25519 returns the result of the scalar multiplication (scalar * point), -/// according to RFC 7748, Section 5. scalar, point and the return value are -/// slices of 32 bytes. -/// -/// scalar can be generated at random, for example with crypto/rand. point should -/// be either Basepoint or the output of another X25519 call. -/// -/// If point is Basepoint (but not if it's a different slice with the same -/// contents) a precomputed implementation might be used for performance. -Uint8List X25519(List scalar, List point) { - /// Outline the body of function, to let the allocation be inlined in the - /// caller, and possibly avoid escaping to the heap. - var dst = List.filled(32, 0); - return x25519(dst, scalar, point); -} - -Uint8List x25519(List dst, List scalar, List point) { - var input = List.filled(32, 0); - if (scalar.length != 32) { - throw ArgumentError('bad scalar length: ${scalar.length}, expected 32'); - } - if (point.length != 32) { - throw ArgumentError('bad scalar length: ${point.length}, expected 32'); - } - input.setRange(0, input.length, scalar); - if (identical(point, basePoint)) { - checkBasepoint(); - ScalarBaseMult(dst, input); - } else { - var base = List.filled(32, 0); - var zero = List.filled(32, 0); - base.setRange(0, base.length, point); - ScalarMult(dst, input, base); - if (ListEquality().equals(dst, zero)) { - throw ArgumentError('bad input point: low order point'); - } - } - return Uint8List.fromList(dst); -} diff --git a/x25519/pubspec.yaml b/x25519/pubspec.yaml deleted file mode 100644 index d98e786..0000000 --- a/x25519/pubspec.yaml +++ /dev/null @@ -1,17 +0,0 @@ -name: x25519 -description: Dart port of x25519 from Go Cryptography curve25519. -version: 0.1.1 -homepage: https://github.com/Tougee/curve25519 - -environment: - sdk: '>=2.12.0 <3.0.0' - -dependencies: - collection: ^1.15.0 - adaptive_number: ^1.0.0 - -dev_dependencies: - pedantic: ^1.9.0 - test: ^1.16.4 - hex: ^0.2.0 - benchmark_harness: ^2.0.0