├── .DS_Store ├── .github └── workflows │ ├── chrome.workflow.yml │ ├── health.yaml │ ├── node.workflow.yml │ ├── post_summaries.yaml │ └── vm.workflow.yml ├── .gitignore ├── .gitlab-ci.yml ├── CHANGELOG.md ├── CONTRIBUTORS ├── LICENSE ├── README.md ├── analysis_options.yaml ├── benchmark ├── all_benchmarks.dart ├── benchmark │ ├── block_cipher_benchmark.dart │ ├── digest_benchmark.dart │ ├── operation_benchmark.dart │ ├── rate_benchmark.dart │ ├── signer_benchmark.dart │ └── stream_cipher_benchmark.dart ├── block │ └── aes_benchmark.dart ├── digests │ ├── blake2b_benchmark.dart │ ├── md2_benchmark.dart │ ├── md4_benchmark.dart │ ├── md5_benchmark.dart │ ├── ripemd128_benchmark.dart │ ├── ripemd160_benchmark.dart │ ├── ripemd256_benchmark.dart │ ├── ripemd320_benchmark.dart │ ├── sha1_benchmark.dart │ ├── sha224_benchmark.dart │ ├── sha256_benchmark.dart │ ├── sha384_benchmark.dart │ ├── sha3_benchmark.dart │ ├── sha512_benchmark.dart │ ├── sha512t_benchmark.dart │ ├── tiger_benchmark.dart │ └── whirlpool_benchmark.dart ├── signers │ └── rsa_signer_benchmark.dart ├── src │ └── ufixnum_benchmark.dart └── stream │ └── salsa20_benchmark.dart ├── lib ├── adapters │ └── stream_cipher_as_block_cipher.dart ├── api.dart ├── asn1.dart ├── asn1 │ ├── asn1_encoding_rule.dart │ ├── asn1_object.dart │ ├── asn1_parser.dart │ ├── asn1_tags.dart │ ├── asn1_utils.dart │ ├── object_identifiers.dart │ ├── object_identifiers_database.dart │ ├── pkcs │ │ ├── pkcs1 │ │ │ └── asn1_digest_info.dart │ │ ├── pkcs10 │ │ │ ├── asn1_certification_request.dart │ │ │ ├── asn1_certification_request_info.dart │ │ │ └── asn1_subject_public_key_info.dart │ │ ├── pkcs12 │ │ │ ├── asn1_authenticated_safe.dart │ │ │ ├── asn1_cert_bag.dart │ │ │ ├── asn1_key_bag.dart │ │ │ ├── asn1_mac_data.dart │ │ │ ├── asn1_pfx.dart │ │ │ ├── asn1_pkcs12_attribute.dart │ │ │ ├── asn1_safe_bag.dart │ │ │ └── asn1_safe_contents.dart │ │ ├── pkcs7 │ │ │ ├── asn1_content_info.dart │ │ │ └── asn1_encrypted_content_info.dart │ │ └── pkcs8 │ │ │ ├── asn1_encrypted_data.dart │ │ │ ├── asn1_encrypted_private_key_info.dart │ │ │ └── asn1_private_key_info.dart │ ├── primitives │ │ ├── asn1_bit_string.dart │ │ ├── asn1_bmp_string.dart │ │ ├── asn1_boolean.dart │ │ ├── asn1_enumerated.dart │ │ ├── asn1_generalized_time.dart │ │ ├── asn1_ia5_string.dart │ │ ├── asn1_integer.dart │ │ ├── asn1_null.dart │ │ ├── asn1_object_identifier.dart │ │ ├── asn1_octet_string.dart │ │ ├── asn1_printable_string.dart │ │ ├── asn1_sequence.dart │ │ ├── asn1_set.dart │ │ ├── asn1_teletext_string.dart │ │ ├── asn1_utc_time.dart │ │ └── asn1_utf8_string.dart │ ├── unsupported_asn1_encoding_rule_exception.dart │ ├── unsupported_asn1_tag_exception.dart │ ├── unsupported_object_identifier_exception.dart │ ├── x501 │ │ ├── asn1_attribute_type_and_value.dart │ │ ├── asn1_name.dart │ │ └── asn1_rdn.dart │ └── x509 │ │ └── asn1_algorithm_identifier.dart ├── asymmetric │ ├── api.dart │ ├── ec_elgamal.dart │ ├── oaep.dart │ ├── pkcs1.dart │ └── rsa.dart ├── block │ ├── aes.dart │ ├── aes_fast.dart │ ├── blowfish.dart │ ├── camellia.dart │ ├── des_base.dart │ ├── desede_engine.dart │ ├── modes │ │ ├── cbc.dart │ │ ├── ccm.dart │ │ ├── cfb.dart │ │ ├── ctr.dart │ │ ├── ecb.dart │ │ ├── gcm.dart │ │ ├── gctr.dart │ │ ├── ige.dart │ │ ├── ofb.dart │ │ └── sic.dart │ ├── rc2_engine.dart │ └── twofish.dart ├── digests │ ├── blake2b.dart │ ├── cshake.dart │ ├── keccak.dart │ ├── md2.dart │ ├── md4.dart │ ├── md5.dart │ ├── ripemd128.dart │ ├── ripemd160.dart │ ├── ripemd256.dart │ ├── ripemd320.dart │ ├── sha1.dart │ ├── sha224.dart │ ├── sha256.dart │ ├── sha3.dart │ ├── sha384.dart │ ├── sha512.dart │ ├── sha512t.dart │ ├── shake.dart │ ├── sm3.dart │ ├── tiger.dart │ ├── whirlpool.dart │ └── xof_utils.dart ├── ecc │ ├── api.dart │ ├── curves │ │ ├── brainpoolp160r1.dart │ │ ├── brainpoolp160t1.dart │ │ ├── brainpoolp192r1.dart │ │ ├── brainpoolp192t1.dart │ │ ├── brainpoolp224r1.dart │ │ ├── brainpoolp224t1.dart │ │ ├── brainpoolp256r1.dart │ │ ├── brainpoolp256t1.dart │ │ ├── brainpoolp320r1.dart │ │ ├── brainpoolp320t1.dart │ │ ├── brainpoolp384r1.dart │ │ ├── brainpoolp384t1.dart │ │ ├── brainpoolp512r1.dart │ │ ├── brainpoolp512t1.dart │ │ ├── gostr3410_2001_cryptopro_a.dart │ │ ├── gostr3410_2001_cryptopro_b.dart │ │ ├── gostr3410_2001_cryptopro_c.dart │ │ ├── gostr3410_2001_cryptopro_xcha.dart │ │ ├── gostr3410_2001_cryptopro_xchb.dart │ │ ├── prime192v1.dart │ │ ├── prime192v2.dart │ │ ├── prime192v3.dart │ │ ├── prime239v1.dart │ │ ├── prime239v2.dart │ │ ├── prime239v3.dart │ │ ├── prime256v1.dart │ │ ├── secp112r1.dart │ │ ├── secp112r2.dart │ │ ├── secp128r1.dart │ │ ├── secp128r2.dart │ │ ├── secp160k1.dart │ │ ├── secp160r1.dart │ │ ├── secp160r2.dart │ │ ├── secp192k1.dart │ │ ├── secp192r1.dart │ │ ├── secp224k1.dart │ │ ├── secp224r1.dart │ │ ├── secp256k1.dart │ │ ├── secp256r1.dart │ │ ├── secp384r1.dart │ │ └── secp521r1.dart │ ├── ecc_base.dart │ ├── ecc_fp.dart │ └── ecdh.dart ├── export.dart ├── impl.dart ├── key_derivators │ ├── api.dart │ ├── argon2.dart │ ├── argon2_native_int_impl.dart │ ├── argon2_register64_impl.dart │ ├── concat_kdf.dart │ ├── ecdh_kdf.dart │ ├── hkdf.dart │ ├── pbkdf2.dart │ ├── pkcs12_parameter_generator.dart │ ├── pkcs5s1_parameter_generator.dart │ └── scrypt.dart ├── key_generators │ ├── api.dart │ ├── ec_key_generator.dart │ └── rsa_key_generator.dart ├── macs │ ├── cbc_block_cipher_mac.dart │ ├── cmac.dart │ ├── hmac.dart │ └── poly1305.dart ├── padded_block_cipher │ └── padded_block_cipher_impl.dart ├── paddings │ ├── iso7816d4.dart │ └── pkcs7.dart ├── pointycastle.dart ├── random │ ├── auto_seed_block_ctr_random.dart │ ├── block_ctr_random.dart │ └── fortuna_random.dart ├── signers │ ├── ecdsa_signer.dart │ ├── pss_signer.dart │ └── rsa_signer.dart ├── src │ ├── api │ │ ├── aead_block_cipher.dart │ │ ├── aead_cipher.dart │ │ ├── aead_parameters.dart │ │ ├── algorithm.dart │ │ ├── asymmetric_block_cipher.dart │ │ ├── asymmetric_key.dart │ │ ├── asymmetric_key_pair.dart │ │ ├── asymmetric_key_parameter.dart │ │ ├── block_cipher.dart │ │ ├── cipher_parameters.dart │ │ ├── des_parameters.dart │ │ ├── desede_parameters.dart │ │ ├── digest.dart │ │ ├── key_derivator.dart │ │ ├── key_generator.dart │ │ ├── key_generator_parameters.dart │ │ ├── key_parameter.dart │ │ ├── mac.dart │ │ ├── padded_block_cipher.dart │ │ ├── padded_block_cipher_parameters.dart │ │ ├── padding.dart │ │ ├── parameters_with_iv.dart │ │ ├── parameters_with_random.dart │ │ ├── parameters_with_salt.dart │ │ ├── parameters_with_salt_configuration.dart │ │ ├── pbe_parameters_generator.dart │ │ ├── private_key.dart │ │ ├── private_key_parameter.dart │ │ ├── public_key.dart │ │ ├── public_key_parameter.dart │ │ ├── rc2_parameters.dart │ │ ├── registry_factory_exception.dart │ │ ├── secure_random.dart │ │ ├── signature.dart │ │ ├── signer.dart │ │ ├── srp_client.dart │ │ ├── srp_server.dart │ │ ├── stream_cipher.dart │ │ └── xof.dart │ ├── ct.dart │ ├── ec_standard_curve_constructor.dart │ ├── impl │ │ ├── base_aead_block_cipher.dart │ │ ├── base_aead_cipher.dart │ │ ├── base_asymmetric_block_cipher.dart │ │ ├── base_block_cipher.dart │ │ ├── base_digest.dart │ │ ├── base_key_derivator.dart │ │ ├── base_mac.dart │ │ ├── base_padding.dart │ │ ├── base_stream_cipher.dart │ │ ├── entropy.dart │ │ ├── keccak_engine.dart │ │ ├── long_sha2_family_digest.dart │ │ ├── md4_family_digest.dart │ │ └── secure_random_base.dart │ ├── platform_check │ │ ├── abstract.dart │ │ ├── native.dart │ │ ├── node_crypto.dart │ │ ├── platform_check.dart │ │ └── web.dart │ ├── registration.dart │ ├── registry │ │ ├── registration.dart │ │ └── registry.dart │ ├── ufixnum.dart │ └── utils.dart ├── srp │ ├── srp6_client.dart │ ├── srp6_server.dart │ ├── srp6_standard_groups.dart │ ├── srp6_util.dart │ └── srp6_verifier_generator.dart └── stream │ ├── chacha20.dart │ ├── chacha20poly1305.dart │ ├── chacha7539.dart │ ├── ctr.dart │ ├── eax.dart │ ├── rc4_engine.dart │ ├── salsa20.dart │ └── sic.dart ├── licenses ├── LICENSE-BouncyCastle.html └── LICENSE-scrypt.txt ├── pubspec.yaml ├── script ├── object_identifiers.csv └── object_identifiers.dart ├── test ├── adapters │ └── stream_cipher_as_block_cipher_test.dart ├── asn1 │ ├── asn1_all_test-disabled.dart │ ├── asn1_dump_test.dart │ ├── asn1_object_test.dart │ ├── asn1_parser_test.dart │ ├── asn1_utils_test.dart │ └── primitives │ │ ├── asn1_bit_string_test.dart │ │ ├── asn1_bmp_string_test.dart │ │ ├── asn1_boolean_test.dart │ │ ├── asn1_enumerated_test.dart │ │ ├── asn1_generalized_time_test.dart │ │ ├── asn1_ia5_string_test.dart │ │ ├── asn1_integer_test.dart │ │ ├── asn1_null_test.dart │ │ ├── asn1_object_identifier_test.dart │ │ ├── asn1_octet_string_test.dart │ │ ├── asn1_printable_string_test.dart │ │ ├── asn1_sequence_test.dart │ │ ├── asn1_set_test.dart │ │ ├── asn1_teletext_string_test.dart │ │ ├── asn1_utc_time_test.dart │ │ └── asn1_utf8_string_test.dart ├── asymmetric │ ├── ec_elgamal_test.dart │ ├── oaep_test.dart │ ├── pkcs1_test.dart │ └── rsa_test.dart ├── block │ ├── aes_fast_test.dart │ ├── aes_test.dart │ ├── blowfish_test.dart │ ├── camellia_test.dart │ ├── desede_engine_test.dart │ ├── rc2_engine_test.dart │ └── twofish_test.dart ├── digests │ ├── blake2b_test.dart │ ├── cshake_test.dart │ ├── keccak_test.dart │ ├── md2_test.dart │ ├── md4_test.dart │ ├── md5_test.dart │ ├── ripemd128_test.dart │ ├── ripemd160_test.dart │ ├── ripemd256_test.dart │ ├── ripemd320_test.dart │ ├── sha1_test.dart │ ├── sha224_test.dart │ ├── sha256_test.dart │ ├── sha384_test.dart │ ├── sha3_test.dart │ ├── sha512_test.dart │ ├── sha512t_test.dart │ ├── shake_test.dart │ ├── sm3_test.dart │ ├── tiger_test.dart │ └── whirlpool_test.dart ├── ecc │ ├── curves_test.dart │ └── ecdh_test.dart ├── impl_test.dart ├── key_derivators │ ├── argon2_nonvm_test.dart │ ├── argon2_vm_test.dart │ ├── concatkdf_nonvm_test.dart │ ├── concatkdf_test.dart │ ├── hkdf_test.dart │ ├── pbkdf2_test.dart │ ├── pkcs12_parameter_generator_test.dart │ ├── scrypt_nonvm_test.dart │ └── scrypt_vm_test.dart ├── key_generators │ ├── ec_key_generator_test.dart │ └── rsa_key_generator_test.dart ├── macs │ ├── cbc_block_cipher_mac_test.dart │ ├── cmac_test.dart │ ├── hmac_test.dart │ ├── poly1305_test.dart │ └── poly1305_web_test.dart ├── modes │ ├── cbc_test.dart │ ├── ccm_test.dart │ ├── cfb_test.dart │ ├── ecb_test.dart │ ├── gcm_test.dart │ ├── gctr_test.dart │ ├── ige_test.dart │ ├── ofb_test.dart │ └── sic_test.dart ├── paddings │ ├── iso7816d4_test.dart │ ├── padded_block_cipher_test.dart │ └── pkcs7_test.dart ├── platform │ ├── platform_native_test.dart │ └── platform_web_test.dart ├── random │ ├── auto_seed_block_ctr_random_test.dart │ ├── block_ctr_random_test.dart │ ├── fixed_rng_test.dart │ └── fortuna_random_test.dart ├── signers │ ├── ecdsa_signer_test.dart │ ├── ecdsa_vec.dart │ ├── ecdsa_vector_vm_test.dart │ ├── pss_signer_test.dart │ └── rsa_signer_test.dart ├── src │ ├── ct_nonvm_test.dart │ ├── ct_test.dart │ ├── ufixnum_test.dart │ └── utils_test.dart ├── srp │ └── srp_test.dart ├── stream │ ├── chacha20_test.dart │ ├── chacha20poly1305_test.dart │ ├── eax_test.dart │ ├── rc4_engine_test.dart │ └── salsa20_test.dart ├── test │ ├── runners │ │ ├── asymmetric_block_cipher.dart │ │ ├── block_cipher.dart │ │ ├── digest.dart │ │ ├── key_derivators.dart │ │ ├── key_generators.dart │ │ ├── mac.dart │ │ ├── padding.dart │ │ ├── registry.dart │ │ ├── signer.dart │ │ └── stream_cipher.dart │ └── src │ │ ├── fixed_secure_random.dart │ │ ├── helpers.dart │ │ ├── null_asymmetric_block_cipher.dart │ │ ├── null_block_cipher.dart │ │ ├── null_digest.dart │ │ ├── null_secure_random.dart │ │ └── null_stream_cipher.dart └── test_resources │ └── kdf-56c │ ├── KDA.req.json │ └── KDA.rsp.json ├── tool └── Makefile └── tutorials ├── aes-cbc.md ├── asn1.md ├── digest.md ├── examples ├── README.md ├── aes-cbc-direct.dart ├── aes-cbc-registry.dart ├── digest-demo.dart ├── digest-direct.dart ├── digest-registry.dart ├── hmac-direct.dart ├── hmac-registry.dart ├── import-demo │ ├── README.md │ ├── differences-show.sh │ ├── import-demo-1.dart │ ├── import-demo-2.dart │ ├── import-demo-3.dart │ └── import-demo-4.dart ├── oid-util.dart └── rsa-demo.dart ├── hmac.md ├── rsa.md └── tips.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bcgit/pc-dart/bbd8569f68a7fccbdf0b92d0b44a9219c126c8dd/.DS_Store -------------------------------------------------------------------------------- /.github/workflows/chrome.workflow.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: ci-chrome 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the master branch 8 | push: 9 | branches: [ master ] 10 | pull_request: 11 | branches: [ master ] 12 | 13 | 14 | # Allows you to run this workflow manually from the Actions tab 15 | workflow_dispatch: 16 | 17 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 18 | jobs: 19 | # This workflow contains a single job called "build" 20 | build: 21 | # The type of runner that the job will run on 22 | runs-on: ubuntu-latest 23 | strategy: 24 | fail-fast: false 25 | matrix: 26 | sdk: [3.2.0, stable, dev] 27 | 28 | # Steps represent a sequence of tasks that will be executed as part of the job 29 | steps: 30 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 31 | - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 32 | - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 33 | with: 34 | sdk: ${{ matrix.sdk }} 35 | 36 | - name: Install dependencies 37 | run: dart pub get 38 | 39 | - name: Test chrome 40 | run: dart test -j 1 -p chrome 41 | -------------------------------------------------------------------------------- /.github/workflows/health.yaml: -------------------------------------------------------------------------------- 1 | name: Health 2 | on: 3 | pull_request: 4 | branches: [ main ] 5 | types: [opened, synchronize, reopened, labeled, unlabeled] 6 | jobs: 7 | health: 8 | uses: dart-lang/ecosystem/.github/workflows/health.yaml@9fabe464ea1d8408774de74d2ac759c1f90ae480 9 | with: 10 | checks: "version,changelog,license,do-not-submit,breaking,coverage,leaking" 11 | permissions: 12 | pull-requests: write -------------------------------------------------------------------------------- /.github/workflows/node.workflow.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: ci-node 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the master branch 8 | push: 9 | branches: [ master ] 10 | pull_request: 11 | branches: [ master ] 12 | 13 | 14 | # Allows you to run this workflow manually from the Actions tab 15 | workflow_dispatch: 16 | 17 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 18 | jobs: 19 | # This workflow contains a single job called "build" 20 | build: 21 | # The type of runner that the job will run on 22 | runs-on: ubuntu-latest 23 | strategy: 24 | fail-fast: false 25 | matrix: 26 | sdk: [3.2.0, stable, dev] 27 | 28 | # Steps represent a sequence of tasks that will be executed as part of the job 29 | steps: 30 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 31 | - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 32 | - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 33 | with: 34 | sdk: ${{ matrix.sdk }} 35 | 36 | - name: Install dependencies 37 | run: dart pub get 38 | 39 | - name: Test node 40 | run: dart test -p node 41 | -------------------------------------------------------------------------------- /.github/workflows/post_summaries.yaml: -------------------------------------------------------------------------------- 1 | name: Comment on the pull request 2 | 3 | on: 4 | # Trigger this workflow after the Health workflow completes. This workflow will have permissions to 5 | # do things like create comments on the PR, even if the original workflow couldn't. 6 | workflow_run: 7 | workflows: 8 | - Health 9 | types: 10 | - completed 11 | 12 | jobs: 13 | upload: 14 | uses: dart-lang/ecosystem/.github/workflows/post_summaries.yaml@main 15 | permissions: 16 | pull-requests: write -------------------------------------------------------------------------------- /.github/workflows/vm.workflow.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: ci-vm 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the master branch 8 | push: 9 | branches: [ master ] 10 | pull_request: 11 | branches: [ master ] 12 | 13 | 14 | # Allows you to run this workflow manually from the Actions tab 15 | workflow_dispatch: 16 | 17 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 18 | jobs: 19 | # This workflow contains a single job called "build" 20 | build: 21 | # The type of runner that the job will run on 22 | strategy: 23 | fail-fast: false 24 | matrix: 25 | os: [ubuntu, macos, windows] 26 | sdk: [stable] 27 | include: 28 | - os: ubuntu 29 | sdk: 3.2.0 30 | - os: ubuntu 31 | sdk: dev 32 | 33 | runs-on: ${{ matrix.os }}-latest 34 | 35 | # Steps represent a sequence of tasks that will be executed as part of the job 36 | steps: 37 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 38 | - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 39 | - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 40 | with: 41 | sdk: ${{ matrix.sdk }} 42 | 43 | - name: Install dependencies 44 | run: dart pub get 45 | 46 | - name: Test dartvm 47 | run: dart test -p vm 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | packages 2 | pubspec.lock 3 | /.project 4 | *.js 5 | *.deps 6 | *.map 7 | 8 | # idea 9 | .idea/ 10 | *.iml 11 | 12 | # dartdoc 13 | doc/ 14 | 15 | .pub/ 16 | .packages 17 | 18 | .settings/ 19 | .dart_tool/ 20 | 21 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | variables: 2 | GIT_DEPTH: 10 3 | 4 | 5 | stages: 6 | - test 7 | - score 8 | 9 | test-code-vm: 10 | stage: test 11 | script: 12 | - "export PATH=$PATH:/usr/lib/dart/bin:$HOME/.pub-cache/bin; \ 13 | dart pub get; \ 14 | dart pub upgrade; \ 15 | dart pub run test;" 16 | 17 | test-code-node: 18 | stage: test 19 | script: 20 | - "export PATH=$PATH:/usr/lib/dart/bin:$HOME/.pub-cache/bin; \ 21 | dart pub get; \ 22 | dart pub upgrade; \ 23 | dart pub run test --timeout 15m -p node" 24 | 25 | test-code-chrome: 26 | stage: test 27 | script: 28 | - "export PATH=$PATH:/usr/lib/dart/bin:$HOME/.pub-cache/bin; \ 29 | dart pub get; \ 30 | dart pub upgrade; \ 31 | dart pub run test --timeout 15m -p chrome" 32 | 33 | score-pana: 34 | stage: score 35 | script: 36 | - "export PATH=$PATH:/usr/lib/dart/bin:$HOME/.pub-cache/bin; \ 37 | dart pub get; \ 38 | dart pub upgrade; \ 39 | dart pub global activate pana; \ 40 | pana ." 41 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # Below is a list of people that have contributed to the Pointy Castle 2 | # project. Names should be added to the list like so: 3 | # 4 | # Name [] 5 | 6 | Iván Zaera Avellón 7 | Steven Roose 8 | Aditya Kishore 9 | Hoylen Sue 10 | Adam Crowder 11 | Herbert Poul 12 | Daniel Linsenmeier 13 | CDDelta 14 | Shammah Chancellor 15 | Rick Bellens 16 | Deniz Türkoglu 17 | Yurii Baryshev 18 | Graciliano M. Passos 19 | Netthaw 20 | Uchiha Kakashi 21 | nyuszika7h https://github.com/nyuszika7h 22 | TiagoSantos 23 | Mathieu D'Amours 24 | Yurii Baryshev 25 | Alban Durrheimer 26 | Olaf Schlüter 27 | Edward Poot 28 | Kajus Wurster 29 | Kaoet 30 | Raphael Schweizer 31 | 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2000 - 2019 The Legion of the Bouncy Castle Inc. (https://www.bouncycastle.org) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:lints/recommended.yaml 2 | 3 | analyzer: 4 | errors: 5 | constant_identifier_names: ignore 6 | file_names: ignore # these should be fixed 7 | no_leading_underscores_for_local_identifiers: ignore # should be fixed! 8 | non_constant_identifier_names: ignore 9 | unnecessary_library_directive: ignore # blocked by dartdoc changes 10 | -------------------------------------------------------------------------------- /benchmark/benchmark/block_cipher_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | 7 | import '../benchmark/rate_benchmark.dart'; 8 | 9 | typedef CipherParametersFactory = CipherParameters Function(); 10 | 11 | class BlockCipherBenchmark extends RateBenchmark { 12 | final String _blockCipherName; 13 | final bool _forEncryption; 14 | final CipherParametersFactory _cipherParametersFactory; 15 | Uint8List? _data; 16 | 17 | late BlockCipher _blockCipher; 18 | 19 | BlockCipherBenchmark(String blockCipherName, String blockCipherVariant, 20 | bool forEncryption, this._cipherParametersFactory) 21 | : _blockCipherName = blockCipherName, 22 | _forEncryption = forEncryption, 23 | super('BlockCipher | $blockCipherName - $blockCipherVariant - ' 24 | '${forEncryption ? 'encrypt' : 'decrypt'}'); 25 | 26 | @override 27 | void setup() { 28 | _blockCipher = BlockCipher(_blockCipherName); 29 | _blockCipher.init(_forEncryption, _cipherParametersFactory()); 30 | _data = Uint8List(_blockCipher.blockSize); 31 | } 32 | 33 | @override 34 | void run() { 35 | _blockCipher.process(_data!); 36 | addSample(_data!.length); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /benchmark/benchmark/digest_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | 7 | import '../benchmark/rate_benchmark.dart'; 8 | 9 | class DigestBenchmark extends RateBenchmark { 10 | final String _digestName; 11 | final Uint8List _data; 12 | 13 | late Digest _digest; 14 | 15 | DigestBenchmark(String digestName, [int dataLength = 1024 * 1024]) 16 | : _digestName = digestName, 17 | _data = Uint8List(dataLength), 18 | super('Digest | $digestName'); 19 | 20 | @override 21 | void setup() { 22 | _digest = Digest(_digestName); 23 | } 24 | 25 | @override 26 | void run() { 27 | _digest.process(_data); 28 | addSample(_data.length); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /benchmark/benchmark/signer_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | 7 | import '../benchmark/rate_benchmark.dart'; 8 | 9 | typedef CipherParametersFactory = CipherParameters Function(); 10 | 11 | class SignerBenchmark extends RateBenchmark { 12 | final String _signerName; 13 | final Uint8List _data; 14 | final CipherParametersFactory _cipherParametersFactory; 15 | final bool _forSigning; 16 | 17 | late Signer _signer; 18 | 19 | SignerBenchmark( 20 | String signerName, bool forSigning, this._cipherParametersFactory, 21 | [int dataLength = 1024 * 1024]) 22 | : _signerName = signerName, 23 | _forSigning = forSigning, 24 | _data = Uint8List(dataLength), 25 | super('Signer | $signerName - ${forSigning ? 'sign' : 'verify'}'); 26 | 27 | @override 28 | void setup() { 29 | _signer = Signer(_signerName); 30 | _signer.init(_forSigning, _cipherParametersFactory()); 31 | } 32 | 33 | @override 34 | void run() { 35 | _signer.generateSignature(_data); 36 | addSample(_data.length); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /benchmark/benchmark/stream_cipher_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | 7 | import '../benchmark/rate_benchmark.dart'; 8 | 9 | typedef CipherParametersFactory = CipherParameters Function(); 10 | 11 | class StreamCipherBenchmark extends RateBenchmark { 12 | final String _streamCipherName; 13 | final bool _forEncryption; 14 | final CipherParametersFactory _cipherParametersFactory; 15 | final Uint8List _data; 16 | 17 | late StreamCipher _streamCipher; 18 | 19 | StreamCipherBenchmark(String streamCipherName, String? streamCipherVariant, 20 | bool forEncryption, this._cipherParametersFactory, 21 | [int dataLength = 1024 * 1024]) 22 | : _streamCipherName = streamCipherName, 23 | _forEncryption = forEncryption, 24 | _data = Uint8List(dataLength), 25 | super( 26 | 'StreamCipher | $streamCipherName ${_formatVariant(streamCipherVariant)}- ' 27 | '${forEncryption ? 'encrypt' : 'decrypt'}'); 28 | 29 | @override 30 | void setup() { 31 | _streamCipher = StreamCipher(_streamCipherName); 32 | _streamCipher.init(_forEncryption, _cipherParametersFactory()); 33 | } 34 | 35 | @override 36 | void run() { 37 | _streamCipher.process(_data); 38 | addSample(_data.length); 39 | } 40 | } 41 | 42 | String _formatVariant(String? streamCipherVariant) { 43 | if (streamCipherVariant == null) { 44 | return ''; 45 | } else { 46 | return '- $streamCipherVariant '; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /benchmark/block/aes_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | 7 | import '../benchmark/block_cipher_benchmark.dart'; 8 | 9 | void main() { 10 | final key = Uint8List.fromList([ 11 | 0x00, 12 | 0x11, 13 | 0x22, 14 | 0x33, 15 | 0x44, 16 | 0x55, 17 | 0x66, 18 | 0x77, 19 | 0x88, 20 | 0x99, 21 | 0xAA, 22 | 0xBB, 23 | 0xCC, 24 | 0xDD, 25 | 0xEE, 26 | 0xFF 27 | ]); 28 | final params = KeyParameter(key); 29 | 30 | BlockCipherBenchmark('AES', '128', true, () => params).report(); 31 | BlockCipherBenchmark('AES', '128', false, () => params).report(); 32 | 33 | BlockCipherBenchmark('AES', '192', true, () => params).report(); 34 | BlockCipherBenchmark('AES', '192', false, () => params).report(); 35 | 36 | BlockCipherBenchmark('AES', '256', true, () => params).report(); 37 | BlockCipherBenchmark('AES', '256', false, () => params).report(); 38 | } 39 | -------------------------------------------------------------------------------- /benchmark/digests/blake2b_benchmark.dart: -------------------------------------------------------------------------------- 1 | import '../benchmark/digest_benchmark.dart'; 2 | 3 | void main() { 4 | DigestBenchmark('Blake2b').report(); 5 | } 6 | -------------------------------------------------------------------------------- /benchmark/digests/md2_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('MD2', 256 * 1024).report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/digests/md4_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('MD4').report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/digests/md5_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('MD5').report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/digests/ripemd128_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('RIPEMD-128').report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/digests/ripemd160_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('RIPEMD-160').report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/digests/ripemd256_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('RIPEMD-256').report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/digests/ripemd320_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('RIPEMD-320').report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/digests/sha1_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('SHA-1').report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/digests/sha224_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('SHA-224').report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/digests/sha256_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('SHA-256').report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/digests/sha384_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('SHA-384').report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/digests/sha3_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('SHA-3/224').report(); 7 | DigestBenchmark('SHA-3/256').report(); 8 | DigestBenchmark('SHA-3/288').report(); 9 | DigestBenchmark('SHA-3/384').report(); 10 | DigestBenchmark('SHA-3/512').report(); 11 | } 12 | -------------------------------------------------------------------------------- /benchmark/digests/sha512_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('SHA-512').report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/digests/sha512t_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('SHA-512/504').report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/digests/tiger_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('Tiger').report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/digests/whirlpool_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import '../benchmark/digest_benchmark.dart'; 4 | 5 | void main() { 6 | DigestBenchmark('Whirlpool').report(); 7 | } 8 | -------------------------------------------------------------------------------- /benchmark/stream/salsa20_benchmark.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | 7 | import '../benchmark/stream_cipher_benchmark.dart'; 8 | 9 | void main() { 10 | final keyBytes = Uint8List.fromList([ 11 | 0x00, 12 | 0x11, 13 | 0x22, 14 | 0x33, 15 | 0x44, 16 | 0x55, 17 | 0x66, 18 | 0x77, 19 | 0x88, 20 | 0x99, 21 | 0xAA, 22 | 0xBB, 23 | 0xCC, 24 | 0xDD, 25 | 0xEE, 26 | 0xFF 27 | ]); 28 | final key = KeyParameter(keyBytes); 29 | final iv = 30 | Uint8List.fromList([0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77]); 31 | final params = ParametersWithIV(key, iv); 32 | 33 | StreamCipherBenchmark('Salsa20', null, true, () => params).report(); 34 | StreamCipherBenchmark('Salsa20', null, false, () => params).report(); 35 | } 36 | -------------------------------------------------------------------------------- /lib/adapters/stream_cipher_as_block_cipher.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.adapters.stream_cipher_as_block_cipher; 4 | 5 | import 'dart:typed_data'; 6 | 7 | import 'package:pointycastle/api.dart'; 8 | import 'package:pointycastle/src/impl/base_block_cipher.dart'; 9 | 10 | /// An adapter to convert an [StreamCipher] to a [BlockCipher] 11 | class StreamCipherAsBlockCipher extends BaseBlockCipher { 12 | final StreamCipher streamCipher; 13 | @override 14 | final int blockSize; 15 | 16 | /// Create a [BlockCipher] from [streamCipher] simulating the given [blockSize] 17 | StreamCipherAsBlockCipher(this.blockSize, this.streamCipher); 18 | 19 | @override 20 | String get algorithmName => streamCipher.algorithmName; 21 | 22 | @override 23 | void reset() { 24 | streamCipher.reset(); 25 | } 26 | 27 | @override 28 | void init(bool forEncryption, CipherParameters? params) { 29 | streamCipher.init(forEncryption, params); 30 | } 31 | 32 | @override 33 | int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { 34 | streamCipher.processBytes(inp, inpOff, blockSize, out, outOff); 35 | return blockSize; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/asn1/asn1_encoding_rule.dart: -------------------------------------------------------------------------------- 1 | enum ASN1EncodingRule { 2 | /// Normal DER encoding rules 3 | ENCODING_DER, 4 | 5 | /// BER encoding where the length is described in a long form 6 | ENCODING_BER_LONG_LENGTH_FORM, 7 | 8 | /// BER Constructed encoding with definite length 9 | ENCODING_BER_CONSTRUCTED, 10 | 11 | /// BER encoding with padded bits to make the length of the value bytes a multiple of eight. Only used for ASN1BitString 12 | ENCODING_BER_PADDED, 13 | 14 | /// BER Constructed encoding with indefinite length 15 | ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH 16 | } 17 | -------------------------------------------------------------------------------- /lib/asn1/object_identifiers.dart: -------------------------------------------------------------------------------- 1 | import 'package:pointycastle/asn1/object_identifiers_database.dart'; 2 | 3 | /// 4 | /// Class holding a list of object identifiers 5 | /// 6 | class ObjectIdentifiers { 7 | /// 8 | /// Returns the object identifier corresponding to the given [readableName]. 9 | /// 10 | /// Returns null if none object identifier can be found for the given [readableName]. 11 | /// 12 | static Map? getIdentifierByName(String readableName) { 13 | for (var element in oi) { 14 | if (element['readableName'] == readableName) { 15 | return element; 16 | } 17 | } 18 | return null; 19 | } 20 | 21 | /// 22 | /// Returns the object identifier corresponding to the given [identifier]. 23 | /// 24 | /// Returns null if none object identifier can be found for the given [identifier]. 25 | /// 26 | static Map? getIdentifierByIdentifier(String? identifier) { 27 | for (var element in oi) { 28 | if (element['identifierString'] == identifier) { 29 | return element; 30 | } 31 | } 32 | return null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/asn1/pkcs/pkcs1/asn1_digest_info.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:pointycastle/asn1.dart'; 4 | 5 | /// 6 | ///``` 7 | /// DigestInfo ::= SEQUENCE { 8 | /// digestAlgorithm DigestAlgorithmIdentifier, 9 | /// digest Digest 10 | /// } 11 | /// 12 | /// Digest ::= OCTET STRING 13 | ///``` 14 | /// 15 | class ASN1DigestInfo extends ASN1Object { 16 | late ASN1AlgorithmIdentifier digestAlgorithm; 17 | late Uint8List digest; 18 | 19 | ASN1DigestInfo(this.digest, this.digestAlgorithm); 20 | 21 | ASN1DigestInfo.fromSequence(ASN1Sequence seq) { 22 | if (seq.elements!.length != 2) { 23 | throw ArgumentError('Sequence has not enough elements'); 24 | } 25 | digestAlgorithm = ASN1AlgorithmIdentifier.fromSequence( 26 | seq.elements!.elementAt(0) as ASN1Sequence); 27 | var o = seq.elements!.elementAt(1) as ASN1OctetString; 28 | if (o.valueBytes != null) { 29 | digest = o.valueBytes!; 30 | } 31 | } 32 | 33 | @override 34 | Uint8List encode( 35 | {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { 36 | var tmp = ASN1Sequence(elements: [ 37 | digestAlgorithm, 38 | ASN1OctetString(octets: digest), 39 | ]); 40 | return tmp.encode(encodingRule: encodingRule); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /lib/asn1/pkcs/pkcs10/asn1_subject_public_key_info.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:pointycastle/asn1.dart'; 4 | 5 | /// 6 | ///``` 7 | /// SubjectPublicKeyInfo { ALGORITHM : IOSet} ::= SEQUENCE { 8 | /// algorithm AlgorithmIdentifier {{IOSet}}, 9 | /// subjectPublicKey BIT STRING 10 | /// } 11 | ///``` 12 | /// 13 | class ASN1SubjectPublicKeyInfo extends ASN1Object { 14 | late ASN1AlgorithmIdentifier algorithm; 15 | late ASN1BitString subjectPublicKey; 16 | 17 | ASN1SubjectPublicKeyInfo( 18 | this.algorithm, 19 | this.subjectPublicKey, 20 | ); 21 | 22 | ASN1SubjectPublicKeyInfo.fromSequence(ASN1Sequence seq) { 23 | if (seq.elements == null || seq.elements!.length != 2) { 24 | throw ArgumentError(''); 25 | } 26 | if (seq.elements!.elementAt(0) is! ASN1Sequence) { 27 | throw ArgumentError('Element at index 0 has to be ASN1Sequence'); 28 | } 29 | if (seq.elements!.elementAt(1) is! ASN1BitString) { 30 | throw ArgumentError('Element at index 1 has to be ASN1BitString'); 31 | } 32 | algorithm = ASN1AlgorithmIdentifier.fromSequence( 33 | seq.elements!.elementAt(0) as ASN1Sequence); 34 | subjectPublicKey = seq.elements!.elementAt(1) as ASN1BitString; 35 | } 36 | 37 | @override 38 | Uint8List encode( 39 | {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { 40 | var tmp = ASN1Sequence( 41 | elements: [ 42 | algorithm, 43 | subjectPublicKey, 44 | ], 45 | ); 46 | return tmp.encode(encodingRule: encodingRule); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lib/asn1/pkcs/pkcs12/asn1_authenticated_safe.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:pointycastle/asn1.dart'; 4 | 5 | /// 6 | /// Taken from [RFC 7292](https://www.rfc-editor.org/rfc/rfc7292#page-10). 7 | ///``` 8 | /// AuthenticatedSafe ::= SEQUENCE OF ContentInfo 9 | ///``` 10 | /// 11 | class ASN1AuthenticatedSafe extends ASN1Object { 12 | late List info; 13 | 14 | ASN1AuthenticatedSafe(this.info); 15 | 16 | ASN1AuthenticatedSafe.fromSequence(ASN1Sequence seq) { 17 | info = []; 18 | if (seq.elements != null) { 19 | for (var element in seq.elements!) { 20 | info.add(ASN1ContentInfo.fromSequence(element as ASN1Sequence)); 21 | } 22 | } 23 | } 24 | 25 | @override 26 | Uint8List encode( 27 | {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { 28 | var tmp = ASN1Sequence(elements: info); 29 | return tmp.encode(encodingRule: encodingRule); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/asn1/pkcs/pkcs12/asn1_key_bag.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | import 'package:pointycastle/asn1.dart'; 3 | 4 | /// 5 | ///``` 6 | /// KeyBag ::= PrivateKeyInfo 7 | ///``` 8 | /// 9 | class ASN1KeyBag extends ASN1Object { 10 | ASN1PrivateKeyInfo privateKeyInfo; 11 | 12 | ASN1KeyBag(this.privateKeyInfo); 13 | 14 | @override 15 | Uint8List encode( 16 | {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { 17 | return privateKeyInfo.encode(encodingRule: encodingRule); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/asn1/pkcs/pkcs12/asn1_mac_data.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:pointycastle/asn1.dart'; 4 | 5 | /// 6 | ///``` 7 | /// MacData ::= SEQUENCE { 8 | /// mac DigestInfo, 9 | /// macSalt OCTET STRING, 10 | /// iterations INTEGER DEFAULT 1 11 | /// } 12 | ///``` 13 | /// 14 | class ASN1MacData extends ASN1Object { 15 | late ASN1DigestInfo mac; 16 | late Uint8List macSalt; 17 | late BigInt iterationCount; 18 | 19 | ASN1MacData(this.mac, this.macSalt, this.iterationCount); 20 | 21 | ASN1MacData.fromSequence(ASN1Sequence seq) { 22 | if (seq.elements!.length != 3) { 23 | throw ArgumentError('Sequence has not enough elements'); 24 | } 25 | mac = 26 | ASN1DigestInfo.fromSequence(seq.elements!.elementAt(0) as ASN1Sequence); 27 | var o = seq.elements!.elementAt(1) as ASN1OctetString; 28 | if (o.valueBytes != null) { 29 | macSalt = o.valueBytes!; 30 | } 31 | var i = seq.elements!.elementAt(2) as ASN1Integer; 32 | if (i.integer != null) { 33 | iterationCount = i.integer!; 34 | } 35 | } 36 | 37 | @override 38 | Uint8List encode( 39 | {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { 40 | var tmp = ASN1Sequence(elements: [ 41 | mac, 42 | ASN1OctetString(octets: macSalt), 43 | ASN1Integer(iterationCount), 44 | ]); 45 | return tmp.encode(encodingRule: encodingRule); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/asn1/pkcs/pkcs12/asn1_pfx.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:pointycastle/asn1.dart'; 4 | 5 | /// 6 | ///``` 7 | /// PFX ::= SEQUENCE { 8 | /// version INTEGER {v3(3)}(v3,...), 9 | /// authSafe ContentInfo, 10 | /// macData MacData OPTIONAL 11 | /// } 12 | ///``` 13 | /// 14 | class ASN1Pfx extends ASN1Object { 15 | late ASN1Integer version; 16 | late ASN1ContentInfo authSafe; 17 | ASN1MacData? macData; 18 | 19 | ASN1Pfx(this.version, this.authSafe, {this.macData}); 20 | 21 | /// 22 | /// Creates an instance of [PFX] from the given [sequence]. The sequence must have at least 2 elements. 23 | /// 24 | ASN1Pfx.fromSequence(ASN1Sequence seq) { 25 | if (seq.elements == null || seq.elements!.isEmpty) { 26 | throw ArgumentError('Empty sequence'); 27 | } 28 | if (seq.elements!.length == 1) { 29 | throw ArgumentError('Sequence has not enough elements'); 30 | } 31 | version = seq.elements!.elementAt(0) as ASN1Integer; 32 | if (version.integer!.toInt() != 3) { 33 | throw ArgumentError('Wrong version for PFX PDU'); 34 | } 35 | authSafe = ASN1ContentInfo.fromSequence( 36 | seq.elements!.elementAt(1) as ASN1Sequence); 37 | if (seq.elements!.length == 3) { 38 | macData = 39 | ASN1MacData.fromSequence(seq.elements!.elementAt(2) as ASN1Sequence); 40 | } 41 | } 42 | 43 | @override 44 | Uint8List encode( 45 | {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { 46 | var tmp = ASN1Sequence(elements: [version, authSafe]); 47 | if (macData != null) { 48 | tmp.add(macData!); 49 | } 50 | return tmp.encode(encodingRule: encodingRule); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /lib/asn1/pkcs/pkcs12/asn1_safe_contents.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:pointycastle/asn1.dart'; 4 | 5 | /// 6 | ///``` 7 | /// SafeContents ::= SEQUENCE OF SafeBag 8 | ///``` 9 | /// 10 | class ASN1SafeContents extends ASN1Object { 11 | /// 12 | /// The safebags to store. 13 | /// 14 | late List safeBags; 15 | 16 | ASN1SafeContents(this.safeBags); 17 | 18 | /// 19 | /// Creates a SafeContents object from the given sequence consisting of [SafeBag] or [ASN1Sequence]. 20 | /// 21 | ASN1SafeContents.fromSequence(ASN1Sequence seq) { 22 | safeBags = []; 23 | if (seq.elements != null) { 24 | for (var element in seq.elements!) { 25 | if (element is ASN1SafeBag) { 26 | safeBags.add(element); 27 | } else if (element is ASN1Sequence) { 28 | safeBags.add(ASN1SafeBag.fromSequence(element)); 29 | } 30 | } 31 | } 32 | } 33 | 34 | @override 35 | Uint8List encode( 36 | {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { 37 | var tmp = ASN1Sequence(elements: safeBags); 38 | return tmp.encode(encodingRule: encodingRule); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lib/asn1/pkcs/pkcs8/asn1_encrypted_data.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:pointycastle/asn1.dart'; 4 | 5 | /// 6 | ///``` 7 | /// EncryptedData ::= SEQUENCE { 8 | /// version Version, 9 | /// encryptedContentInfo EncryptedContentInfo 10 | /// } 11 | ///``` 12 | /// 13 | class ASN1EncryptedData extends ASN1Object { 14 | ASN1Integer version = ASN1Integer.fromtInt(0); 15 | late ASN1EncryptedContentInfo encryptedContentInfo; 16 | 17 | ASN1EncryptedData(this.encryptedContentInfo); 18 | 19 | ASN1EncryptedData.fromSequence(ASN1Sequence seq) { 20 | version = seq.elements!.elementAt(0) as ASN1Integer; 21 | if (seq.elements!.length >= 2) { 22 | var el = seq.elements!.elementAt(1); 23 | if (el is ASN1Sequence) { 24 | encryptedContentInfo = ASN1EncryptedContentInfo.fromSequence(el); 25 | } 26 | } 27 | } 28 | 29 | @override 30 | Uint8List encode( 31 | {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { 32 | var tmp = ASN1Sequence(elements: [ 33 | version, 34 | encryptedContentInfo, 35 | ]); 36 | return tmp.encode(encodingRule: encodingRule); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/asn1/pkcs/pkcs8/asn1_encrypted_private_key_info.dart: -------------------------------------------------------------------------------- 1 | import 'package:pointycastle/asn1.dart'; 2 | 3 | class ASN1EncryptedPrivateKeyInfo extends ASN1Object {} 4 | -------------------------------------------------------------------------------- /lib/asn1/primitives/asn1_enumerated.dart: -------------------------------------------------------------------------------- 1 | import 'package:pointycastle/asn1/asn1_tags.dart'; 2 | import 'package:pointycastle/asn1/primitives/asn1_integer.dart'; 3 | 4 | /// 5 | /// An ASN1Enumerated object 6 | /// 7 | class ASN1Enumerated extends ASN1Integer { 8 | /// 9 | /// Create an [ASN1Enumerated] entity with the given integer [i]. 10 | /// 11 | ASN1Enumerated(int i, {int tag = ASN1Tags.ENUMERATED}) 12 | : super(BigInt.from(i), tag: tag); 13 | 14 | /// 15 | /// Creates an [ASN1Enumerated] entity from the given [encodedBytes]. 16 | /// 17 | ASN1Enumerated.fromBytes(super.encodedBytes) : super.fromBytes(); 18 | } 19 | -------------------------------------------------------------------------------- /lib/asn1/primitives/asn1_null.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; 4 | import 'package:pointycastle/asn1/asn1_object.dart'; 5 | import 'package:pointycastle/asn1/asn1_tags.dart'; 6 | import 'package:pointycastle/asn1/unsupported_asn1_encoding_rule_exception.dart'; 7 | 8 | /// 9 | /// An ASN1 Null object 10 | /// 11 | class ASN1Null extends ASN1Object { 12 | /// 13 | /// Creates an empty [ASN1Null] entity with only the [tag] set. 14 | /// 15 | ASN1Null({int tag = ASN1Tags.NULL}) : super(tag: tag); 16 | 17 | /// 18 | /// Creates an [ASN1Null] entity from the given [encodedBytes]. 19 | /// 20 | ASN1Null.fromBytes(Uint8List super.encodedBytes) : super.fromBytes(); 21 | 22 | /// 23 | /// Encode the [ASN1Null] to the byte representation. 24 | /// 25 | /// This basically returns **[0x05, 0x00]** or **[0x05, 0x81, 0x00]** depending on the [encodingRule] and will not call the *super.encode()* method. 26 | /// 27 | /// Supported encoding rules are : 28 | /// * [ASN1EncodingRule.ENCODING_DER] 29 | /// * [ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM] 30 | /// 31 | @override 32 | Uint8List encode( 33 | {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { 34 | switch (encodingRule) { 35 | case ASN1EncodingRule.ENCODING_DER: 36 | return Uint8List.fromList([tag!, 0x00]); 37 | case ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM: 38 | return Uint8List.fromList([tag!, 0x81, 0x00]); 39 | default: 40 | throw UnsupportedAsn1EncodingRuleException(encodingRule); 41 | } 42 | } 43 | 44 | @override 45 | String dump({int spaces = 0}) { 46 | var sb = StringBuffer(); 47 | for (var i = 0; i < spaces; i++) { 48 | sb.write(' '); 49 | } 50 | sb.write('NULL'); 51 | return sb.toString(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /lib/asn1/unsupported_asn1_encoding_rule_exception.dart: -------------------------------------------------------------------------------- 1 | import 'package:pointycastle/asn1/asn1_encoding_rule.dart'; 2 | 3 | /// 4 | /// Exception that indicates that the given [ASN1EncodingRule] is not supported 5 | /// 6 | class UnsupportedAsn1EncodingRuleException implements Exception { 7 | ASN1EncodingRule rule; 8 | 9 | UnsupportedAsn1EncodingRuleException(this.rule); 10 | 11 | @override 12 | String toString() => 13 | 'UnsupportedAsn1EncodingRuleException: Encoding $rule is not supported by this ASN1Object.'; 14 | } 15 | -------------------------------------------------------------------------------- /lib/asn1/unsupported_asn1_tag_exception.dart: -------------------------------------------------------------------------------- 1 | /// 2 | /// Exception that indicates that the given tag is not supported 3 | /// 4 | class UnsupportedASN1TagException implements Exception { 5 | int tag; 6 | 7 | UnsupportedASN1TagException(this.tag); 8 | 9 | @override 10 | String toString() => 11 | 'UnsupportedASN1TagException: Tag $tag is not supported yet'; 12 | } 13 | -------------------------------------------------------------------------------- /lib/asn1/unsupported_object_identifier_exception.dart: -------------------------------------------------------------------------------- 1 | /// 2 | /// Exception that indicates that the given object identifier is not supported 3 | /// 4 | class UnsupportedObjectIdentifierException implements Exception { 5 | String? oiString; 6 | 7 | UnsupportedObjectIdentifierException(this.oiString); 8 | 9 | @override 10 | String toString() => 11 | 'UnsupportedObjectIdentifierException: ObjectIdentifier $oiString is not supported yet'; 12 | } 13 | -------------------------------------------------------------------------------- /lib/asn1/x501/asn1_name.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | import 'package:pointycastle/asn1.dart'; 3 | 4 | /// 5 | ///``` 6 | /// Name ::= CHOICE { -- only one possibility for now -- 7 | /// rdnSequence RDNSequence 8 | /// } 9 | /// 10 | /// RDNSequence ::= SEQUENCE OF RelativeDistinguishedName 11 | ///``` 12 | /// 13 | class ASN1Name extends ASN1Object { 14 | late List rdnSequence; 15 | 16 | ASN1Name(this.rdnSequence); 17 | 18 | @override 19 | Uint8List encode( 20 | {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { 21 | var tmp = ASN1Sequence( 22 | elements: rdnSequence, 23 | ); 24 | return tmp.encode(encodingRule: encodingRule); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/asn1/x501/asn1_rdn.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:pointycastle/asn1.dart'; 4 | 5 | /// 6 | ///``` 7 | /// RelativeDistinguishedName ::= SET SIZE (1..MAX) OF AttributeTypeAndValue 8 | ///``` 9 | /// 10 | class ASN1RDN extends ASN1Object { 11 | /// Values for the RDN. Elements should be of [AttributeTypeAndValue] 12 | late ASN1Set values; 13 | 14 | ASN1RDN(this.values); 15 | 16 | @override 17 | Uint8List encode( 18 | {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { 19 | return values.encode(encodingRule: encodingRule); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lib/asn1/x509/asn1_algorithm_identifier.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:pointycastle/asn1.dart'; 4 | 5 | /// 6 | ///``` 7 | /// AlgorithmIdentifier ::= SEQUENCE { 8 | /// algorithm OBJECT IDENTIFIER, 9 | /// parameters ANY DEFINED BY algorithm OPTIONAL 10 | /// } 11 | ///``` 12 | /// 13 | class ASN1AlgorithmIdentifier extends ASN1Object { 14 | late ASN1ObjectIdentifier algorithm; 15 | ASN1Object? parameters; 16 | 17 | ASN1AlgorithmIdentifier(this.algorithm, {this.parameters}); 18 | 19 | /// 20 | /// Creates a AlgorithmIdentifier instance from the given [identifier] like "1.3.14.3.2.26". 21 | /// 22 | ASN1AlgorithmIdentifier.fromIdentifier(String identifier, {this.parameters}) { 23 | algorithm = ASN1ObjectIdentifier.fromIdentifierString(identifier); 24 | } 25 | 26 | /// 27 | /// Creates a AlgorithmIdentifier instance from the given [name] like "sha1". 28 | /// 29 | ASN1AlgorithmIdentifier.fromName(String name, {this.parameters}) { 30 | algorithm = ASN1ObjectIdentifier.fromName(name); 31 | } 32 | 33 | ASN1AlgorithmIdentifier.fromSequence(ASN1Sequence seq) { 34 | algorithm = seq.elements!.elementAt(0) as ASN1ObjectIdentifier; 35 | if (seq.elements!.length >= 2) { 36 | parameters = seq.elements!.elementAt(1); 37 | } 38 | } 39 | 40 | @override 41 | Uint8List encode( 42 | {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) { 43 | var tmp = ASN1Sequence(elements: [ 44 | algorithm, 45 | parameters ?? ASN1Null(), 46 | ]); 47 | return tmp.encode(encodingRule: encodingRule); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/block/modes/ctr.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.block_cipher.modes.ctr; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | import 'package:pointycastle/adapters/stream_cipher_as_block_cipher.dart'; 7 | import 'package:pointycastle/stream/ctr.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | class CTRBlockCipher extends StreamCipherAsBlockCipher { 11 | /// Intended for internal use. 12 | static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( 13 | BlockCipher, 14 | '/CTR', 15 | (_, final Match match) => () { 16 | var underlying = BlockCipher(match.group(1)!); 17 | return CTRBlockCipher( 18 | underlying.blockSize, CTRStreamCipher(underlying)); 19 | }); 20 | 21 | CTRBlockCipher(super.blockSize, super.underlyingCipher); 22 | } 23 | -------------------------------------------------------------------------------- /lib/block/modes/ecb.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.block_cipher.modes.ecb; 4 | 5 | import 'dart:typed_data'; 6 | 7 | import 'package:pointycastle/api.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | import 'package:pointycastle/src/impl/base_block_cipher.dart'; 10 | 11 | /// Implementation of Electronic Code Book (ECB) mode on top of a [BlockCipher]. 12 | class ECBBlockCipher extends BaseBlockCipher { 13 | /// Intended for internal use. 14 | static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( 15 | BlockCipher, 16 | '/ECB', 17 | (_, final Match match) => () { 18 | var underlying = BlockCipher(match.group(1)!); 19 | return ECBBlockCipher(underlying); 20 | }); 21 | 22 | final BlockCipher _underlyingCipher; 23 | 24 | ECBBlockCipher(this._underlyingCipher); 25 | 26 | @override 27 | String get algorithmName => '${_underlyingCipher.algorithmName}/ECB'; 28 | @override 29 | int get blockSize => _underlyingCipher.blockSize; 30 | @override 31 | void reset() { 32 | _underlyingCipher.reset(); 33 | } 34 | 35 | @override 36 | void init(bool forEncryption, CipherParameters? params) { 37 | _underlyingCipher.init(forEncryption, params); 38 | } 39 | 40 | @override 41 | int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) => 42 | _underlyingCipher.processBlock(inp, inpOff, out, outOff); 43 | } 44 | -------------------------------------------------------------------------------- /lib/block/modes/sic.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.block_cipher.modes.sic; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | import 'package:pointycastle/adapters/stream_cipher_as_block_cipher.dart'; 7 | import 'package:pointycastle/stream/sic.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | /// See [SICStreamCipher]. 11 | class SICBlockCipher extends StreamCipherAsBlockCipher { 12 | /// Intended for internal use. 13 | static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( 14 | BlockCipher, 15 | '/SIC', 16 | (_, final Match match) => () { 17 | var underlying = BlockCipher(match.group(1)!); 18 | return SICBlockCipher( 19 | underlying.blockSize, SICStreamCipher(underlying)); 20 | }); 21 | 22 | SICBlockCipher(super.blockSize, super.underlyingCipher); 23 | } 24 | -------------------------------------------------------------------------------- /lib/digests/keccak.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.digest.keccak; 4 | 5 | import 'dart:typed_data'; 6 | 7 | import 'package:pointycastle/api.dart'; 8 | import 'package:pointycastle/src/impl/keccak_engine.dart'; 9 | import 'package:pointycastle/src/registry/registry.dart'; 10 | 11 | /// Implementation of Keccak digest. 12 | class KeccakDigest extends KeccakEngine { 13 | static final RegExp _keccakREGEX = RegExp(r'^Keccak\/([0-9]+)$'); 14 | 15 | /// Intended for internal use. 16 | static final FactoryConfig factoryConfig = DynamicFactoryConfig( 17 | Digest, 18 | _keccakREGEX, 19 | (_, final Match match) => () { 20 | var bitLength = int.parse(match.group(1)!); 21 | return KeccakDigest(bitLength); 22 | }); 23 | 24 | KeccakDigest([int bitLength = 288]) { 25 | switch (bitLength) { 26 | case 128: 27 | case 224: 28 | case 256: 29 | case 288: 30 | case 384: 31 | case 512: 32 | init(bitLength); 33 | break; 34 | default: 35 | throw StateError( 36 | 'invalid bitLength ($bitLength) for Keccak must only be 128,224,256,288,384,512'); 37 | } 38 | } 39 | 40 | @override 41 | String get algorithmName => 'Keccak/$fixedOutputLength'; 42 | 43 | @override 44 | int doFinal(Uint8List out, int outOff) { 45 | squeeze(out, outOff, fixedOutputLength); 46 | reset(); 47 | return digestSize; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/digests/sha3.dart: -------------------------------------------------------------------------------- 1 | // This file has been migrated. 2 | 3 | library impl.digest.sha3; 4 | 5 | import 'dart:typed_data'; 6 | 7 | import 'package:pointycastle/api.dart'; 8 | import 'package:pointycastle/src/impl/keccak_engine.dart'; 9 | import 'package:pointycastle/src/registry/registry.dart'; 10 | 11 | /// Implementation of SHA3 digest. 12 | /// https://csrc.nist.gov/publications/detail/fips/202/final 13 | class SHA3Digest extends KeccakEngine { 14 | static final RegExp _sha3REGEX = RegExp(r'^SHA3-([0-9]+)$'); 15 | 16 | /// Intended for internal use. 17 | static final FactoryConfig factoryConfig = DynamicFactoryConfig( 18 | Digest, 19 | _sha3REGEX, 20 | (_, final Match match) => () { 21 | var bitLength = int.parse(match.group(1)!); 22 | return SHA3Digest(bitLength); 23 | }); 24 | 25 | SHA3Digest([int? bitLength = 288]) { 26 | switch (bitLength) { 27 | case 224: 28 | case 256: 29 | case 384: 30 | case 512: 31 | init(bitLength!); 32 | break; 33 | default: 34 | throw StateError( 35 | 'invalid bitLength ($bitLength) for SHA-3 must only be 224,256,384,512'); 36 | } 37 | } 38 | 39 | @override 40 | String get algorithmName => 'SHA3-$fixedOutputLength'; 41 | 42 | @override 43 | int doFinal(Uint8List out, int outOff) { 44 | // FIPS 202 SHA3 https://github.com/PointyCastle/pointycastle/issues/128 45 | absorbBits(0x02, 2); 46 | squeeze(out, outOff, fixedOutputLength); 47 | reset(); 48 | return digestSize; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /lib/digests/sha384.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.digest.sha384; 4 | 5 | import 'dart:typed_data'; 6 | 7 | import 'package:pointycastle/api.dart'; 8 | import 'package:pointycastle/src/impl/long_sha2_family_digest.dart'; 9 | import 'package:pointycastle/src/registry/registry.dart'; 10 | 11 | /// Implementation of SHA-384 digest. 12 | class SHA384Digest extends LongSHA2FamilyDigest implements Digest { 13 | static final FactoryConfig factoryConfig = 14 | StaticFactoryConfig(Digest, 'SHA-384', () => SHA384Digest()); 15 | 16 | static const _DIGEST_LENGTH = 48; 17 | 18 | SHA384Digest() { 19 | reset(); 20 | } 21 | 22 | @override 23 | final algorithmName = 'SHA-384'; 24 | @override 25 | final digestSize = _DIGEST_LENGTH; 26 | 27 | @override 28 | void reset() { 29 | super.reset(); 30 | 31 | h1.set(0xcbbb9d5d, 0xc1059ed8); 32 | h2.set(0x629a292a, 0x367cd507); 33 | h3.set(0x9159015a, 0x3070dd17); 34 | h4.set(0x152fecd8, 0xf70e5939); 35 | h5.set(0x67332667, 0xffc00b31); 36 | h6.set(0x8eb44a87, 0x68581511); 37 | h7.set(0xdb0c2e0d, 0x64f98fa7); 38 | h8.set(0x47b5481d, 0xbefa4fa4); 39 | } 40 | 41 | @override 42 | int doFinal(Uint8List out, int outOff) { 43 | finish(); 44 | 45 | var view = ByteData.view(out.buffer, out.offsetInBytes, out.length); 46 | h1.pack(view, outOff, Endian.big); 47 | h2.pack(view, outOff + 8, Endian.big); 48 | h3.pack(view, outOff + 16, Endian.big); 49 | h4.pack(view, outOff + 24, Endian.big); 50 | h5.pack(view, outOff + 32, Endian.big); 51 | h6.pack(view, outOff + 40, Endian.big); 52 | 53 | reset(); 54 | 55 | return _DIGEST_LENGTH; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /lib/digests/sha512.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.digest.sha512; 4 | 5 | import 'dart:typed_data'; 6 | 7 | import 'package:pointycastle/api.dart'; 8 | import 'package:pointycastle/src/impl/long_sha2_family_digest.dart'; 9 | import 'package:pointycastle/src/registry/registry.dart'; 10 | 11 | /// Implementation of SHA-512 digest. 12 | class SHA512Digest extends LongSHA2FamilyDigest implements Digest { 13 | static final FactoryConfig factoryConfig = 14 | StaticFactoryConfig(Digest, 'SHA-512', () => SHA512Digest()); 15 | 16 | static const _DIGEST_LENGTH = 64; 17 | 18 | SHA512Digest() { 19 | reset(); 20 | } 21 | 22 | @override 23 | final algorithmName = 'SHA-512'; 24 | @override 25 | final digestSize = _DIGEST_LENGTH; 26 | 27 | @override 28 | void reset() { 29 | super.reset(); 30 | 31 | h1.set(0x6a09e667, 0xf3bcc908); 32 | h2.set(0xbb67ae85, 0x84caa73b); 33 | h3.set(0x3c6ef372, 0xfe94f82b); 34 | h4.set(0xa54ff53a, 0x5f1d36f1); 35 | h5.set(0x510e527f, 0xade682d1); 36 | h6.set(0x9b05688c, 0x2b3e6c1f); 37 | h7.set(0x1f83d9ab, 0xfb41bd6b); 38 | h8.set(0x5be0cd19, 0x137e2179); 39 | } 40 | 41 | @override 42 | int doFinal(Uint8List out, int outOff) { 43 | finish(); 44 | 45 | var view = ByteData.view(out.buffer, out.offsetInBytes, out.length); 46 | h1.pack(view, outOff, Endian.big); 47 | h2.pack(view, outOff + 8, Endian.big); 48 | h3.pack(view, outOff + 16, Endian.big); 49 | h4.pack(view, outOff + 24, Endian.big); 50 | h5.pack(view, outOff + 32, Endian.big); 51 | h6.pack(view, outOff + 40, Endian.big); 52 | h7.pack(view, outOff + 48, Endian.big); 53 | h8.pack(view, outOff + 56, Endian.big); 54 | 55 | reset(); 56 | 57 | return _DIGEST_LENGTH; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /lib/digests/xof_utils.dart: -------------------------------------------------------------------------------- 1 | library impl.digest.utils; 2 | 3 | import 'dart:typed_data'; 4 | 5 | class XofUtils { 6 | static Uint8List leftEncode(int strLen) { 7 | var n = 1; 8 | var v = strLen; 9 | while ((v >>= 8) != 0) { 10 | n++; 11 | } 12 | var b = Uint8List(n + 1); 13 | b[0] = n; 14 | for (var i = 1; i <= n; i++) { 15 | b[i] = strLen >> (8 * (n - i)); 16 | } 17 | return b; 18 | } 19 | 20 | static Uint8List rightEncode(int strLen) { 21 | var n = 1; 22 | var v = strLen; 23 | while ((v >>= 8) != 0) { 24 | n++; 25 | } 26 | 27 | var b = Uint8List(n + 1); 28 | 29 | b[n] = n; 30 | 31 | for (var i = 0; i < n; i++) { 32 | b[i] = strLen >> (8 * (n - i - 1)); 33 | } 34 | 35 | return b; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/ecc/curves/brainpoolp160r1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.brainpoolp160r1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_brainpoolp160r1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'brainpoolp160r1', () => ECCurve_brainpoolp160r1()); 14 | 15 | factory ECCurve_brainpoolp160r1() => constructFpStandardCurve( 16 | 'brainpoolp160r1', ECCurve_brainpoolp160r1._make, 17 | q: BigInt.parse('e95e4a5f737059dc60dfc7ad95b3d8139515620f', radix: 16), 18 | a: BigInt.parse('340e7be2a280eb74e2be61bada745d97e8f7c300', radix: 16), 19 | b: BigInt.parse('1e589a8595423412134faa2dbdec95c8d8675e58', radix: 16), 20 | g: BigInt.parse( 21 | '04bed5af16ea3f6a4f62938c4631eb5af7bdbcdbc31667cb477a1a8ec338f94741669c976316da6321', 22 | radix: 16), 23 | n: BigInt.parse('e95e4a5f737059dc60df5991d45029409e60fc09', radix: 16), 24 | h: BigInt.parse('1', radix: 16), 25 | seed: null) as ECCurve_brainpoolp160r1; 26 | 27 | static ECCurve_brainpoolp160r1 _make(String domainName, ECCurve curve, 28 | ECPoint G, BigInt n, BigInt h, List? seed) => 29 | ECCurve_brainpoolp160r1._super(domainName, curve, G, n, h, seed); 30 | 31 | ECCurve_brainpoolp160r1._super(super.domainName, super.curve, super.G, 32 | super.n, BigInt super._h, super.seed); 33 | } 34 | -------------------------------------------------------------------------------- /lib/ecc/curves/brainpoolp160t1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.brainpoolp160t1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_brainpoolp160t1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'brainpoolp160t1', () => ECCurve_brainpoolp160t1()); 14 | 15 | factory ECCurve_brainpoolp160t1() => constructFpStandardCurve( 16 | 'brainpoolp160t1', ECCurve_brainpoolp160t1._make, 17 | q: BigInt.parse('e95e4a5f737059dc60dfc7ad95b3d8139515620f', radix: 16), 18 | a: BigInt.parse('e95e4a5f737059dc60dfc7ad95b3d8139515620c', radix: 16), 19 | b: BigInt.parse('7a556b6dae535b7b51ed2c4d7daa7a0b5c55f380', radix: 16), 20 | g: BigInt.parse( 21 | '04b199b13b9b34efc1397e64baeb05acc265ff2378add6718b7c7c1961f0991b842443772152c9e0ad', 22 | radix: 16), 23 | n: BigInt.parse('e95e4a5f737059dc60df5991d45029409e60fc09', radix: 16), 24 | h: BigInt.parse('1', radix: 16), 25 | seed: null) as ECCurve_brainpoolp160t1; 26 | 27 | static ECCurve_brainpoolp160t1 _make(String domainName, ECCurve curve, 28 | ECPoint G, BigInt n, BigInt h, List? seed) => 29 | ECCurve_brainpoolp160t1._super(domainName, curve, G, n, h, seed); 30 | 31 | ECCurve_brainpoolp160t1._super(super.domainName, super.curve, super.G, 32 | super.n, BigInt super._h, super.seed); 33 | } 34 | -------------------------------------------------------------------------------- /lib/ecc/curves/brainpoolp192r1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.brainpoolp192r1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_brainpoolp192r1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'brainpoolp192r1', () => ECCurve_brainpoolp192r1()); 14 | 15 | factory ECCurve_brainpoolp192r1() => constructFpStandardCurve( 16 | 'brainpoolp192r1', ECCurve_brainpoolp192r1._make, 17 | q: BigInt.parse('c302f41d932a36cda7a3463093d18db78fce476de1a86297', 18 | radix: 16), 19 | a: BigInt.parse('6a91174076b1e0e19c39c031fe8685c1cae040e5c69a28ef', 20 | radix: 16), 21 | b: BigInt.parse('469a28ef7c28cca3dc721d044f4496bcca7ef4146fbf25c9', 22 | radix: 16), 23 | g: BigInt.parse( 24 | '04c0a0647eaab6a48753b033c56cb0f0900a2f5c4853375fd614b690866abd5bb88b5f4828c1490002e6773fa2fa299b8f', 25 | radix: 16), 26 | n: BigInt.parse('c302f41d932a36cda7a3462f9e9e916b5be8f1029ac4acc1', 27 | radix: 16), 28 | h: BigInt.parse('1', radix: 16), 29 | seed: null) as ECCurve_brainpoolp192r1; 30 | 31 | static ECCurve_brainpoolp192r1 _make(String domainName, ECCurve curve, 32 | ECPoint G, BigInt n, BigInt h, List? seed) => 33 | ECCurve_brainpoolp192r1._super(domainName, curve, G, n, h, seed); 34 | 35 | ECCurve_brainpoolp192r1._super(super.domainName, super.curve, super.G, 36 | super.n, BigInt super._h, super.seed); 37 | } 38 | -------------------------------------------------------------------------------- /lib/ecc/curves/brainpoolp192t1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.brainpoolp192t1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_brainpoolp192t1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'brainpoolp192t1', () => ECCurve_brainpoolp192t1()); 14 | 15 | factory ECCurve_brainpoolp192t1() => constructFpStandardCurve( 16 | 'brainpoolp192t1', ECCurve_brainpoolp192t1._make, 17 | q: BigInt.parse('c302f41d932a36cda7a3463093d18db78fce476de1a86297', 18 | radix: 16), 19 | a: BigInt.parse('c302f41d932a36cda7a3463093d18db78fce476de1a86294', 20 | radix: 16), 21 | b: BigInt.parse('13d56ffaec78681e68f9deb43b35bec2fb68542e27897b79', 22 | radix: 16), 23 | g: BigInt.parse( 24 | '043ae9e58c82f63c30282e1fe7bbf43fa72c446af6f4618129097e2c5667c2223a902ab5ca449d0084b7e5b3de7ccc01c9', 25 | radix: 16), 26 | n: BigInt.parse('c302f41d932a36cda7a3462f9e9e916b5be8f1029ac4acc1', 27 | radix: 16), 28 | h: BigInt.parse('1', radix: 16), 29 | seed: null) as ECCurve_brainpoolp192t1; 30 | 31 | static ECCurve_brainpoolp192t1 _make(String domainName, ECCurve curve, 32 | ECPoint G, BigInt n, BigInt h, List? seed) => 33 | ECCurve_brainpoolp192t1._super(domainName, curve, G, n, h, seed); 34 | 35 | ECCurve_brainpoolp192t1._super(super.domainName, super.curve, super.G, 36 | super.n, BigInt super._h, super.seed); 37 | } 38 | -------------------------------------------------------------------------------- /lib/ecc/curves/brainpoolp224t1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.brainpoolp224t1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_brainpoolp224t1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'brainpoolp224t1', () => ECCurve_brainpoolp224t1()); 14 | 15 | factory ECCurve_brainpoolp224t1() => constructFpStandardCurve( 16 | 'brainpoolp224t1', ECCurve_brainpoolp224t1._make, 17 | q: BigInt.parse( 18 | 'd7c134aa264366862a18302575d1d787b09f075797da89f57ec8c0ff', 19 | radix: 16), 20 | a: BigInt.parse( 21 | 'd7c134aa264366862a18302575d1d787b09f075797da89f57ec8c0fc', 22 | radix: 16), 23 | b: BigInt.parse( 24 | '4b337d934104cd7bef271bf60ced1ed20da14c08b3bb64f18a60888d', 25 | radix: 16), 26 | g: BigInt.parse( 27 | '046ab1e344ce25ff3896424e7ffe14762ecb49f8928ac0c76029b4d5800374e9f5143e568cd23f3f4d7c0d4b1e41c8cc0d1c6abd5f1a46db4c', 28 | radix: 16), 29 | n: BigInt.parse( 30 | 'd7c134aa264366862a18302575d0fb98d116bc4b6ddebca3a5a7939f', 31 | radix: 16), 32 | h: BigInt.parse('1', radix: 16), 33 | seed: null) as ECCurve_brainpoolp224t1; 34 | 35 | static ECCurve_brainpoolp224t1 _make(String domainName, ECCurve curve, 36 | ECPoint G, BigInt n, BigInt? h, List? seed) => 37 | ECCurve_brainpoolp224t1._super(domainName, curve, G, n, h, seed); 38 | 39 | ECCurve_brainpoolp224t1._super( 40 | super.domainName, super.curve, super.G, super.n, super.h, super.seed); 41 | } 42 | -------------------------------------------------------------------------------- /lib/ecc/curves/prime192v1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.prime192v1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_prime192v1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'prime192v1', () => ECCurve_prime192v1()); 14 | 15 | factory ECCurve_prime192v1() => 16 | constructFpStandardCurve('prime192v1', ECCurve_prime192v1._make, 17 | q: BigInt.parse('fffffffffffffffffffffffffffffffeffffffffffffffff', 18 | radix: 16), 19 | a: BigInt.parse('fffffffffffffffffffffffffffffffefffffffffffffffc', 20 | radix: 16), 21 | b: BigInt.parse('64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1', 22 | radix: 16), 23 | g: BigInt.parse('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012', 24 | radix: 16), 25 | n: BigInt.parse('ffffffffffffffffffffffff99def836146bc9b1b4d22831', 26 | radix: 16), 27 | h: BigInt.parse('1', radix: 16), 28 | seed: BigInt.parse('3045ae6fc8422f64ed579528d38120eae12196d5', 29 | radix: 16)) as ECCurve_prime192v1; 30 | 31 | static ECCurve_prime192v1 _make(String domainName, ECCurve curve, ECPoint G, 32 | BigInt n, BigInt h, List seed) => 33 | ECCurve_prime192v1._super(domainName, curve, G, n, h, seed); 34 | 35 | ECCurve_prime192v1._super(super.domainName, super.curve, super.G, super.n, 36 | BigInt super._h, List super.seed); 37 | } 38 | -------------------------------------------------------------------------------- /lib/ecc/curves/prime192v2.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.prime192v2; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_prime192v2 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'prime192v2', () => ECCurve_prime192v2()); 14 | 15 | factory ECCurve_prime192v2() => 16 | constructFpStandardCurve('prime192v2', ECCurve_prime192v2._make, 17 | q: BigInt.parse('fffffffffffffffffffffffffffffffeffffffffffffffff', 18 | radix: 16), 19 | a: BigInt.parse('fffffffffffffffffffffffffffffffefffffffffffffffc', 20 | radix: 16), 21 | b: BigInt.parse('cc22d6dfb95c6b25e49c0d6364a4e5980c393aa21668d953', 22 | radix: 16), 23 | g: BigInt.parse('03eea2bae7e1497842f2de7769cfe9c989c072ad696f48034a', 24 | radix: 16), 25 | n: BigInt.parse('fffffffffffffffffffffffe5fb1a724dc80418648d8dd31', 26 | radix: 16), 27 | h: BigInt.parse('1', radix: 16), 28 | seed: BigInt.parse('31a92ee2029fd10d901b113e990710f0d21ac6b6', 29 | radix: 16)) as ECCurve_prime192v2; 30 | 31 | static ECCurve_prime192v2 _make(String domainName, ECCurve curve, ECPoint G, 32 | BigInt n, BigInt h, List seed) => 33 | ECCurve_prime192v2._super(domainName, curve, G, n, h, seed); 34 | 35 | ECCurve_prime192v2._super(super.domainName, super.curve, super.G, super.n, 36 | BigInt super.h, List super.seed); 37 | } 38 | -------------------------------------------------------------------------------- /lib/ecc/curves/prime192v3.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.prime192v3; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_prime192v3 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'prime192v3', () => ECCurve_prime192v3()); 14 | 15 | factory ECCurve_prime192v3() => 16 | constructFpStandardCurve('prime192v3', ECCurve_prime192v3._make, 17 | q: BigInt.parse('fffffffffffffffffffffffffffffffeffffffffffffffff', 18 | radix: 16), 19 | a: BigInt.parse('fffffffffffffffffffffffffffffffefffffffffffffffc', 20 | radix: 16), 21 | b: BigInt.parse('22123dc2395a05caa7423daeccc94760a7d462256bd56916', 22 | radix: 16), 23 | g: BigInt.parse('027d29778100c65a1da1783716588dce2b8b4aee8e228f1896', 24 | radix: 16), 25 | n: BigInt.parse('ffffffffffffffffffffffff7a62d031c83f4294f640ec13', 26 | radix: 16), 27 | h: BigInt.parse('1', radix: 16), 28 | seed: BigInt.parse('c469684435deb378c4b65ca9591e2a5763059a2e', 29 | radix: 16)) as ECCurve_prime192v3; 30 | 31 | static ECCurve_prime192v3 _make(String domainName, ECCurve curve, ECPoint G, 32 | BigInt n, BigInt h, List seed) => 33 | ECCurve_prime192v3._super(domainName, curve, G, n, h, seed); 34 | 35 | ECCurve_prime192v3._super(super.domainName, super.curve, super.G, super.n, 36 | BigInt super._h, List super.seed); 37 | } 38 | -------------------------------------------------------------------------------- /lib/ecc/curves/prime256v1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.prime256v1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_prime256v1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'prime256v1', () => ECCurve_prime256v1()); 14 | 15 | factory ECCurve_prime256v1() => constructFpStandardCurve( 16 | 'prime256v1', ECCurve_prime256v1._make, 17 | q: BigInt.parse('ffffffff00000001000000000000000000000000ffffffffffffffffffffffff', 18 | radix: 16), 19 | a: BigInt.parse( 20 | 'ffffffff00000001000000000000000000000000fffffffffffffffffffffffc', 21 | radix: 16), 22 | b: BigInt.parse( 23 | '5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b', 24 | radix: 16), 25 | g: BigInt.parse( 26 | '036b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296', 27 | radix: 16), 28 | n: BigInt.parse( 29 | 'ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551', 30 | radix: 16), 31 | h: BigInt.parse('1', radix: 16), 32 | seed: BigInt.parse('c49d360886e704936a6678e1139d26b7819f7e90', 33 | radix: 16)) as ECCurve_prime256v1; 34 | 35 | static ECCurve_prime256v1 _make(String domainName, ECCurve curve, ECPoint G, 36 | BigInt n, BigInt h, List seed) => 37 | ECCurve_prime256v1._super(domainName, curve, G, n, h, seed); 38 | 39 | ECCurve_prime256v1._super(super.domainName, super.curve, super.G, super.n, 40 | BigInt super._h, List super.seed); 41 | } 42 | -------------------------------------------------------------------------------- /lib/ecc/curves/secp112r1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.secp112r1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_secp112r1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'secp112r1', () => ECCurve_secp112r1()); 14 | 15 | factory ECCurve_secp112r1() => 16 | constructFpStandardCurve('secp112r1', ECCurve_secp112r1._make, 17 | q: BigInt.parse('db7c2abf62e35e668076bead208b', radix: 16), 18 | a: BigInt.parse('db7c2abf62e35e668076bead2088', radix: 16), 19 | b: BigInt.parse('659ef8ba043916eede8911702b22', radix: 16), 20 | g: BigInt.parse( 21 | '0409487239995a5ee76b55f9c2f098a89ce5af8724c0a23e0e0ff77500', 22 | radix: 16), 23 | n: BigInt.parse('db7c2abf62e35e7628dfac6561c5', radix: 16), 24 | h: BigInt.parse('1', radix: 16), 25 | seed: BigInt.parse('00f50b028e4d696e676875615175290472783fb1', 26 | radix: 16)) as ECCurve_secp112r1; 27 | 28 | static ECCurve_secp112r1 _make(String domainName, ECCurve curve, ECPoint G, 29 | BigInt n, BigInt h, List seed) => 30 | ECCurve_secp112r1._super(domainName, curve, G, n, h, seed); 31 | 32 | ECCurve_secp112r1._super(super.domainName, super.curve, super.G, super.n, 33 | BigInt super._h, List super.seed); 34 | } 35 | -------------------------------------------------------------------------------- /lib/ecc/curves/secp112r2.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.secp112r2; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_secp112r2 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'secp112r2', () => ECCurve_secp112r2()); 14 | 15 | factory ECCurve_secp112r2() => 16 | constructFpStandardCurve('secp112r2', ECCurve_secp112r2._make, 17 | q: BigInt.parse('db7c2abf62e35e668076bead208b', radix: 16), 18 | a: BigInt.parse('6127c24c05f38a0aaaf65c0ef02c', radix: 16), 19 | b: BigInt.parse('51def1815db5ed74fcc34c85d709', radix: 16), 20 | g: BigInt.parse( 21 | '044ba30ab5e892b4e1649dd0928643adcd46f5882e3747def36e956e97', 22 | radix: 16), 23 | n: BigInt.parse('36df0aafd8b8d7597ca10520d04b', radix: 16), 24 | h: BigInt.parse('4', radix: 16), 25 | seed: BigInt.parse('002757a1114d696e6768756151755316c05e0bd4', 26 | radix: 16)) as ECCurve_secp112r2; 27 | 28 | static ECCurve_secp112r2 _make(String domainName, ECCurve curve, ECPoint G, 29 | BigInt n, BigInt h, List seed) => 30 | ECCurve_secp112r2._super(domainName, curve, G, n, h, seed); 31 | 32 | ECCurve_secp112r2._super(super.domainName, super.curve, super.G, super.n, 33 | BigInt super._h, List super.seed); 34 | } 35 | -------------------------------------------------------------------------------- /lib/ecc/curves/secp128r1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.secp128r1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_secp128r1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'secp128r1', () => ECCurve_secp128r1()); 14 | 15 | factory ECCurve_secp128r1() => constructFpStandardCurve( 16 | 'secp128r1', ECCurve_secp128r1._make, 17 | q: BigInt.parse('fffffffdffffffffffffffffffffffff', radix: 16), 18 | a: BigInt.parse('fffffffdfffffffffffffffffffffffc', radix: 16), 19 | b: BigInt.parse('e87579c11079f43dd824993c2cee5ed3', radix: 16), 20 | g: BigInt.parse( 21 | '04161ff7528b899b2d0c28607ca52c5b86cf5ac8395bafeb13c02da292dded7a83', 22 | radix: 16), 23 | n: BigInt.parse('fffffffe0000000075a30d1b9038a115', radix: 16), 24 | h: BigInt.parse('1', radix: 16), 25 | seed: BigInt.parse('000e0d4d696e6768756151750cc03a4473d03679', 26 | radix: 16)) as ECCurve_secp128r1; 27 | 28 | static ECCurve_secp128r1 _make(String domainName, ECCurve curve, ECPoint G, 29 | BigInt n, BigInt h, List seed) => 30 | ECCurve_secp128r1._super(domainName, curve, G, n, h, seed); 31 | 32 | ECCurve_secp128r1._super(super.domainName, super.curve, super.G, super.n, 33 | BigInt super._h, List super.seed); 34 | } 35 | -------------------------------------------------------------------------------- /lib/ecc/curves/secp128r2.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.secp128r2; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_secp128r2 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'secp128r2', () => ECCurve_secp128r2()); 14 | 15 | factory ECCurve_secp128r2() => constructFpStandardCurve( 16 | 'secp128r2', ECCurve_secp128r2._make, 17 | q: BigInt.parse('fffffffdffffffffffffffffffffffff', radix: 16), 18 | a: BigInt.parse('d6031998d1b3bbfebf59cc9bbff9aee1', radix: 16), 19 | b: BigInt.parse('5eeefca380d02919dc2c6558bb6d8a5d', radix: 16), 20 | g: BigInt.parse( 21 | '047b6aa5d85e572983e6fb32a7cdebc14027b6916a894d3aee7106fe805fc34b44', 22 | radix: 16), 23 | n: BigInt.parse('3fffffff7fffffffbe0024720613b5a3', radix: 16), 24 | h: BigInt.parse('4', radix: 16), 25 | seed: BigInt.parse('004d696e67687561517512d8f03431fce63b88f4', 26 | radix: 16)) as ECCurve_secp128r2; 27 | 28 | static ECCurve_secp128r2 _make(String domainName, ECCurve curve, ECPoint G, 29 | BigInt n, BigInt h, List seed) => 30 | ECCurve_secp128r2._super(domainName, curve, G, n, h, seed); 31 | 32 | ECCurve_secp128r2._super(super.domainName, super.curve, super.G, super.n, 33 | BigInt super._h, List super.seed); 34 | } 35 | -------------------------------------------------------------------------------- /lib/ecc/curves/secp160k1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.secp160k1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_secp160k1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'secp160k1', () => ECCurve_secp160k1()); 14 | 15 | factory ECCurve_secp160k1() => constructFpStandardCurve( 16 | 'secp160k1', ECCurve_secp160k1._make, 17 | q: BigInt.parse('fffffffffffffffffffffffffffffffeffffac73', radix: 16), 18 | a: BigInt.parse('0', radix: 16), 19 | b: BigInt.parse('7', radix: 16), 20 | g: BigInt.parse( 21 | '043b4c382ce37aa192a4019e763036f4f5dd4d7ebb938cf935318fdced6bc28286531733c3f03c4fee', 22 | radix: 16), 23 | n: BigInt.parse('100000000000000000001b8fa16dfab9aca16b6b3', radix: 16), 24 | h: BigInt.parse('1', radix: 16), 25 | seed: null) as ECCurve_secp160k1; 26 | 27 | static ECCurve_secp160k1 _make(String domainName, ECCurve curve, ECPoint G, 28 | BigInt n, BigInt h, List? seed) => 29 | ECCurve_secp160k1._super(domainName, curve, G, n, h, seed); 30 | 31 | ECCurve_secp160k1._super(super.domainName, super.curve, super.G, super.n, 32 | BigInt super._h, super.seed); 33 | } 34 | -------------------------------------------------------------------------------- /lib/ecc/curves/secp160r1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.secp160r1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_secp160r1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'secp160r1', () => ECCurve_secp160r1()); 14 | 15 | factory ECCurve_secp160r1() => constructFpStandardCurve( 16 | 'secp160r1', ECCurve_secp160r1._make, 17 | q: BigInt.parse('ffffffffffffffffffffffffffffffff7fffffff', radix: 16), 18 | a: BigInt.parse('ffffffffffffffffffffffffffffffff7ffffffc', radix: 16), 19 | b: BigInt.parse('1c97befc54bd7a8b65acf89f81d4d4adc565fa45', radix: 16), 20 | g: BigInt.parse( 21 | '044a96b5688ef573284664698968c38bb913cbfc8223a628553168947d59dcc912042351377ac5fb32', 22 | radix: 16), 23 | n: BigInt.parse('100000000000000000001f4c8f927aed3ca752257', radix: 16), 24 | h: BigInt.parse('1', radix: 16), 25 | seed: BigInt.parse('1053cde42c14d696e67687561517533bf3f83345', 26 | radix: 16)) as ECCurve_secp160r1; 27 | 28 | static ECCurve_secp160r1 _make(String domainName, ECCurve curve, ECPoint G, 29 | BigInt n, BigInt h, List seed) => 30 | ECCurve_secp160r1._super(domainName, curve, G, n, h, seed); 31 | 32 | ECCurve_secp160r1._super(super.domainName, super.curve, super.G, super.n, 33 | BigInt super._h, List super.seed); 34 | } 35 | -------------------------------------------------------------------------------- /lib/ecc/curves/secp160r2.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.secp160r2; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_secp160r2 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'secp160r2', () => ECCurve_secp160r2()); 14 | 15 | factory ECCurve_secp160r2() => constructFpStandardCurve( 16 | 'secp160r2', ECCurve_secp160r2._make, 17 | q: BigInt.parse('fffffffffffffffffffffffffffffffeffffac73', radix: 16), 18 | a: BigInt.parse('fffffffffffffffffffffffffffffffeffffac70', radix: 16), 19 | b: BigInt.parse('b4e134d3fb59eb8bab57274904664d5af50388ba', radix: 16), 20 | g: BigInt.parse( 21 | '0452dcb034293a117e1f4ff11b30f7199d3144ce6dfeaffef2e331f296e071fa0df9982cfea7d43f2e', 22 | radix: 16), 23 | n: BigInt.parse('100000000000000000000351ee786a818f3a1a16b', radix: 16), 24 | h: BigInt.parse('1', radix: 16), 25 | seed: BigInt.parse('b99b99b099b323e02709a4d696e6768756151751', 26 | radix: 16)) as ECCurve_secp160r2; 27 | 28 | static ECCurve_secp160r2 _make(String domainName, ECCurve curve, ECPoint G, 29 | BigInt n, BigInt h, List seed) => 30 | ECCurve_secp160r2._super(domainName, curve, G, n, h, seed); 31 | 32 | ECCurve_secp160r2._super(super.domainName, super.curve, super.G, super.n, 33 | BigInt super._h, List super.seed); 34 | } 35 | -------------------------------------------------------------------------------- /lib/ecc/curves/secp192k1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.secp192k1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_secp192k1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'secp192k1', () => ECCurve_secp192k1()); 14 | 15 | factory ECCurve_secp192k1() => constructFpStandardCurve( 16 | 'secp192k1', ECCurve_secp192k1._make, 17 | q: BigInt.parse('fffffffffffffffffffffffffffffffffffffffeffffee37', 18 | radix: 16), 19 | a: BigInt.parse('0', radix: 16), 20 | b: BigInt.parse('3', radix: 16), 21 | g: BigInt.parse( 22 | '04db4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d', 23 | radix: 16), 24 | n: BigInt.parse('fffffffffffffffffffffffe26f2fc170f69466a74defd8d', 25 | radix: 16), 26 | h: BigInt.parse('1', radix: 16), 27 | seed: null) as ECCurve_secp192k1; 28 | 29 | static ECCurve_secp192k1 _make(String domainName, ECCurve curve, ECPoint G, 30 | BigInt n, BigInt h, List? seed) => 31 | ECCurve_secp192k1._super(domainName, curve, G, n, h, seed); 32 | 33 | ECCurve_secp192k1._super(super.domainName, super.curve, super.G, super.n, 34 | BigInt super._h, super.seed); 35 | } 36 | -------------------------------------------------------------------------------- /lib/ecc/curves/secp192r1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.secp192r1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_secp192r1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'secp192r1', () => ECCurve_secp192r1()); 14 | 15 | factory ECCurve_secp192r1() => constructFpStandardCurve( 16 | 'secp192r1', ECCurve_secp192r1._make, 17 | q: BigInt.parse('fffffffffffffffffffffffffffffffeffffffffffffffff', 18 | radix: 16), 19 | a: BigInt.parse('fffffffffffffffffffffffffffffffefffffffffffffffc', 20 | radix: 16), 21 | b: BigInt.parse('64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1', 22 | radix: 16), 23 | g: BigInt.parse( 24 | '04188da80eb03090f67cbf20eb43a18800f4ff0afd82ff101207192b95ffc8da78631011ed6b24cdd573f977a11e794811', 25 | radix: 16), 26 | n: BigInt.parse('ffffffffffffffffffffffff99def836146bc9b1b4d22831', 27 | radix: 16), 28 | h: BigInt.parse('1', radix: 16), 29 | seed: BigInt.parse('3045ae6fc8422f64ed579528d38120eae12196d5', 30 | radix: 16)) as ECCurve_secp192r1; 31 | 32 | static ECCurve_secp192r1 _make(String domainName, ECCurve curve, ECPoint G, 33 | BigInt n, BigInt h, List seed) => 34 | ECCurve_secp192r1._super(domainName, curve, G, n, h, seed); 35 | 36 | ECCurve_secp192r1._super(super.domainName, super.curve, super.G, super.n, 37 | BigInt super._h, List super.seed); 38 | } 39 | -------------------------------------------------------------------------------- /lib/ecc/curves/secp224k1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.secp224k1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_secp224k1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'secp224k1', () => ECCurve_secp224k1()); 14 | 15 | factory ECCurve_secp224k1() => constructFpStandardCurve( 16 | 'secp224k1', ECCurve_secp224k1._make, 17 | q: BigInt.parse( 18 | 'fffffffffffffffffffffffffffffffffffffffffffffffeffffe56d', 19 | radix: 16), 20 | a: BigInt.parse('0', radix: 16), 21 | b: BigInt.parse('5', radix: 16), 22 | g: BigInt.parse( 23 | '04a1455b334df099df30fc28a169a467e9e47075a90f7e650eb6b7a45c7e089fed7fba344282cafbd6f7e319f7c0b0bd59e2ca4bdb556d61a5', 24 | radix: 16), 25 | n: BigInt.parse( 26 | '10000000000000000000000000001dce8d2ec6184caf0a971769fb1f7', 27 | radix: 16), 28 | h: BigInt.parse('1', radix: 16), 29 | seed: null) as ECCurve_secp224k1; 30 | 31 | static ECCurve_secp224k1 _make(String domainName, ECCurve curve, ECPoint G, 32 | BigInt n, BigInt h, List? seed) => 33 | ECCurve_secp224k1._super(domainName, curve, G, n, h, seed); 34 | 35 | ECCurve_secp224k1._super(super.domainName, super.curve, super.G, super.n, 36 | BigInt super._h, super.seed); 37 | } 38 | -------------------------------------------------------------------------------- /lib/ecc/curves/secp256k1.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.ec_domain_parameters.secp256k1; 4 | 5 | import 'package:pointycastle/ecc/api.dart'; 6 | import 'package:pointycastle/ecc/ecc_base.dart'; 7 | import 'package:pointycastle/src/ec_standard_curve_constructor.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | // ignore: camel_case_types 11 | class ECCurve_secp256k1 extends ECDomainParametersImpl { 12 | static final FactoryConfig factoryConfig = StaticFactoryConfig( 13 | ECDomainParameters, 'secp256k1', () => ECCurve_secp256k1()); 14 | 15 | factory ECCurve_secp256k1() => constructFpStandardCurve( 16 | 'secp256k1', ECCurve_secp256k1._make, 17 | q: BigInt.parse( 18 | 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f', 19 | radix: 16), 20 | a: BigInt.parse('0', radix: 16), 21 | b: BigInt.parse('7', radix: 16), 22 | g: BigInt.parse( 23 | '0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8', 24 | radix: 16), 25 | n: BigInt.parse( 26 | 'fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141', 27 | radix: 16), 28 | h: BigInt.parse('1', radix: 16), 29 | seed: null) as ECCurve_secp256k1; 30 | 31 | static ECCurve_secp256k1 _make(String domainName, ECCurve curve, ECPoint G, 32 | BigInt n, BigInt h, List? seed) => 33 | ECCurve_secp256k1._super(domainName, curve, G, n, h, seed); 34 | 35 | ECCurve_secp256k1._super(super.domainName, super.curve, super.G, super.n, 36 | BigInt super._h, super.seed); 37 | } 38 | -------------------------------------------------------------------------------- /lib/impl.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | /// This library contains all out-of-the-box implementations of the interfaces provided in the API 4 | /// which are compatible with client and server sides. 5 | library impl; 6 | 7 | // cipher implementations 8 | 9 | // asymmetric 10 | export 'package:pointycastle/asymmetric/api.dart'; 11 | export 'package:pointycastle/ecc/api.dart'; 12 | export 'package:pointycastle/key_derivators/api.dart'; 13 | export 'package:pointycastle/key_generators/api.dart'; 14 | -------------------------------------------------------------------------------- /lib/key_derivators/argon2.dart: -------------------------------------------------------------------------------- 1 | export 'argon2_register64_impl.dart' 2 | if (dart.library.io) 'argon2_native_int_impl.dart'; 3 | -------------------------------------------------------------------------------- /lib/key_derivators/ecdh_kdf.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | import 'dart:typed_data'; 3 | 4 | import 'package:pointycastle/export.dart'; 5 | import 'package:pointycastle/src/impl/base_key_derivator.dart'; 6 | import 'package:pointycastle/src/utils.dart'; 7 | 8 | import '../src/registry/registry.dart'; 9 | 10 | class ECDHKeyDerivator extends BaseKeyDerivator { 11 | late ECDHKDFParameters parameters; 12 | static final FactoryConfig factoryConfig = 13 | StaticFactoryConfig(KeyDerivator, 'ECDH', () => ECDHKeyDerivator()); 14 | 15 | @override 16 | String get algorithmName => '/ECDH'; 17 | 18 | @override 19 | int deriveKey(Uint8List inp, int inpOff, Uint8List out, int outOff) { 20 | var ecdh = ECDHBasicAgreement()..init(parameters.privateKey); 21 | var ag = ecdh.calculateAgreement(parameters.publicKey); 22 | var key = encodeBigIntAsUnsigned(ag); 23 | // pad to keysize 24 | var padlength = max((keySize / 8).ceil() - key.length, 0); 25 | out.setAll(outOff, Uint8List.fromList(List.filled(padlength, 0))); 26 | out.setAll(outOff + padlength, key); 27 | return padlength + key.length; 28 | } 29 | 30 | @override 31 | void init(covariant ECDHKDFParameters params) { 32 | parameters = params; 33 | } 34 | 35 | @override 36 | int get keySize => parameters.privateKey.parameters!.curve.fieldSize; 37 | } 38 | -------------------------------------------------------------------------------- /lib/key_generators/api.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library api.key_generators; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | import 'package:pointycastle/ecc/api.dart'; 7 | 8 | /// Abstract [CipherParameters] to init an ECC key generator. 9 | class ECKeyGeneratorParameters extends KeyGeneratorParameters { 10 | final ECDomainParameters _domainParameters; 11 | 12 | ECKeyGeneratorParameters(ECDomainParameters domainParameters) 13 | : _domainParameters = domainParameters, 14 | super(domainParameters.n.bitLength); 15 | 16 | ECDomainParameters get domainParameters => _domainParameters; 17 | } 18 | 19 | /// Abstract [CipherParameters] to init an RSA key generator. 20 | class RSAKeyGeneratorParameters extends KeyGeneratorParameters { 21 | final BigInt publicExponent; 22 | final int certainty; 23 | 24 | RSAKeyGeneratorParameters( 25 | this.publicExponent, int bitStrength, this.certainty) 26 | : super(bitStrength); 27 | } 28 | -------------------------------------------------------------------------------- /lib/key_generators/ec_key_generator.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.key_generator.ec_key_generator; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | import 'package:pointycastle/ecc/api.dart'; 7 | import 'package:pointycastle/key_generators/api.dart'; 8 | import 'package:pointycastle/src/registry/registry.dart'; 9 | 10 | /// Abstract [CipherParameters] to init an ECC key generator. 11 | class ECKeyGenerator implements KeyGenerator { 12 | static final FactoryConfig factoryConfig = 13 | StaticFactoryConfig(KeyGenerator, 'EC', () => ECKeyGenerator()); 14 | 15 | late ECDomainParameters _params; 16 | late SecureRandom _random; 17 | 18 | @override 19 | String get algorithmName => 'EC'; 20 | 21 | @override 22 | void init(CipherParameters params) { 23 | ECKeyGeneratorParameters ecparams; 24 | 25 | if (params is ParametersWithRandom) { 26 | _random = params.random; 27 | ecparams = params.parameters as ECKeyGeneratorParameters; 28 | } else { 29 | _random = SecureRandom(); 30 | ecparams = params as ECKeyGeneratorParameters; 31 | } 32 | 33 | _params = ecparams.domainParameters; 34 | } 35 | 36 | @override 37 | AsymmetricKeyPair generateKeyPair() { 38 | var n = _params.n; 39 | var nBitLength = n.bitLength; 40 | BigInt? d; 41 | 42 | do { 43 | d = _random.nextBigInteger(nBitLength); 44 | } while (d == BigInt.zero || (d >= n)); 45 | 46 | var Q = _params.G * d; 47 | 48 | return AsymmetricKeyPair(ECPublicKey(Q, _params), ECPrivateKey(d, _params)); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /lib/paddings/iso7816d4.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.padding.iso7816d4; 4 | 5 | import 'dart:typed_data' show Uint8List; 6 | 7 | import 'package:pointycastle/api.dart'; 8 | import 'package:pointycastle/src/impl/base_padding.dart'; 9 | import 'package:pointycastle/src/registry/registry.dart'; 10 | 11 | /// A padder that adds the padding according to the scheme referenced in 12 | /// ISO 7814-4 - scheme 2 from ISO 9797-1. The first byte is 0x80, rest is 0x00 13 | class ISO7816d4Padding extends BasePadding { 14 | static final FactoryConfig factoryConfig = 15 | StaticFactoryConfig(Padding, 'ISO7816-4', () => ISO7816d4Padding()); 16 | 17 | @override 18 | String get algorithmName => 'ISO7816-4'; 19 | 20 | @override 21 | void init([CipherParameters? params]) { 22 | // nothing to do. 23 | } 24 | 25 | /// add the pad bytes to the passed in block, returning the 26 | /// number of bytes added. 27 | @override 28 | int addPadding(Uint8List data, int offset) { 29 | var added = data.length - offset; 30 | 31 | data[offset] = 0x80; 32 | offset++; 33 | 34 | while (offset < data.length) { 35 | data[offset] = 0; 36 | offset++; 37 | } 38 | 39 | return added; 40 | } 41 | 42 | /// return the number of pad bytes present in the block. 43 | @override 44 | int padCount(Uint8List data) { 45 | var count = data.length - 1; 46 | 47 | while (count > 0 && data[count] == 0) { 48 | count--; 49 | } 50 | 51 | if (data[count] != 0x80) { 52 | throw ArgumentError('pad block corrupted'); 53 | } 54 | 55 | return data.length - count; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /lib/paddings/pkcs7.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.padding.pkcs7; 4 | 5 | import 'dart:typed_data'; 6 | 7 | import 'package:pointycastle/api.dart'; 8 | import 'package:pointycastle/src/impl/base_padding.dart'; 9 | import 'package:pointycastle/src/registry/registry.dart'; 10 | import 'package:pointycastle/src/ufixnum.dart'; 11 | 12 | /// A [Padding] that adds PKCS7/PKCS5 padding to a block. 13 | class PKCS7Padding extends BasePadding { 14 | static final FactoryConfig factoryConfig = 15 | StaticFactoryConfig(Padding, 'PKCS7', () => PKCS7Padding()); 16 | 17 | @override 18 | String get algorithmName => 'PKCS7'; 19 | 20 | @override 21 | void init([CipherParameters? params]) { 22 | // nothing to do. 23 | } 24 | 25 | @override 26 | int addPadding(Uint8List data, int offset) { 27 | var code = data.length - offset; 28 | 29 | while (offset < data.length) { 30 | data[offset] = code; 31 | offset++; 32 | } 33 | 34 | return code; 35 | } 36 | 37 | @override 38 | int padCount(Uint8List data) { 39 | var count = clip8(data[data.length - 1]); 40 | 41 | if (count > data.length || count == 0) { 42 | throw ArgumentError('Invalid or corrupted pad block'); 43 | } 44 | 45 | for (var i = 1; i <= count; i++) { 46 | if (data[data.length - i] != count) { 47 | throw ArgumentError('Invalid or corrupted pad block'); 48 | } 49 | } 50 | 51 | return count; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /lib/pointycastle.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | /// 4 | /// This is the main entry point to the cipher library API. 5 | /// 6 | /// It includes the following libraries: 7 | /// * **api.dart** = comprises the whole API specification 8 | /// * **impl.dart** = defines algorithm implementations and all cipherParameters to be used with them 9 | /// * **asn1.dart** = ASN1 library to encode and decode ASN1 objects 10 | /// 11 | library pointycastle; 12 | 13 | export 'package:pointycastle/api.dart'; 14 | export 'package:pointycastle/impl.dart'; 15 | export 'package:pointycastle/asn1.dart'; 16 | -------------------------------------------------------------------------------- /lib/random/fortuna_random.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.secure_random.fortuna_random; 4 | 5 | import 'dart:typed_data'; 6 | 7 | import 'package:pointycastle/api.dart'; 8 | import 'package:pointycastle/block/aes.dart'; 9 | import 'package:pointycastle/random/auto_seed_block_ctr_random.dart'; 10 | import 'package:pointycastle/src/registry/registry.dart'; 11 | 12 | /// An implementation of [SecureRandom] as specified in the Fortuna algorithm. 13 | class FortunaRandom implements SecureRandom { 14 | static final FactoryConfig factoryConfig = 15 | StaticFactoryConfig(SecureRandom, 'Fortuna', () => FortunaRandom()); 16 | 17 | final AESEngine _aes; 18 | late AutoSeedBlockCtrRandom _prng; 19 | 20 | @override 21 | String get algorithmName => 'Fortuna'; 22 | 23 | FortunaRandom() : _aes = AESEngine() { 24 | _prng = AutoSeedBlockCtrRandom(_aes, false); 25 | } 26 | 27 | @override 28 | void seed(covariant KeyParameter param) { 29 | if (param.key.length != 32) { 30 | throw ArgumentError('Fortuna PRNG can only be used with 256 bits keys'); 31 | } 32 | 33 | final iv = Uint8List(16); 34 | iv[15] = 1; 35 | _prng.seed(ParametersWithIV(param, iv)); 36 | } 37 | 38 | @override 39 | int nextUint8() => _prng.nextUint8(); 40 | 41 | @override 42 | int nextUint16() => _prng.nextUint16(); 43 | 44 | @override 45 | int nextUint32() => _prng.nextUint32(); 46 | 47 | @override 48 | BigInt nextBigInteger(int bitLength) => _prng.nextBigInteger(bitLength); 49 | 50 | @override 51 | Uint8List nextBytes(int count) { 52 | if (count > 1048576) { 53 | throw ArgumentError( 54 | 'Fortuna PRNG cannot generate more than 1MB of random data per invocation'); 55 | } 56 | 57 | return _prng.nextBytes(count); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /lib/src/api/aead_block_cipher.dart: -------------------------------------------------------------------------------- 1 | part of '../../api.dart'; 2 | 3 | /// A block cipher mode that includes authenticated encryption 4 | abstract class AEADBlockCipher extends BlockCipher { 5 | factory AEADBlockCipher(String algorithmName) => 6 | registry.create(algorithmName); 7 | 8 | /// Process [len] bytes from [inp] starting at offset [inpOff] and output the 9 | /// result to [out] at offset [outOff]. 10 | /// 11 | /// Returns the number of bytes written to the output. 12 | int processBytes( 13 | Uint8List inp, int inpOff, int len, Uint8List out, int outOff); 14 | 15 | /// Finish the operation either appending or verifying the MAC at the end of 16 | /// the data. 17 | /// 18 | /// Returns the number of bytes written to the output. 19 | int doFinal(Uint8List out, int outOff); 20 | } 21 | 22 | class InvalidCipherTextException implements Exception { 23 | final String message; 24 | 25 | InvalidCipherTextException(this.message); 26 | } 27 | -------------------------------------------------------------------------------- /lib/src/api/aead_cipher.dart: -------------------------------------------------------------------------------- 1 | part of '../../api.dart'; 2 | 3 | abstract class AEADCipher extends Algorithm { 4 | void init(bool forEncryption, CipherParameters params); 5 | 6 | factory AEADCipher(String algorithmName) => 7 | registry.create(algorithmName); 8 | 9 | @override 10 | String get algorithmName; 11 | 12 | void processAADByte(int inp); 13 | 14 | void processAADBytes(Uint8List inp, int inpOff, int len); 15 | 16 | int processByte(int inp, Uint8List out, int outOff); 17 | 18 | int processBytes( 19 | Uint8List inp, int inOff, int len, Uint8List out, int outOff); 20 | 21 | int doFinal(Uint8List out, int outOff); 22 | 23 | Uint8List get mac; 24 | 25 | int getUpdateOutputSize(int len); 26 | 27 | int getOutputSize(int len); 28 | 29 | void reset(); 30 | } 31 | -------------------------------------------------------------------------------- /lib/src/api/aead_parameters.dart: -------------------------------------------------------------------------------- 1 | part of '../../api.dart'; 2 | 3 | // ignore_for_file: omit_local_variable_types, prefer_single_quotes, non_constant_identifier_names, directives_ordering, prefer_typing_uninitialized_variables 4 | 5 | class AEADParameters 6 | implements CipherParameters { 7 | final UnderlyingCipherParameters parameters; 8 | 9 | final Uint8List associatedData; 10 | 11 | final Uint8List nonce; 12 | 13 | final int macSize; 14 | 15 | AEADParameters( 16 | this.parameters, this.macSize, this.nonce, this.associatedData); 17 | } 18 | -------------------------------------------------------------------------------- /lib/src/api/algorithm.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// All algorithms defined by Pointy Castle inherit from this class. 6 | abstract class Algorithm { 7 | /// Get this algorithm's standard name. 8 | String get algorithmName; 9 | } 10 | -------------------------------------------------------------------------------- /lib/src/api/asymmetric_block_cipher.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// Asymmetric block cipher engines are expected to conform to this interface. 6 | abstract class AsymmetricBlockCipher extends Algorithm { 7 | /// Create the cipher specified by the standard [algorithmName]. 8 | factory AsymmetricBlockCipher(String algorithmName) => 9 | registry.create(algorithmName); 10 | 11 | /// Get this ciphers's maximum input block size. 12 | int get inputBlockSize; 13 | 14 | /// Get this ciphers's maximum output block size. 15 | int get outputBlockSize; 16 | 17 | /// Reset the cipher to its original state. 18 | void reset(); 19 | 20 | /// Init the cipher with its initialization [params]. The type of [CipherParameters] depends on the algorithm being used (see 21 | /// the documentation of each implementation to find out more). 22 | /// 23 | /// Use the argument [forEncryption] to tell the cipher if you want to encrypt or decrypt data. 24 | void init(bool forEncryption, CipherParameters params); 25 | 26 | /// Process a whole block of [data] at once, returning the result in a byte array. 27 | Uint8List process(Uint8List data); 28 | 29 | /// Process a block of [len] bytes given by [inp] and starting at offset [inpOff] and put the resulting cipher text in [out] 30 | /// beginning at position [outOff]. 31 | /// 32 | /// This method returns the total bytes put in the output buffer. 33 | int processBlock( 34 | Uint8List inp, int inpOff, int len, Uint8List out, int outOff); 35 | } 36 | -------------------------------------------------------------------------------- /lib/src/api/asymmetric_key.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// The interface that asymmetric (public and private) keys conform to. 6 | abstract class AsymmetricKey {} 7 | -------------------------------------------------------------------------------- /lib/src/api/asymmetric_key_pair.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// A pair of public and private asymmetric keys. 6 | class AsymmetricKeyPair { 7 | final B publicKey; 8 | final V privateKey; 9 | 10 | AsymmetricKeyPair(this.publicKey, this.privateKey); 11 | 12 | @override 13 | bool operator ==(Object other) => 14 | identical(this, other) || 15 | other is AsymmetricKeyPair && 16 | runtimeType == other.runtimeType && 17 | publicKey == other.publicKey && 18 | privateKey == other.privateKey; 19 | 20 | @override 21 | int get hashCode => publicKey.hashCode ^ privateKey.hashCode; 22 | } 23 | -------------------------------------------------------------------------------- /lib/src/api/asymmetric_key_parameter.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// Abstract [CipherParameters] to hold an asymmetric (public or private) key 6 | abstract class AsymmetricKeyParameter 7 | implements CipherParameters { 8 | final T key; 9 | 10 | AsymmetricKeyParameter(this.key); 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/api/block_cipher.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// Block cipher engines are expected to conform to this interface. 6 | abstract class BlockCipher extends Algorithm { 7 | /// Create the cipher specified by the standard [algorithmName]. 8 | factory BlockCipher(String algorithmName) => 9 | registry.create(algorithmName); 10 | 11 | /// Get this ciphers's block size. 12 | int get blockSize; 13 | 14 | /// Reset the cipher to its original state. 15 | void reset(); 16 | 17 | /// Init the cipher with its initialization [params]. The type of 18 | /// [CipherParameters] depends on the algorithm being used (see the 19 | /// documentation of each implementation to find out more). 20 | /// 21 | /// Use the argument [forEncryption] to tell the cipher if you want to encrypt 22 | /// or decrypt data. 23 | void init(bool forEncryption, CipherParameters? params); 24 | 25 | /// Process a whole block of [blockSize] bytes stored in [data] at once, returning the result in a 26 | /// byte array. 27 | /// 28 | /// This call is equivalent to [processBlock] but it allocates the array under the hood. 29 | Uint8List process(Uint8List data); 30 | 31 | /// Process a whole block of data given by [inp] and starting at offset 32 | /// [inpOff]. 33 | /// 34 | /// The resulting cipher text is put in [out] beginning at position [outOff]. 35 | /// 36 | /// This method returns the total bytes processed (which is the same as the 37 | /// block size of the algorithm). 38 | int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff); 39 | } 40 | -------------------------------------------------------------------------------- /lib/src/api/cipher_parameters.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// All cipher initialization parameters classes implement this. 6 | abstract class CipherParameters {} 7 | -------------------------------------------------------------------------------- /lib/src/api/des_parameters.dart: -------------------------------------------------------------------------------- 1 | part of '../../api.dart'; 2 | 3 | class DESParameters extends KeyParameter { 4 | final int DES_KEY_LENGTH = 8; 5 | 6 | DESParameters(super.key); 7 | } 8 | -------------------------------------------------------------------------------- /lib/src/api/desede_parameters.dart: -------------------------------------------------------------------------------- 1 | part of '../../api.dart'; 2 | 3 | class DESedeParameters extends DESParameters { 4 | final int DES_EDE_KEY_LENGTH = 24; 5 | 6 | DESedeParameters(super.key); 7 | } 8 | -------------------------------------------------------------------------------- /lib/src/api/digest.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// The interface that a message digest conforms to. 6 | abstract class Digest extends Algorithm { 7 | /// Create the digest specified by the standard [algorithmName]. 8 | factory Digest(String algorithmName) => 9 | registry.create(algorithmName); 10 | 11 | /// Get this digest's output size in bytes 12 | int get digestSize; 13 | 14 | /// Return the size in bytes of the internal buffer the digest applies 15 | /// it's compression function to. 16 | int get byteLength; 17 | 18 | /// Reset the digest to its original state. 19 | void reset(); 20 | 21 | /// Process a whole block of [data] at once, returning the result in a new byte array. 22 | Uint8List process(Uint8List data); 23 | 24 | /// Add one byte of data to the digested input. 25 | void updateByte(int inp); 26 | 27 | /// Add [len] bytes of data contained in [inp], starting at position [inpOff] 28 | /// ti the digested input. 29 | void update(Uint8List inp, int inpOff, int len); 30 | 31 | /// Store the digest of previously given data in buffer [out] starting at 32 | /// offset [outOff]. This method returns the size of the digest. 33 | int doFinal(Uint8List out, int outOff); 34 | } 35 | -------------------------------------------------------------------------------- /lib/src/api/key_derivator.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// The interface that a symmetric key derivator conforms to. 6 | /// 7 | /// A [KeyDerivator] is normally used to convert some master data (like a password, for instance) to a symmetric key. 8 | abstract class KeyDerivator extends Algorithm { 9 | /// Create the key derivator specified by the standard [algorithmName]. 10 | factory KeyDerivator(String algorithmName) => 11 | registry.create(algorithmName); 12 | 13 | /// Get this derivator key's output size. 14 | int get keySize; 15 | 16 | /// Init the derivator with its initialization [params]. The type of [CipherParameters] depends on the algorithm being used 17 | /// (see the documentation of each implementation to find out more). 18 | void init(CipherParameters params); 19 | 20 | /// Process a whole block of [data] at once, returning the result in a byte array. 21 | Uint8List process(Uint8List data); 22 | 23 | /// Derive key from given input and put it in [out] at offset [outOff]. 24 | int deriveKey(Uint8List inp, int inpOff, Uint8List out, int outOff); 25 | } 26 | -------------------------------------------------------------------------------- /lib/src/api/key_generator.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// The interface that asymmetric key generators conform to. 6 | /// 7 | /// A [KeyGenerator] is used to create a pair of public and private keys. 8 | abstract class KeyGenerator extends Algorithm { 9 | /// Create the key generator specified by the standard [algorithmName]. 10 | factory KeyGenerator(String algorithmName) => 11 | registry.create(algorithmName); 12 | 13 | /// Init the generator with its initialization [params]. The type of [CipherParameters] depends on the algorithm being used 14 | /// (see the documentation of each implementation to find out more). 15 | void init(CipherParameters params); 16 | 17 | /// Generate a key pair. 18 | AsymmetricKeyPair generateKeyPair(); 19 | } 20 | -------------------------------------------------------------------------------- /lib/src/api/key_generator_parameters.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// Abstract [CipherParameters] to init an asymmetric key generator. 6 | abstract class KeyGeneratorParameters implements CipherParameters { 7 | final int bitStrength; 8 | 9 | KeyGeneratorParameters(this.bitStrength); 10 | } 11 | -------------------------------------------------------------------------------- /lib/src/api/key_parameter.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// [CipherParameters] consisting of just a key of arbitrary length. 6 | class KeyParameter extends CipherParameters { 7 | late Uint8List key; 8 | 9 | KeyParameter(this.key); 10 | 11 | KeyParameter.offset(Uint8List key, int keyOff, int keyLen) { 12 | this.key = Uint8List(keyLen); 13 | arrayCopy(key, keyOff, this.key, 0, keyLen); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/src/api/mac.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// The interface that a MAC (message authentication code) conforms to. 6 | abstract class Mac extends Algorithm { 7 | /// Create the MAC specified by the standard [algorithmName]. 8 | factory Mac(String algorithmName) => registry.create(algorithmName); 9 | 10 | /// Get this MAC's output size. 11 | int get macSize; 12 | 13 | /// Reset the MAC to its original state. 14 | void reset(); 15 | 16 | /// Init the MAC with its initialization [params]. The type of 17 | /// [CipherParameters] depends on the algorithm being used (see 18 | /// the documentation of each implementation to find out more). 19 | void init(CipherParameters params); 20 | 21 | /// Process a whole block of [data] at once, returning the result in a new 22 | /// byte array. 23 | Uint8List process(Uint8List data); 24 | 25 | /// Add one byte of data to the MAC input. 26 | void updateByte(int inp); 27 | 28 | /// Add [len] bytes of data contained in [inp], starting at position [inpOff] 29 | /// to the MAC'ed input. 30 | void update(Uint8List inp, int inpOff, int len); 31 | 32 | /// Store the MAC of previously given data in buffer [out] starting at 33 | /// offset [outOff]. This method returns the size of the digest. 34 | int doFinal(Uint8List out, int outOff); 35 | } 36 | -------------------------------------------------------------------------------- /lib/src/api/padded_block_cipher_parameters.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// [CipherParameters] for [PaddedBlockCipher]s consisting of two underlying [CipherParameters], one for the [BlockCipher] (of 6 | /// type [UnderlyingCipherParameters]) and the other for the [Padding] (of type [PaddingCipherParameters]). 7 | class PaddedBlockCipherParameters< 8 | UnderlyingCipherParameters extends CipherParameters?, 9 | PaddingCipherParameters extends CipherParameters?> 10 | implements CipherParameters { 11 | final UnderlyingCipherParameters? underlyingCipherParameters; 12 | final PaddingCipherParameters? paddingCipherParameters; 13 | 14 | PaddedBlockCipherParameters( 15 | this.underlyingCipherParameters, this.paddingCipherParameters); 16 | } 17 | -------------------------------------------------------------------------------- /lib/src/api/padding.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// The interface that a padding conforms to. 6 | abstract class Padding extends Algorithm { 7 | /// Create the digest specified by the standard [algorithmName]. 8 | factory Padding(String algorithmName) => 9 | registry.create(algorithmName); 10 | 11 | /// Initialise the padder. Normally, paddings don't need any init params. 12 | void init([CipherParameters? params]); 13 | 14 | /// Process a whole block of [data] at once, returning the result in a byte array. If [pad] is 15 | /// true adds padding to the given block, otherwise, padding is removed. 16 | /// 17 | /// Note: this assumes that the last block of plain text is always passed to it inside [data]. The 18 | /// reason for this is that some modes such as 'trailing bit compliment' base the padding on the 19 | /// last byte of plain text. 20 | Uint8List process(bool pad, Uint8List data); 21 | 22 | /// Add the pad bytes to the passed in block, returning the number of bytes added. 23 | /// 24 | /// Note: this assumes that the last block of plain text is always passed to it inside [data]. i.e. 25 | /// if [offset] is zero, indicating the entire block is to be overwritten with padding the value of 26 | /// [data] should be the same as the last block of plain text. The reason for this is that some 27 | /// modes such as 'trailing bit compliment' base the padding on the last byte of plain text. 28 | int addPadding(Uint8List data, int offset); 29 | 30 | /// Get the number of pad bytes present in the block. 31 | int padCount(Uint8List data); 32 | } 33 | -------------------------------------------------------------------------------- /lib/src/api/parameters_with_iv.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// [CipherParameters] consisting of an underlying [CipherParameters] (of type [UnderlyingParameters]) and an initialization 6 | /// vector of arbitrary length. 7 | class ParametersWithIV 8 | implements CipherParameters { 9 | final Uint8List iv; 10 | final UnderlyingParameters? parameters; 11 | 12 | ParametersWithIV(this.parameters, this.iv); 13 | } 14 | -------------------------------------------------------------------------------- /lib/src/api/parameters_with_random.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | //TODO consider mixin 6 | /// [CipherParameters] consisting of an underlying [CipherParameters] (of type 7 | /// [UnderlyingParameters]) and an acompanying [SecureRandom]. 8 | class ParametersWithRandom 9 | implements CipherParameters { 10 | final UnderlyingParameters parameters; 11 | final SecureRandom random; 12 | 13 | ParametersWithRandom(this.parameters, this.random); 14 | } 15 | -------------------------------------------------------------------------------- /lib/src/api/parameters_with_salt.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// [CipherParameters] consisting of an underlying [CipherParameters] (of type 6 | /// [UnderlyingParameters]) and an acompanying salt of type [Uint8List]. 7 | class ParametersWithSalt 8 | implements CipherParameters { 9 | final UnderlyingParameters parameters; 10 | final Uint8List salt; 11 | 12 | ParametersWithSalt(this.parameters, this.salt); 13 | } 14 | -------------------------------------------------------------------------------- /lib/src/api/parameters_with_salt_configuration.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// [CipherParameters] consisting of an underlying [CipherParameters] (of type 6 | /// [UnderlyingParameters]), an acompanying [SecureRandom], and salt length. 7 | class ParametersWithSaltConfiguration< 8 | UnderlyingParameters extends CipherParameters> implements CipherParameters { 9 | final UnderlyingParameters parameters; 10 | final SecureRandom random; 11 | final int saltLength; 12 | 13 | ParametersWithSaltConfiguration( 14 | this.parameters, this.random, this.saltLength); 15 | } 16 | -------------------------------------------------------------------------------- /lib/src/api/pbe_parameters_generator.dart: -------------------------------------------------------------------------------- 1 | part of '../../api.dart'; 2 | 3 | abstract class PBEParametersGenerator { 4 | factory PBEParametersGenerator(String algorithmName) => 5 | registry.create(algorithmName); 6 | 7 | void init(Uint8List password, Uint8List salt, int iterationCount); 8 | 9 | /// 10 | /// Generates a derived key with the given [keySize] in bytes. 11 | /// 12 | KeyParameter generateDerivedParameters(int keySize); 13 | 14 | /// 15 | /// Generates a derived key with the given [keySize] in bytes and a derived IV with the given [ivSize]. 16 | /// 17 | ParametersWithIV generateDerivedParametersWithIV(int keySize, int ivSize); 18 | 19 | /// 20 | /// Generates a derived key with the given [keySize] in bytes used for mac generating. 21 | /// 22 | KeyParameter generateDerivedMacParameters(int keySize); 23 | } 24 | -------------------------------------------------------------------------------- /lib/src/api/private_key.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// The interface that asymmetric private keys conform to. 6 | abstract class PrivateKey implements AsymmetricKey {} 7 | -------------------------------------------------------------------------------- /lib/src/api/private_key_parameter.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// A [CipherParameters] to hold an asymmetric private key 6 | class PrivateKeyParameter 7 | extends AsymmetricKeyParameter { 8 | PrivateKeyParameter(PrivateKey key) : super(key as T); 9 | } 10 | -------------------------------------------------------------------------------- /lib/src/api/public_key.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// The interface that asymmetric public keys conform to. 6 | abstract class PublicKey implements AsymmetricKey {} 7 | -------------------------------------------------------------------------------- /lib/src/api/public_key_parameter.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// A [CipherParameters] to hold an asymmetric public key 6 | class PublicKeyParameter 7 | extends AsymmetricKeyParameter { 8 | PublicKeyParameter(PublicKey key) : super(key as T); 9 | } 10 | -------------------------------------------------------------------------------- /lib/src/api/rc2_parameters.dart: -------------------------------------------------------------------------------- 1 | part of '../../api.dart'; 2 | 3 | class RC2Parameters extends KeyParameter { 4 | late int effectiveKeyBits; 5 | 6 | RC2Parameters(Uint8List key, {int? bits}) : super(key) { 7 | if (bits != null) { 8 | effectiveKeyBits = bits; 9 | } else { 10 | effectiveKeyBits = (key.length > 128) ? 1024 : (key.length * 8); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /lib/src/api/registry_factory_exception.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// This kind of exception is thrown when a user tries to create an algorithm 6 | /// or domain parameters that were not correctly registered. This can be 7 | /// because the corresponding class was not imported, or because the algorithm 8 | /// does not exist. 9 | class RegistryFactoryException implements Exception { 10 | final String message; 11 | 12 | RegistryFactoryException(this.message); 13 | 14 | RegistryFactoryException.unknown(String algorithm, [Type? type]) 15 | : this( 16 | 'No algorithm registered${type != null ? ' of type $type' : ''} with name: $algorithm'); 17 | 18 | RegistryFactoryException.invalid(String algorithm, [Type? type]) 19 | : this( 20 | 'Algorithm name $algorithm is invalid${type != null ? ' of type $type' : ''}'); 21 | 22 | @override 23 | String toString() => 'RegistryFactoryException: $message'; 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/api/secure_random.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// A synchronous secure random number generator (RNG). 6 | /// 7 | /// Being synchronous, this RNG cannot return direct results from sources of randomness like 8 | /// '/dev/random' or similar. For that, use an **EntropySource** which allows to be called 9 | /// asynchronously. Usually an **EntropySource** should be seen like a random generation device while 10 | /// a [SecureRandom] should be seen like a cryptographic PRNG. Thus, data from an **EntropySource** 11 | /// should be seen as 'more random' than that returned from a [SecureRandom]. 12 | abstract class SecureRandom extends Algorithm { 13 | /// Create the secure random specified by the standard [algorithmName]. 14 | factory SecureRandom([String algorithmName = '']) => 15 | registry.create(algorithmName); 16 | 17 | /// Seed the RNG with some entropy (look at package cipher_entropy providing entropy sources). 18 | void seed(CipherParameters params); 19 | 20 | /// Get one byte long random int. 21 | int nextUint8(); 22 | 23 | /// Get two bytes long random int. 24 | int nextUint16(); 25 | 26 | /// Get four bytes long random int. 27 | int nextUint32(); 28 | 29 | /// Get a random BigInteger of [bitLength] bits. 30 | BigInt nextBigInteger(int bitLength); 31 | 32 | /// Get a list of bytes of arbitrary length. 33 | Uint8List nextBytes(int count); 34 | } 35 | -------------------------------------------------------------------------------- /lib/src/api/signature.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// An interface for signatures created by a [Signer] 6 | abstract class Signature {} 7 | -------------------------------------------------------------------------------- /lib/src/api/signer.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// An interface for DSAs (digital signature algorithms) 6 | abstract class Signer extends Algorithm { 7 | /// Create the signer specified by the standard [algorithmName]. 8 | factory Signer(String algorithmName) => 9 | registry.create(algorithmName); 10 | 11 | /// Reset the signer to its original state. 12 | void reset(); 13 | 14 | /// Init the signer with its initialization [params]. The type of [CipherParameters] depends on the algorithm being used (see 15 | /// the documentation of each implementation to find out more). 16 | /// 17 | /// Use the argument [forSigning] to tell the signer if you want to generate or verify signatures. 18 | void init(bool forSigning, CipherParameters params); 19 | 20 | /// Sign the passed in [message] (usually the output of a hash function) 21 | Signature generateSignature(Uint8List message); 22 | 23 | /// Verify the [message] against the [signature]. 24 | bool verifySignature(Uint8List message, Signature signature); 25 | } 26 | -------------------------------------------------------------------------------- /lib/src/api/srp_client.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | abstract class SRPClient { 6 | ///Computes the client evidence message M1 using the previously received values. 7 | ///To be called after calculating the secret S. 8 | ///returns M1: the client side generated evidence message 9 | ///throws Exception 10 | BigInt? calculateClientEvidenceMessage(); 11 | 12 | ///Generates the secret S given the server's credentials 13 | ///@param serverB The server's credentials 14 | ///@return Client's verification message for the server 15 | ///@throws Exception If server's credentials are invalid 16 | /// 17 | BigInt? calculateSecret(BigInt serverB); 18 | 19 | /// Computes the final session key as a result of the SRP successful mutual authentication 20 | /// To be called after verifying the server evidence message M2. 21 | /// returns Key: the mutually authenticated symmetric session key 22 | /// throws Exception 23 | BigInt? calculateSessionKey(); 24 | 25 | /// Generates the client's credentials that are to be sent to the server. 26 | /// @return The client's public value 27 | BigInt? generateClientCredentials( 28 | Uint8List salt, Uint8List identity, Uint8List password); 29 | 30 | /// Authenticates the server evidence message M2 received and saves it only if correct. 31 | /// [serverM2] the server side generated evidence message 32 | /// return A boolean indicating if the server message M2 was the expected one. 33 | /// throws Exception 34 | bool verifyServerEvidenceMessage(BigInt serverM2); 35 | } 36 | -------------------------------------------------------------------------------- /lib/src/api/stream_cipher.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | part of '../../api.dart'; 4 | 5 | /// The interface stream ciphers conform to. 6 | abstract class StreamCipher extends Algorithm { 7 | /// Create the cipher specified by the standard [algorithmName]. 8 | factory StreamCipher(String algorithmName) => 9 | registry.create(algorithmName); 10 | 11 | /// Reset the cipher to its original state. 12 | void reset(); 13 | 14 | /// Init the cipher with its initialization [params]. The type of 15 | /// [CipherParameters] depends on the algorithm being used (see the 16 | /// documentation of each implementation to find out more). 17 | /// 18 | /// Use the argument [forEncryption] to tell the cipher if you want to encrypt 19 | /// or decrypt data. 20 | void init(bool forEncryption, CipherParameters? params); 21 | 22 | /// Process a whole block of [data] at once, returning the result in a byte array. 23 | Uint8List process(Uint8List data); 24 | 25 | /// Process one byte of data given by [inp] and return its encrypted value. 26 | int returnByte(int inp); 27 | 28 | /// Process [len] bytes of data given by [inp] and starting at offset [inpOff]. 29 | /// The resulting cipher text is put in [out] beginning at position [outOff]. 30 | void processBytes( 31 | Uint8List inp, int inpOff, int len, Uint8List out, int outOff); 32 | } 33 | -------------------------------------------------------------------------------- /lib/src/api/xof.dart: -------------------------------------------------------------------------------- 1 | part of '../../api.dart'; 2 | 3 | abstract class Xof extends Digest { 4 | /// Create the Xof specified by the standard [algorithmName]. 5 | factory Xof(String algorithmName) => registry.create(algorithmName); 6 | 7 | /// 8 | int doFinalRange(Uint8List out, int outOff, int outLen); 9 | 10 | int doOutput(Uint8List out, int outOff, int outLen); 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/ct.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | /// 6 | /// Constant time XOR, use to replace if (condition) { xor(x,y);} 7 | /// CT_xor, x <- x ^ y when b is true 8 | /// asserts x length and y length are equal 9 | /// 10 | void CT_xor(Uint8List x, Uint8List y, bool b) { 11 | assert(x.length == y.length, 'x length and y length must be same'); 12 | var mask = b ? 0xFF : 0; // (-b) & 0xFF; 13 | for (var i = 0; i < x.length; i++) { 14 | x[i] = x[i] ^ (y[i] & mask); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /lib/src/ec_standard_curve_constructor.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/ecc/ecc_base.dart'; 4 | import 'package:pointycastle/ecc/ecc_fp.dart' as fp; 5 | import 'package:pointycastle/src/utils.dart' as utils; 6 | 7 | ECDomainParametersImpl constructFpStandardCurve( 8 | String name, Function constructor, 9 | {BigInt? q, 10 | BigInt? a, 11 | BigInt? b, 12 | BigInt? g, 13 | BigInt? n, 14 | BigInt? h, 15 | BigInt? seed}) { 16 | var curve = fp.ECCurve(q, a, b); 17 | var seedBytes = (seed == null) ? null : utils.encodeBigInt(seed); 18 | return constructor( 19 | name, curve, curve.decodePoint(utils.encodeBigInt(g)), n, h, seedBytes); 20 | } 21 | -------------------------------------------------------------------------------- /lib/src/impl/base_aead_cipher.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import '../../api.dart'; 4 | 5 | abstract class BaseAEADCipher implements AEADCipher { 6 | Uint8List process(Uint8List data) { 7 | var out = Uint8List(data.length); 8 | processBytes(data, 0, data.length, out, 0); 9 | return out; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/impl/base_asymmetric_block_cipher.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | 7 | /// Base implementation of [AsymmetricBlockCipher] which provides shared methods. 8 | abstract class BaseAsymmetricBlockCipher implements AsymmetricBlockCipher { 9 | @override 10 | Uint8List process(Uint8List data) { 11 | var out = Uint8List(outputBlockSize); 12 | var len = processBlock(data, 0, data.length, out, 0); 13 | return out.sublist(0, len); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/src/impl/base_block_cipher.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | 7 | /// Base implementation of [BlockCipher] which provides shared methods. 8 | abstract class BaseBlockCipher implements BlockCipher { 9 | @override 10 | Uint8List process(Uint8List data) { 11 | var out = Uint8List(blockSize); 12 | var len = processBlock(data, 0, out, 0); 13 | return out.sublist(0, len); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/src/impl/base_digest.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | 7 | /// Base implementation of [Digest] which provides shared methods. 8 | abstract class BaseDigest implements Digest { 9 | @override 10 | Uint8List process(Uint8List data) { 11 | update(data, 0, data.length); 12 | var out = Uint8List(digestSize); 13 | var len = doFinal(out, 0); 14 | return out.sublist(0, len); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /lib/src/impl/base_key_derivator.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | 7 | /// Base implementation of [KeyDerivator] which provides shared methods. 8 | abstract class BaseKeyDerivator implements KeyDerivator { 9 | @override 10 | Uint8List process(Uint8List data) { 11 | var out = Uint8List(keySize); 12 | var len = deriveKey(data, 0, out, 0); 13 | return out.sublist(0, len); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/src/impl/base_mac.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | 7 | /// Base implementation of [Mac] which provides shared methods. 8 | abstract class BaseMac implements Mac { 9 | @override 10 | Uint8List process(Uint8List data) { 11 | update(data, 0, data.length); 12 | var out = Uint8List(macSize); 13 | var len = doFinal(out, 0); 14 | return out.sublist(0, len); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /lib/src/impl/base_padding.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | 7 | /// Base implementation of [Padding] which provides shared methods. 8 | abstract class BasePadding implements Padding { 9 | @override 10 | Uint8List process(bool pad, Uint8List data) { 11 | if (pad) { 12 | throw StateError( 13 | 'cannot add padding, use PaddedBlockCipher to add padding'); 14 | } else { 15 | var len = padCount(data); 16 | return data.sublist(0, data.length - len); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/src/impl/base_stream_cipher.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | 7 | /// Base implementation of [StreamCipher] which provides shared methods. 8 | abstract class BaseStreamCipher implements StreamCipher { 9 | @override 10 | Uint8List process(Uint8List data) { 11 | var out = Uint8List(data.length); 12 | processBytes(data, 0, data.length, out, 0); 13 | return out; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/src/impl/entropy.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | /// Defines an entropy source, this is not to be confused with a rng. 4 | /// Entropy sources are used to supply seed material. 5 | abstract class EntropySource { 6 | Uint8List getBytes(int len); 7 | } 8 | -------------------------------------------------------------------------------- /lib/src/impl/secure_random_base.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | import 'package:pointycastle/src/ufixnum.dart'; 7 | import 'package:pointycastle/src/utils.dart' as utils; 8 | 9 | /// An utility base implementation of [SecureRandom] so that only [nextUint8] method needs to be 10 | /// implemented. 11 | abstract class SecureRandomBase implements SecureRandom { 12 | @override 13 | int nextUint16() { 14 | var b0 = nextUint8(); 15 | var b1 = nextUint8(); 16 | return clip16((b1 << 8) | b0); 17 | } 18 | 19 | @override 20 | int nextUint32() { 21 | var b0 = nextUint8(); 22 | var b1 = nextUint8(); 23 | var b2 = nextUint8(); 24 | var b3 = nextUint8(); 25 | return clip32((b3 << 24) | (b2 << 16) | (b1 << 8) | b0); 26 | } 27 | 28 | @override 29 | BigInt nextBigInteger(int bitLength) { 30 | return utils.decodeBigIntWithSign(1, _randomBits(bitLength)); 31 | } 32 | 33 | @override 34 | Uint8List nextBytes(int count) { 35 | var bytes = Uint8List(count); 36 | for (var i = 0; i < count; i++) { 37 | bytes[i] = nextUint8(); 38 | } 39 | return bytes; 40 | } 41 | 42 | List _randomBits(int numBits) { 43 | if (numBits < 0) { 44 | throw ArgumentError('numBits must be non-negative'); 45 | } 46 | 47 | var numBytes = (numBits + 7) ~/ 8; // avoid overflow 48 | var randomBits = Uint8List(numBytes); 49 | 50 | // Generate random bytes and mask out any excess bits 51 | if (numBytes > 0) { 52 | for (var i = 0; i < numBytes; i++) { 53 | randomBits[i] = nextUint8(); 54 | } 55 | var excessBits = 8 * numBytes - numBits; 56 | randomBits[0] &= (1 << (8 - excessBits)) - 1; 57 | } 58 | return randomBits; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /lib/src/platform_check/abstract.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | import 'dart:typed_data'; 3 | 4 | import 'package:pointycastle/src/impl/entropy.dart'; 5 | 6 | import 'platform_check.dart'; 7 | 8 | class PlatformGeneric extends Platform { 9 | static final PlatformGeneric instance = PlatformGeneric(); 10 | 11 | const PlatformGeneric(); 12 | 13 | @override 14 | bool get isNative => false; 15 | 16 | @override 17 | String get platform => 'generic'; 18 | 19 | @override 20 | EntropySource platformEntropySource() { 21 | return _GenericEntropySource(); 22 | } 23 | } 24 | 25 | Platform getPlatform() => PlatformGeneric.instance; 26 | 27 | // Uses the built in entropy source 28 | class _GenericEntropySource implements EntropySource { 29 | final _src = Random.secure(); 30 | 31 | @override 32 | Uint8List getBytes(int len) { 33 | return Uint8List.fromList( 34 | List.generate(len, (i) => _src.nextInt(256))); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/src/platform_check/native.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io' as io; 2 | import 'dart:math'; 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/src/impl/entropy.dart'; 6 | 7 | import 'platform_check.dart'; 8 | 9 | class PlatformIO extends Platform { 10 | static final PlatformIO instance = PlatformIO(); 11 | 12 | const PlatformIO(); 13 | 14 | @override 15 | String get platform { 16 | if (io.Platform.isAndroid) return 'Android'; 17 | if (io.Platform.isIOS) return 'iOS'; 18 | if (io.Platform.isWindows) return 'Windows'; 19 | if (io.Platform.isLinux) return 'Linux'; 20 | if (io.Platform.isFuchsia) return 'Fuchsia'; 21 | if (io.Platform.isMacOS) return 'MacOS'; 22 | 23 | return 'native'; 24 | } 25 | 26 | @override 27 | bool get isNative => true; 28 | 29 | @override 30 | EntropySource platformEntropySource() { 31 | return _NativeRngProvider(); 32 | } 33 | } 34 | 35 | class _NativeRngProvider implements EntropySource { 36 | final _src = Random.secure(); 37 | 38 | @override 39 | Uint8List getBytes(int len) { 40 | return Uint8List.fromList( 41 | List.generate(len, (i) => _src.nextInt(256))); 42 | } 43 | } 44 | 45 | Platform getPlatform() => PlatformIO.instance; 46 | -------------------------------------------------------------------------------- /lib/src/platform_check/node_crypto.dart: -------------------------------------------------------------------------------- 1 | /// Wrapper for needed NodeJS Crypto library function and require. 2 | library nodecryto; 3 | 4 | import 'dart:js_interop'; 5 | import 'dart:js_interop_unsafe'; 6 | 7 | @JS() 8 | external JSObject require(String id); 9 | 10 | @JS() 11 | @staticInterop 12 | class NodeCrypto { 13 | static JSAny randomFillSync(JSAny buf) { 14 | final crypto = require('crypto'); 15 | return crypto.callMethod('randomFillSync'.toJS, buf); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lib/src/platform_check/platform_check.dart: -------------------------------------------------------------------------------- 1 | import 'package:pointycastle/src/impl/entropy.dart'; 2 | 3 | import 'abstract.dart' 4 | if (dart.library.io) 'native.dart' 5 | if (dart.library.js) 'web.dart'; 6 | 7 | abstract class Platform { 8 | static Platform get instance => getPlatform(); 9 | static const bool _fwInteger = 9007199254740992 + 1 != 9007199254740992; 10 | 11 | const Platform(); 12 | 13 | String get platform; 14 | 15 | bool get isNative; 16 | 17 | bool get fullWidthInteger => _fwInteger; 18 | 19 | void assertFullWidthInteger() { 20 | if (!_fwInteger) { 21 | throw PlatformException( 22 | 'full width integer not supported on this platform'); 23 | } 24 | } 25 | 26 | /// Platform dependent entropy source. 27 | EntropySource platformEntropySource(); 28 | } 29 | 30 | class PlatformException implements Exception { 31 | String cause; 32 | 33 | PlatformException(this.cause); 34 | 35 | @override 36 | String toString() => cause; 37 | } 38 | -------------------------------------------------------------------------------- /lib/src/platform_check/web.dart: -------------------------------------------------------------------------------- 1 | @JS() 2 | import 'dart:js_interop'; 3 | import 'dart:math'; 4 | import 'dart:typed_data'; 5 | 6 | import 'package:pointycastle/src/impl/entropy.dart'; 7 | 8 | import 'node_crypto.dart'; 9 | import 'platform_check.dart'; 10 | 11 | class PlatformWeb extends Platform { 12 | static final PlatformWeb instance = PlatformWeb(); 13 | static bool useBuiltInRng = false; 14 | 15 | PlatformWeb() { 16 | try { 17 | Random.secure(); 18 | useBuiltInRng = true; 19 | } on UnsupportedError { 20 | useBuiltInRng = false; 21 | } 22 | } 23 | 24 | @override 25 | bool get isNative => false; 26 | 27 | @override 28 | String get platform => 'web'; 29 | 30 | @override 31 | EntropySource platformEntropySource() { 32 | if (useBuiltInRng) { 33 | return _JsBuiltInEntropySource(); 34 | } else { 35 | // 36 | // Assume that if we cannot get a built in Secure RNG then we are 37 | // probably on NodeJS. 38 | // 39 | return _JsNodeEntropySource(); 40 | } 41 | } 42 | } 43 | 44 | // Uses the built in entropy source 45 | class _JsBuiltInEntropySource implements EntropySource { 46 | final _src = Random.secure(); 47 | 48 | @override 49 | Uint8List getBytes(int len) { 50 | return Uint8List.fromList( 51 | List.generate(len, (i) => _src.nextInt(256))); 52 | } 53 | } 54 | 55 | /// 56 | class _JsNodeEntropySource implements EntropySource { 57 | @override 58 | Uint8List getBytes(int len) { 59 | var list = Uint8List(len); 60 | NodeCrypto.randomFillSync(list.buffer.toJS); 61 | return list; 62 | } 63 | } 64 | 65 | Platform getPlatform() => PlatformWeb.instance; 66 | -------------------------------------------------------------------------------- /lib/src/registration.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | // 4 | // 5 | //TODO find out that these two methods are for! 6 | //BlockCipher _cfbBlockCipherFactory(String algorithmName) { 7 | // var parts = algorithmName.split("/"); 8 | // 9 | // if (parts.length != 2) return null; 10 | // if (!parts[1].startsWith("CFB-")) return null; 11 | // 12 | // var blockSizeInBits = int.parse(parts[1].substring(4)); 13 | // if ((blockSizeInBits % 8) != 0) { 14 | // throw new ArgumentError("Bad CFB block size: $blockSizeInBits (must be a multiple of 8)"); 15 | // } 16 | // 17 | // var underlyingCipher = _createOrNull(() => new BlockCipher(parts[0])); 18 | // 19 | // if (underlyingCipher != null) { 20 | // return new CFBBlockCipher(underlyingCipher, blockSizeInBits ~/ 8); 21 | // } 22 | // 23 | // return null; 24 | //} 25 | // 26 | //BlockCipher _ofbBlockCipherFactory(String algorithmName) { 27 | // var parts = algorithmName.split("/"); 28 | // 29 | // if (parts.length != 2) return null; 30 | // if (!parts[1].startsWith("OFB-")) return null; 31 | // 32 | // var blockSizeInBits = int.parse(parts[1].substring(4)); 33 | // if ((blockSizeInBits % 8) != 0) { 34 | // throw new ArgumentError("Bad OFB block size: $blockSizeInBits (must be a multiple of 8)"); 35 | // } 36 | // 37 | // var underlyingCipher = _createOrNull(() => new BlockCipher(parts[0])); 38 | // 39 | // if (underlyingCipher != null) { 40 | // return new OFBBlockCipher(underlyingCipher, blockSizeInBits ~/ 8); 41 | // } 42 | // 43 | // return null; 44 | //} 45 | -------------------------------------------------------------------------------- /lib/srp/srp6_verifier_generator.dart: -------------------------------------------------------------------------------- 1 | library src.srp_verifier_generator; 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/srp/srp6_standard_groups.dart'; 6 | import 'package:pointycastle/srp/srp6_util.dart'; 7 | import 'package:pointycastle/pointycastle.dart'; 8 | 9 | /// Generates new SRP verifier for user 10 | class SRP6VerifierGenerator { 11 | late BigInt N; 12 | late BigInt g; 13 | Digest digest; 14 | 15 | SRP6VerifierGenerator( 16 | {required SRP6GroupParameters group, required this.digest}) { 17 | N = group.N; 18 | g = group.g; 19 | } 20 | 21 | /// Creates a new SRP verifier 22 | /// [salt] The salt to use, generally should be large and random 23 | /// [identity] The user's identifying information (eg. username) 24 | /// [password] The user's password 25 | /// returns A new verifier for use in future SRP authentication 26 | BigInt generateVerifier( 27 | Uint8List salt, Uint8List identity, Uint8List password) { 28 | var x = SRP6Util.calculateX(digest, N, salt, identity, password); 29 | 30 | return g.modPow(x, N); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/stream/ctr.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | library impl.stream_cipher.ctr; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | import 'package:pointycastle/stream/sic.dart'; 7 | import 'package:pointycastle/src/registry/registry.dart'; 8 | 9 | /// Just an alias to be able to create SIC as CTR 10 | class CTRStreamCipher extends SICStreamCipher { 11 | /// Intended for internal use. 12 | static final FactoryConfig factoryConfig = DynamicFactoryConfig.suffix( 13 | StreamCipher, 14 | '/CTR', 15 | (_, final Match match) => () { 16 | var digestName = match.group(1); 17 | return CTRStreamCipher(BlockCipher(digestName!)); 18 | }); 19 | 20 | CTRStreamCipher(super.underlyingCipher); 21 | @override 22 | String get algorithmName => '${underlyingCipher.algorithmName}/CTR'; 23 | } 24 | -------------------------------------------------------------------------------- /licenses/LICENSE-BouncyCastle.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Copyright (c) 2000-2013 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) 9 |

10 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software 11 | and associated documentation files (the "Software"), to deal in the Software without restriction, 12 | including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 14 | subject to the following conditions: 15 |

16 | The above copyright notice and this permission notice shall be included in all copies or substantial 17 | portions of the Software. 18 |

19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 20 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 21 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | 26 | 27 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: pointycastle 2 | version: 4.0.0 3 | description: A Dart library implementing cryptographic algorithms and primitives, modeled on the BouncyCastle library. 4 | homepage: https://github.com/bcgit/pc-dart 5 | topics: 6 | - crypto 7 | - rsa 8 | - ecc 9 | - asn1 10 | 11 | environment: 12 | sdk: ^3.2.0 13 | 14 | dependencies: 15 | collection: ^1.15.0 16 | convert: ^3.0.0 17 | 18 | dev_dependencies: 19 | benchmark_harness: ^2.0.0 20 | lints: ^3.0.0 21 | test: ^1.16.0 22 | -------------------------------------------------------------------------------- /script/object_identifiers.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'dart:io'; 3 | 4 | /// 5 | /// Small script to convert the .csv file to dart code to replace the internal object identifier database 6 | /// 7 | void main(List args) { 8 | var f = File('script/object_identifiers.csv'); 9 | var list = >[]; 10 | var added = []; 11 | for (var l in f.readAsLinesSync()) { 12 | var splitted = l.split(','); 13 | var s = splitted.elementAt(0); 14 | var splittedInts = s.split('.'); 15 | var asInt = []; 16 | for (var i in splittedInts) { 17 | asInt.add(int.parse(i)); 18 | } 19 | var identifierString = splitted.elementAt(0); 20 | var readableName = splitted.elementAt(1); 21 | if (added.contains(identifierString)) { 22 | print('already added $identifierString ($readableName)'); 23 | } else { 24 | added.add(splitted.elementAt(0)); 25 | } 26 | list.add({ 27 | 'identifierString': identifierString, 28 | 'readableName': readableName, 29 | 'identifier': asInt 30 | }); 31 | } 32 | print(json.encode(list)); 33 | } 34 | -------------------------------------------------------------------------------- /test/adapters/stream_cipher_as_block_cipher_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:test/test.dart'; 4 | import 'package:pointycastle/adapters/stream_cipher_as_block_cipher.dart'; 5 | 6 | import '../test/runners/block_cipher.dart'; 7 | import '../test/src/helpers.dart'; 8 | import '../test/src/null_stream_cipher.dart'; 9 | 10 | void main() { 11 | var cbc = StreamCipherAsBlockCipher(16, NullStreamCipher()); 12 | group('StreamCipherAsBlockCipher:', () { 13 | runBlockCipherTests(cbc, null, [ 14 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit ........', 15 | formatBytesAsHexString(createUint8ListFromString( 16 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit ........')), 17 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme ...', 18 | formatBytesAsHexString(createUint8ListFromString( 19 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme ...')), 20 | ]); 21 | }); 22 | } 23 | -------------------------------------------------------------------------------- /test/asn1/asn1_all_test-disabled.dart: -------------------------------------------------------------------------------- 1 | /// 2 | /// Collection of ASN1 related tests. 3 | /// Invoker for <-->/all_tests_web.dart 4 | /// 5 | library; 6 | 7 | import 'asn1_object_test.dart' as object_test; 8 | import 'asn1_utils_test.dart' as utils_test; 9 | import 'primitives/asn1_bit_string_test.dart' as p_bitstring_test; 10 | import 'primitives/asn1_boolean_test.dart' as p_boolean_test; 11 | import 'primitives/asn1_enumerated_test.dart' as p_enumerated_test; 12 | import 'primitives/asn1_ia5_string_test.dart' as p_ia5string_test; 13 | import 'primitives/asn1_integer_test.dart' as p_integer_test; 14 | import 'primitives/asn1_null_test.dart' as p_null_test; 15 | import 'primitives/asn1_object_identifier_test.dart' as p_oid_test; 16 | import 'primitives/asn1_octet_string_test.dart' as p_octet_string_test; 17 | import 'primitives/asn1_printable_string_test.dart' as p_printable_string_test; 18 | import 'primitives/asn1_sequence_test.dart' as p_sequence_test; 19 | import 'primitives/asn1_set_test.dart' as p_set_test; 20 | import 'primitives/asn1_utc_time_test.dart' as p_utc_time_test; 21 | import 'primitives/asn1_utf8_string_test.dart' as p_utf8_string_test; 22 | 23 | void main() { 24 | object_test.main(); 25 | utils_test.main(); 26 | 27 | p_bitstring_test.main(); 28 | p_boolean_test.main(); 29 | p_enumerated_test.main(); 30 | p_ia5string_test.main(); 31 | p_integer_test.main(); 32 | p_null_test.main(); 33 | p_oid_test.main(); 34 | p_octet_string_test.main(); 35 | p_printable_string_test.main(); 36 | p_sequence_test.main(); 37 | p_set_test.main(); 38 | p_utc_time_test.main(); 39 | p_utf8_string_test.main(); 40 | } 41 | -------------------------------------------------------------------------------- /test/asn1/primitives/asn1_boolean_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:pointycastle/asn1/primitives/asn1_boolean.dart'; 4 | import 'package:test/test.dart'; 5 | 6 | void main() { 7 | test('Test named constructor fromBytes', () { 8 | var bytes = Uint8List.fromList([0x01, 0x01, 0xFF]); 9 | 10 | var valueBytes = Uint8List.fromList([0xFF]); 11 | 12 | var asn1Object = ASN1Boolean.fromBytes(bytes); 13 | expect(asn1Object.tag, 1); 14 | expect(asn1Object.isConstructed, false); 15 | expect(asn1Object.encodedBytes, bytes); 16 | expect(asn1Object.valueByteLength, 1); 17 | expect(asn1Object.valueStartPosition, 2); 18 | expect(asn1Object.valueBytes, valueBytes); 19 | }); 20 | 21 | test('Test encode', () { 22 | var asn1Boolean = ASN1Boolean(true); 23 | 24 | var bytes = Uint8List.fromList([0x01, 0x01, 0xFF]); 25 | 26 | expect(asn1Boolean.encode(), bytes); 27 | }); 28 | 29 | test('Test dump', () { 30 | var expected = '''BOOLEAN true'''; 31 | var bytes = Uint8List.fromList([0x01, 0x01, 0xFF]); 32 | 33 | var asn1Object = ASN1Boolean.fromBytes(bytes); 34 | expect(asn1Object.dump(), expected); 35 | }); 36 | } 37 | -------------------------------------------------------------------------------- /test/asn1/primitives/asn1_enumerated_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:pointycastle/asn1/primitives/asn1_enumerated.dart'; 4 | import 'package:test/test.dart'; 5 | 6 | void main() { 7 | test('Test named constructor fromBytes', () { 8 | var bytes = Uint8List.fromList([0x0a, 0x01, 0x02]); 9 | 10 | var valueBytes = Uint8List.fromList([0x02]); 11 | 12 | var asn1Object = ASN1Enumerated.fromBytes(bytes); 13 | expect(asn1Object.tag, 10); 14 | expect(asn1Object.isConstructed, false); 15 | expect(asn1Object.encodedBytes, bytes); 16 | expect(asn1Object.valueByteLength, 1); 17 | expect(asn1Object.valueStartPosition, 2); 18 | expect(asn1Object.valueBytes, valueBytes); 19 | expect(asn1Object.integer.toString(), '2'); 20 | }); 21 | 22 | test('Test encode', () { 23 | var utf8String = ASN1Enumerated(2); 24 | 25 | var bytes = Uint8List.fromList([0x0a, 0x01, 0x02]); 26 | 27 | expect(utf8String.encode(), bytes); 28 | }); 29 | 30 | test('Test dump', () { 31 | var expected = '''INTEGER 2'''; 32 | var bytes = Uint8List.fromList([0x0a, 0x01, 0x02]); 33 | 34 | var asn1Object = ASN1Enumerated.fromBytes(bytes); 35 | expect(asn1Object.dump(), expected); 36 | }); 37 | } 38 | -------------------------------------------------------------------------------- /test/asymmetric/pkcs1_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | import 'package:pointycastle/src/registry/registry.dart'; 5 | 6 | import '../test/runners/asymmetric_block_cipher.dart'; 7 | import '../test/src/null_asymmetric_block_cipher.dart'; 8 | import '../test/src/null_secure_random.dart'; 9 | 10 | void main() { 11 | ParametersWithRandom> pubpar() => 12 | ParametersWithRandom( 13 | PublicKeyParameter(NullPublicKey()), NullSecureRandom()); 14 | ParametersWithRandom> privpar() => 15 | ParametersWithRandom( 16 | PrivateKeyParameter(NullPrivateKey()), NullSecureRandom()); 17 | 18 | registry.register(NullAsymmetricBlockCipher.factoryConfig); 19 | registry.register(NullSecureRandom.factoryConfig); 20 | 21 | runAsymmetricBlockCipherTests( 22 | AsymmetricBlockCipher('Null/PKCS1'), pubpar, privpar, [ 23 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 24 | '020a010203040506070809004c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e2e2e', 25 | '01ffffffffffffffffffff004c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e2e2e', 26 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme', 27 | '02080102030405060700456e20756e206c75676172206465204c61204d616e6368612c206465206375796f206e6f6d627265206e6f2071756965726f2061636f726461726d65', 28 | '01ffffffffffffffff00456e20756e206c75676172206465204c61204d616e6368612c206465206375796f206e6f6d627265206e6f2071756965726f2061636f726461726d65', 29 | ]); 30 | } 31 | -------------------------------------------------------------------------------- /test/block/blowfish_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:pointycastle/api.dart'; 2 | import 'package:pointycastle/block/blowfish.dart'; 3 | import 'package:test/test.dart'; 4 | 5 | import '../test/src/helpers.dart'; 6 | 7 | void main() { 8 | group('Blowfish Engine', () { 9 | blockCipherTest(0, BlowfishEngine(), _kp('0000000000000000'), '0000000000000000', '4ef997456198dd78'); 10 | 11 | blockCipherTest(1, BlowfishEngine(), _kp('ffffffffffffffff'), 'ffffffffffffffff', '51866fd5b85ecb8a'); 12 | 13 | blockCipherTest(2, BlowfishEngine(), _kp('3000000000000000'), '1000000000000001', '7d856f9a613063f2'); 14 | 15 | blockCipherTest(3, BlowfishEngine(), _kp('1111111111111111'), '1111111111111111', '2466dd878b963c9d'); 16 | 17 | blockCipherTest(4, BlowfishEngine(), _kp('0123456789abcdef'), '1111111111111111', '61f9c3802281b096'); 18 | 19 | blockCipherTest(5, BlowfishEngine(), _kp('fedcba9876543210'), '0123456789abcdef', '0aceab0fc6a0a28d'); 20 | 21 | blockCipherTest(6, BlowfishEngine(), _kp('7ca110454a1a6e57'), '01a1d6d039776742', '59c68245eb05282b'); 22 | 23 | blockCipherTest(7, BlowfishEngine(), _kp('0131d9619dc1376e'), '5cd54ca83def57da', 'b1b8cc0b250f09a0'); 24 | }); 25 | } 26 | 27 | KeyParameter _kp(String key) { 28 | return KeyParameter(createUint8ListFromHexString(key)); 29 | } 30 | -------------------------------------------------------------------------------- /test/block/desede_engine_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:pointycastle/api.dart'; 2 | import 'package:pointycastle/block/desede_engine.dart'; 3 | import 'package:test/test.dart'; 4 | 5 | import '../test/src/helpers.dart'; 6 | 7 | void main() { 8 | group('DESede Engine', () { 9 | blockCipherTest( 10 | 0, 11 | DESedeEngine(), 12 | DESedeParameters( 13 | createUint8ListFromHexString('0123456789ABCDEF0123456789ABCDEF'), 14 | ), 15 | '4e6f77206973207468652074696d6520666f7220616c6c20', 16 | '3fa40e8a984d48156a271787ab8883f9893d51ec4b563b53'); 17 | blockCipherTest( 18 | 1, 19 | DESedeEngine(), 20 | DESedeParameters( 21 | createUint8ListFromHexString('0123456789abcdeffedcba9876543210'), 22 | ), 23 | '4e6f77206973207468652074696d6520666f7220616c6c20', 24 | 'd80a0d8b2bae5e4e6a0094171abcfc2775d2235a706e232c'); 25 | 26 | blockCipherTest( 27 | 2, 28 | DESedeEngine(), 29 | DESedeParameters( 30 | createUint8ListFromHexString( 31 | '0123456789abcdef0123456789abcdef0123456789abcdef'), 32 | ), 33 | '4e6f77206973207468652074696d6520666f7220616c6c20', 34 | '3fa40e8a984d48156a271787ab8883f9893d51ec4b563b53'); 35 | blockCipherTest( 36 | 3, 37 | DESedeEngine(), 38 | DESedeParameters( 39 | createUint8ListFromHexString( 40 | '0123456789abcdeffedcba98765432100123456789abcdef'), 41 | ), 42 | '4e6f77206973207468652074696d6520666f7220616c6c20', 43 | 'd80a0d8b2bae5e4e6a0094171abcfc2775d2235a706e232c'); 44 | }); 45 | } 46 | -------------------------------------------------------------------------------- /test/block/twofish_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:pointycastle/api.dart'; 2 | import 'package:pointycastle/block/modes/cbc.dart'; 3 | import 'package:pointycastle/block/twofish.dart'; 4 | import 'package:test/test.dart'; 5 | 6 | import '../test/src/helpers.dart'; 7 | 8 | void main() { 9 | group('Twofish Engine', () { 10 | final input = '000102030405060708090a0b0c0d0e0f'; 11 | 12 | blockCipherTest(0, TwofishEngine(), _kp('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'), input, 13 | '8ef0272c42db838bcf7b07af0ec30f38'); 14 | 15 | blockCipherTest(1, TwofishEngine(), _kp('000102030405060708090a0b0c0d0e0f1011121314151617'), input, 16 | '95accc625366547617f8be4373d10cd7'); 17 | 18 | blockCipherTest( 19 | 2, TwofishEngine(), _kp('000102030405060708090a0b0c0d0e0f'), input, '9fb63337151be9c71306d159ea7afaa4'); 20 | 21 | blockCipherTest( 22 | 3, 23 | CBCBlockCipher(TwofishEngine()), 24 | _kpWithIV('0123456789abcdef1234567890abcdef', '1234567890abcdef0123456789abcdef'), 25 | input, 26 | 'd6bfdbb2090562e960273783127e2658'); 27 | }); 28 | } 29 | 30 | KeyParameter _kp(String key) { 31 | return KeyParameter(createUint8ListFromHexString(key)); 32 | } 33 | 34 | ParametersWithIV _kpWithIV(String key, String iv) { 35 | return ParametersWithIV(_kp(key), createUint8ListFromHexString(iv)); 36 | } 37 | -------------------------------------------------------------------------------- /test/digests/md2_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | void main() { 8 | runDigestTests(Digest('MD2'), [ 9 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 10 | '70bdf19ce16c171706e9ef02219f35a8', 11 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 12 | '2b6aa7a2fe344c9bd4844c73c306a26a', 13 | ]); 14 | } 15 | -------------------------------------------------------------------------------- /test/digests/md4_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | void main() { 8 | runDigestTests(Digest('MD4'), [ 9 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 10 | '1d6839cb198b77f5d9a027a5ed1989d7', 11 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 12 | '95cdeefe499f74582d2894436cfbb989', 13 | ]); 14 | } 15 | -------------------------------------------------------------------------------- /test/digests/md5_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | void main() { 8 | runDigestTests(Digest('MD5'), [ 9 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 10 | 'b4dbd72756e62ad118c9759446956d15', 11 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 12 | 'dc4381c2a676fdcd92fad9ba4b97116d', 13 | ]); 14 | } 15 | -------------------------------------------------------------------------------- /test/digests/ripemd128_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | void main() { 8 | runDigestTests(Digest('RIPEMD-128'), [ 9 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 10 | '3e67e64143573d714263ed98b8d85c1d', 11 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 12 | '6a022533ba64455b63cdadbdc57dcc3d', 13 | ]); 14 | } 15 | -------------------------------------------------------------------------------- /test/digests/ripemd160_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | /// NOTE: abc and empty string test vectors were taken from 8 | /// [http://homes.esat.kuleuven.be/~bosselae/ripemd160.html]. 9 | void main() { 10 | runDigestTests(Digest('RIPEMD-160'), [ 11 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 12 | '7cc186f1d641709ec2bd363b10d3d66f122b365e', 13 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme ...', 14 | '48573da6caf89431a195e70f305f0df3b4f7ace6', 15 | 'abc', 16 | '8eb208f7e05d987a9b044a8e98c6b087f15a0bfc', 17 | '', 18 | '9c1185a5c5e9fc54612808977ee8f548b2258d31', 19 | ]); 20 | } 21 | -------------------------------------------------------------------------------- /test/digests/ripemd256_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | void main() { 8 | runDigestTests(Digest('RIPEMD-256'), [ 9 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 10 | '5bca9a62d8c446acea2716a6634bed99ae9c240ebadf584b277397028bbe74de', 11 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 12 | 'b12cc8c54ad8e14e9cbaa8bdd1d78139880fc824a2af19c67699d64fb4322cc2', 13 | ]); 14 | } 15 | -------------------------------------------------------------------------------- /test/digests/ripemd320_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | void main() { 8 | runDigestTests(Digest('RIPEMD-320'), [ 9 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 10 | '64a765d4c54e5a7fab2f09d833eea3aed68b327c949f3b9b167be59e049bb2b23bb3c1613308a25b', 11 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 12 | '45b72f4944bad47751ce6a80bfe68c7eb98e9e67edd91f3dad3f6dd470e04f61711766d3d24b9ebe', 13 | ]); 14 | } 15 | -------------------------------------------------------------------------------- /test/digests/sha1_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | void main() { 8 | runDigestTests(Digest('SHA-1'), [ 9 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 10 | '04e7635f310b9fbfa496ace02fa3ff9e7737f58c', 11 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 12 | 'cc8c8c2319221ae0b2a5dd5b26748a937c5855e4', 13 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 14 | 'b777fc3b3d773d11cdb187b7ec7db99ce802e1b6', 15 | ]); 16 | } 17 | -------------------------------------------------------------------------------- /test/digests/sha224_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | void main() { 8 | runDigestTests(Digest('SHA-224'), [ 9 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 10 | '10cffc69eddba6e8eafae57155284bd074778e0903e251ea9c8f9f62', 11 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 12 | 'f62bf1175f02176cfb00c370aea1c7203ba45a91cf776535380ab1a5', 13 | ]); 14 | } 15 | -------------------------------------------------------------------------------- /test/digests/sha256_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | void main() { 8 | runDigestTests(Digest('SHA-256'), [ 9 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 10 | '5bd6045a7697c48316411ff00be02595cf3d8596d99ba12482d18c90d61633cb', 11 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 12 | '2ab2e44465bec2b6bcfc8d13bfe07aa7e25e064685c60c2715d1831172376073', 13 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 14 | 'e43f7439c928c57b4d48263dcee29d046a53301af129d7b681227380ba01595b', 15 | ]); 16 | } 17 | -------------------------------------------------------------------------------- /test/digests/sha384_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | void main() { 8 | runDigestTests(Digest('SHA-384'), [ 9 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 10 | '3b6ae66bd9a8c2e447051836d5b74326037a9f0f875c904f6dec446aa3cd18b9ae4618cc63abc35a1d68a7acf45835a1', 11 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 12 | '198d957423fab1fc8489ba431629ff0d6350e8f8fccd68dd7fa02b344234491d99a43ec454521d19e304ad95c9507079', 13 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 14 | '052413522e7af6c106f26b1d725664ab4c5ea40e111dfe1a537429888a95978fc76f5f0e8996158e9fae81e2b876935e', 15 | ]); 16 | } 17 | -------------------------------------------------------------------------------- /test/digests/sha512_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | void main() { 8 | runDigestTests(Digest('SHA-512'), [ 9 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 10 | '7a61cb16b6c459d0894ba7ce01a50a43036da9f77e9a27c2e17d563c7eca877fa9e1d91968f5c61552a62f72deb07c5f6c00f8f43d0c3dccd46dfcc248b29b0e', 11 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 12 | 'f221fdceac5a63b712f303b444cf8aeacdc5a58835c340469772075430ddc43d983891458e543b0abd8c4acb71d69a808e292a86eaef1c1b1ddc83a567d8a346', 13 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 14 | '04e576a2c557a86d7ee178d4fe8adde77ab9c9b0ce8f3a5c51818f6e52b0a79fc79131ba7fda51a26c9ed6533a6954fc46ad31f90dce9c7c9671c47426296d7e', 15 | ]); 16 | } 17 | -------------------------------------------------------------------------------- /test/digests/sha512t_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | void main() { 8 | runDigestTests(Digest('SHA-512/224'), [ 9 | '', 10 | '6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4', 11 | 'abc', 12 | '4634270f707b6a54daae7530460842e20e37ed265ceee9a43e8924aa', 13 | 'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 14 | '23fec5bb94d60b23308192640b0c453335d664734fe40e7268674af9', 15 | ]); 16 | 17 | runDigestTests(Digest('SHA-512/256'), [ 18 | '', 19 | 'c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a', 20 | 'abc', 21 | '53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23', 22 | 'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 23 | '3928e184fb8690f840da3988121d31be65cb9d3ef83ee6146feac861e19b563a', 24 | ]); 25 | 26 | runDigestTests(Digest('SHA-512/488'), [ 27 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 28 | '77c5a401110133e531d1acf33ea6010d8d8149f9804310b6d32a69033aee079e88603166478069b1d4622030a508930a062199150f66462e26063266e5', 29 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 30 | '149a6a1e7f9741b56186b01c9195e1c5a003197ff559604653ea176c6d6e75c7cd117d3105cf10bc8d1f24e46c98c5a8b2fa2e53c16e95ada867b20ea1', 31 | ]); 32 | } 33 | -------------------------------------------------------------------------------- /test/digests/sm3_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | import 'package:test/test.dart'; 7 | 8 | import '../test/runners/digest.dart'; 9 | import '../test/src/helpers.dart'; 10 | 11 | void main() { 12 | runDigestTests(Digest('SM3'), [ 13 | // Example 1, From GB/T 32905-2016 14 | 'abc', 15 | '66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0', 16 | // Example 2, From GB/T 32905-2016 17 | 'abcd' * 16, 18 | 'debe9ff92275b8a138604889c18e5a4d6fdb70e5387e5765293dcba39c0c5732', 19 | ]); 20 | 21 | group('optional SM3 tests', () { 22 | test('64K Digest', () { 23 | var dig = Digest('SM3'); 24 | 25 | for (var i = 0; i < 65536; i++) { 26 | dig.updateByte(i); 27 | } 28 | 29 | var out = Uint8List(dig.digestSize); 30 | dig.doFinal(out, 0); 31 | 32 | expect( 33 | createUint8ListFromHexString( 34 | '97049bdc8f0736bc7300eafa9980aeb9cf00f24f7ec3a8f1f8884954d7655c1d'), 35 | equals(out)); 36 | }); 37 | 38 | test("10^6 'a' Test", () { 39 | var dig = Digest('SM3'); 40 | 41 | for (var i = 0; i < 1000000; i++) { 42 | dig.updateByte(97); 43 | } 44 | 45 | var out = Uint8List(dig.digestSize); 46 | dig.doFinal(out, 0); 47 | 48 | expect( 49 | createUint8ListFromHexString( 50 | 'c8aaf89429554029e231941a2acc0ad61ff2a5acd8fadd25847a3a732b3b02c3'), 51 | equals(out)); 52 | }); 53 | }); 54 | } 55 | -------------------------------------------------------------------------------- /test/digests/tiger_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | void main() { 8 | runDigestTests(Digest('Tiger'), [ 9 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 10 | 'c9a8c5f0ce21cd25d1158c7b9b9ef043437ef0e2bce65cca', 11 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 12 | '8edc9820300d6453f6784523bbf32d9e44ce20fbec7b07f8', 13 | ]); 14 | } 15 | -------------------------------------------------------------------------------- /test/digests/whirlpool_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/digest.dart'; 6 | 7 | void main() { 8 | runDigestTests(Digest('Whirlpool'), [ 9 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 10 | '3238fa7959052ebcd091894cb303743f910068300b3ee13391a15b3c1648ddc38b84df1864b90ff8e00d6b900b9aab503db1bff57c1e23e365665396db378db1', 11 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 12 | 'dda630ae2b2ab1a0b29f587ec612230749833b5954ca164b99d72634cbad854efffc2d3ae06f5edeba0297df46431eeab573059e108257b01f6fc1350e7e6665', 13 | ]); 14 | } 15 | -------------------------------------------------------------------------------- /test/ecc/curves_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/test.dart'; 2 | import 'package:pointycastle/export.dart'; 3 | 4 | void main() { 5 | group('ECCurve tests', () { 6 | test('ECCurve constructors', () { 7 | ECCurve_brainpoolp160r1(); 8 | ECCurve_brainpoolp160t1(); 9 | ECCurve_brainpoolp192r1(); 10 | ECCurve_brainpoolp192t1(); 11 | ECCurve_brainpoolp224r1(); 12 | ECCurve_brainpoolp224t1(); 13 | ECCurve_brainpoolp224t1(); 14 | ECCurve_brainpoolp224t1(); 15 | ECCurve_brainpoolp224t1(); 16 | ECCurve_brainpoolp224t1(); 17 | ECCurve_brainpoolp224t1(); 18 | ECCurve_brainpoolp224t1(); 19 | ECCurve_brainpoolp224t1(); 20 | ECCurve_brainpoolp224t1(); 21 | ECCurve_brainpoolp224t1(); 22 | 23 | ECCurve_gostr3410_2001_cryptopro_a(); 24 | ECCurve_gostr3410_2001_cryptopro_b(); 25 | ECCurve_gostr3410_2001_cryptopro_c(); 26 | ECCurve_gostr3410_2001_cryptopro_xcha(); 27 | ECCurve_gostr3410_2001_cryptopro_xchb(); 28 | 29 | ECCurve_prime192v1(); 30 | ECCurve_prime192v2(); 31 | ECCurve_prime192v3(); 32 | ECCurve_prime239v1(); 33 | ECCurve_prime239v2(); 34 | ECCurve_prime239v3(); 35 | ECCurve_prime256v1(); 36 | 37 | ECCurve_secp112r1(); 38 | ECCurve_secp112r2(); 39 | ECCurve_secp128r1(); 40 | ECCurve_secp128r2(); 41 | ECCurve_secp160k1(); 42 | ECCurve_secp160r1(); 43 | ECCurve_secp160r2(); 44 | ECCurve_secp192k1(); 45 | ECCurve_secp192r1(); 46 | ECCurve_secp224k1(); 47 | ECCurve_secp224r1(); 48 | ECCurve_secp256k1(); 49 | ECCurve_secp256r1(); 50 | ECCurve_secp384r1(); 51 | ECCurve_secp521r1(); 52 | }); 53 | }); 54 | } 55 | -------------------------------------------------------------------------------- /test/key_derivators/pbkdf2_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/key_derivators.dart'; 6 | import '../test/src/helpers.dart'; 7 | 8 | void main() { 9 | var salt = createUint8ListFromString('salt'); 10 | var pkcs = KeyDerivator('SHA-1/HMAC/PBKDF2'); 11 | var params = Pbkdf2Parameters(salt, 100, 16); 12 | 13 | runKeyDerivatorTests(pkcs, [ 14 | params, 15 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', 16 | '12aaf52b2fc239db41778c59d0e3c927', 17 | params, 18 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme...', 19 | '5b78b99ac2cc6b6626558f53c7490f4a', 20 | ]); 21 | } 22 | -------------------------------------------------------------------------------- /test/key_derivators/scrypt_nonvm_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | @OnPlatform({ 4 | 'vm': Skip(), 5 | }) 6 | library test.key_derivators.scrypt_test; 7 | 8 | import 'package:pointycastle/pointycastle.dart'; 9 | import 'package:test/test.dart'; 10 | 11 | import '../test/runners/key_derivators.dart'; 12 | import '../test/src/helpers.dart'; 13 | 14 | /// NOTE: the expected results for these tests are taken from the Java library found at 15 | /// [https://github.com/wg/scrypt]. See also 16 | /// [http://tools.ietf.org/html/draft-josefsson-scrypt-kdf-00#page-10] (which at the time of writing 17 | /// this test had typos because it interchanged N and r parameters). 18 | void main() { 19 | // 20 | // This is a sanity test for the js platform 21 | // 22 | 23 | var scrypt = KeyDerivator('scrypt'); 24 | runKeyDerivatorTests(scrypt, [ 25 | ScryptParameters(1024, 8, 16, 64, createUint8ListFromString('NaCl')), 26 | 'password', 27 | 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640' 28 | ]); 29 | } 30 | -------------------------------------------------------------------------------- /test/key_derivators/scrypt_vm_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | @OnPlatform({ 4 | 'chrome': Skip('Excessive time / resource consumption on this platform'), 5 | 'node': Skip('Excessive time / resource consumption on this platform') 6 | }) 7 | library test.key_derivators.scrypt_test; 8 | 9 | import 'package:pointycastle/pointycastle.dart'; 10 | import 'package:test/test.dart'; 11 | 12 | import '../test/runners/key_derivators.dart'; 13 | import '../test/src/helpers.dart'; 14 | 15 | /// NOTE: the expected results for these tests are taken from the Java library found at 16 | /// [https://github.com/wg/scrypt]. See also 17 | /// [http://tools.ietf.org/html/draft-josefsson-scrypt-kdf-00#page-10] (which at the time of writing 18 | /// this test had typos because it interchanged N and r parameters). 19 | void main() { 20 | group('scrypt - vm ', () { 21 | var scrypt = KeyDerivator('scrypt'); 22 | runKeyDerivatorTests(scrypt, [ 23 | ScryptParameters(1024, 8, 16, 64, createUint8ListFromString('NaCl')), 24 | 'password', 25 | 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640', 26 | ScryptParameters( 27 | 16384, 8, 1, 64, createUint8ListFromString('SodiumChloride')), 28 | 'pleaseletmein', 29 | '7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887', 30 | ScryptParameters( 31 | 1048576, 8, 1, 64, createUint8ListFromString('SodiumChloride')), 32 | 'pleaseletmein', 33 | '2101cb9b6a511aaeaddbbe09cf70f881ec568d574a2ffd4dabe5ee9820adaa478e56fd8f4ba5d09ffa1c6d927c40f4c337304049e8a952fbcbf45c6fa77a41a4', 34 | ]); 35 | }); 36 | } 37 | -------------------------------------------------------------------------------- /test/key_generators/ec_key_generator_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | import '../test/runners/key_generators.dart'; 5 | import '../test/src/null_secure_random.dart'; 6 | 7 | void main() { 8 | var rnd = NullSecureRandom(); 9 | 10 | var domainParams = ECDomainParameters('prime192v1'); 11 | var ecParams = ECKeyGeneratorParameters(domainParams); 12 | var params = ParametersWithRandom(ecParams, rnd); 13 | 14 | var keyGenerator = KeyGenerator('EC'); 15 | keyGenerator.init(params); 16 | 17 | runKeyGeneratorTests(keyGenerator, [ 18 | _keyPair( 19 | domainParams, 20 | '4165461920577864743570110591887661239883413257826890841803', 21 | '433060747015770533144900903117711353276551186421527917903', 22 | '96533667595335344311200144916688449305687896108635671'), 23 | _keyPair( 24 | domainParams, 25 | '952128485350936803657958938747669190775028076767588715981', 26 | '2074616205026821401743282701487442392635099812302414322181', 27 | '590882579351047642528856087035049998200115612080958942767'), 28 | _keyPair( 29 | domainParams, 30 | '24186169899158470982826728287136856913767539338281496876', 31 | '2847521372076459404463997303980674024509607281070145578802', 32 | '1181668625034499949713400973925183307950925536265809249863'), 33 | ]); 34 | } 35 | 36 | AsymmetricKeyPair _keyPair( 37 | ECDomainParameters domainParams, String qX, String qY, String d) => 38 | AsymmetricKeyPair( 39 | ECPublicKey( 40 | domainParams.curve.createPoint(BigInt.parse(qX), BigInt.parse(qY)), 41 | domainParams), 42 | ECPrivateKey(BigInt.parse(d), domainParams)); 43 | -------------------------------------------------------------------------------- /test/macs/cbc_block_cipher_mac_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/mac.dart'; 6 | import '../test/src/helpers.dart'; 7 | 8 | void main() { 9 | final mac = Mac('AES/CBC_CMAC/PKCS7'); 10 | 11 | // Test vectors from BouncyCastle CBCBlockCipherMac (was DES/CBC_CMAC/PKCS7). 12 | // Note: Key and expected outputs adapted from DES engine to AES 13 | final key = createUint8ListFromHexString('0123456789abcdef0123456789abcdef'); 14 | final keyParam = KeyParameter(key); 15 | 16 | final input1 = createUint8ListFromHexString( 17 | '37363534333231204e6f77206973207468652074696d6520666f7220'); 18 | final input2 = createUint8ListFromHexString('3736353433323120'); 19 | 20 | final output5WithAes = '0376f977de2166d1'; 21 | final output6WithAes = 'f338ed02ba54413f'; 22 | 23 | mac.init(keyParam); 24 | 25 | runMacTests(mac, [ 26 | PlainTextDigestPair(input2, output5WithAes), 27 | PlainTextDigestPair(input1, output6WithAes), 28 | // same input again: 29 | PlainTextDigestPair(input1, output6WithAes) 30 | ]); 31 | } 32 | -------------------------------------------------------------------------------- /test/macs/poly1305_web_test.dart: -------------------------------------------------------------------------------- 1 | @TestOn('js') 2 | // See file LICENSE for more information. 3 | 4 | library test.macs.poly1305_test; 5 | 6 | import 'package:pointycastle/export.dart'; 7 | import 'package:pointycastle/src/platform_check/platform_check.dart'; 8 | import 'package:test/test.dart'; 9 | 10 | void main() { 11 | group('Poly1305 - js', () { 12 | test('must emit PlatformException', () { 13 | expect(() { 14 | Poly1305.withCipher(AESEngine()); 15 | }, throwsA(TypeMatcher())); 16 | 17 | expect(() { 18 | Poly1305(); 19 | }, throwsA(TypeMatcher())); 20 | }); 21 | }); 22 | } 23 | -------------------------------------------------------------------------------- /test/modes/cbc_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | import 'package:pointycastle/src/registry/registry.dart'; 7 | 8 | import '../test/runners/block_cipher.dart'; 9 | import '../test/src/null_block_cipher.dart'; 10 | 11 | void main() { 12 | final iv = Uint8List.fromList([ 13 | 0x00, 14 | 0x11, 15 | 0x22, 16 | 0x33, 17 | 0x44, 18 | 0x55, 19 | 0x66, 20 | 0x77, 21 | 0x88, 22 | 0x99, 23 | 0xAA, 24 | 0xBB, 25 | 0xCC, 26 | 0xDD, 27 | 0xEE, 28 | 0xFF 29 | ]); 30 | final params = ParametersWithIV(null, iv); 31 | 32 | registry.register(NullBlockCipher.factoryConfig); 33 | 34 | runBlockCipherTests(BlockCipher('Null/CBC'), params, [ 35 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit ........', 36 | '4c7e505629750f07fbecc79ba8b282903e5e233f5d556e6a9e98ebbbcbddece35b3d575a29201c4afffc82cba2ae8f8a355a773f4549686ad1d2ace58c80a1a4', 37 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme ...', 38 | '457f02462a750a02eff8d89ba8b8ceb3245f4f2744166263c3d8bcfe88dbbbca4b7f214829741006e3b6d3def9aed2af391001294a1b626282c4bebbd980fc81', 39 | ]); 40 | } 41 | -------------------------------------------------------------------------------- /test/modes/cfb_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | import 'package:pointycastle/src/registry/registry.dart'; 7 | 8 | import '../test/runners/block_cipher.dart'; 9 | import '../test/src/null_block_cipher.dart'; 10 | 11 | void main() { 12 | final iv = Uint8List.fromList([ 13 | 0x00, 14 | 0x11, 15 | 0x22, 16 | 0x33, 17 | 0x44, 18 | 0x55, 19 | 0x66, 20 | 0x77, 21 | 0x88, 22 | 0x99, 23 | 0xAA, 24 | 0xBB, 25 | 0xCC, 26 | 0xDD, 27 | 0xEE, 28 | 0xFF 29 | ]); 30 | final params = ParametersWithIV(null, iv); 31 | 32 | registry.register(NullBlockCipher.factoryConfig); 33 | 34 | runBlockCipherTests(BlockCipher('Null/CFB-128'), params, [ 35 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit ........', 36 | '4c7e505629750f07fbecc79ba8b282903e5e233f5d556e6a9e98ebbbcbddece35b3d575a29201c4afffc82cba2ae8f8a355a773f4549686ad1d2ace58c80a1a4', 37 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme ...', 38 | '457f02462a750a02eff8d89ba8b8ceb3245f4f2744166263c3d8bcfe88dbbbca4b7f214829741006e3b6d3def9aed2af391001294a1b626282c4bebbd980fc81', 39 | ]); 40 | } 41 | -------------------------------------------------------------------------------- /test/modes/ecb_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | import 'package:pointycastle/src/registry/registry.dart'; 7 | 8 | import '../test/runners/block_cipher.dart'; 9 | import '../test/src/null_block_cipher.dart'; 10 | 11 | void main() { 12 | final iv = Uint8List.fromList([ 13 | 0x00, 14 | 0x11, 15 | 0x22, 16 | 0x33, 17 | 0x44, 18 | 0x55, 19 | 0x66, 20 | 0x77, 21 | 0x88, 22 | 0x99, 23 | 0xAA, 24 | 0xBB, 25 | 0xCC, 26 | 0xDD, 27 | 0xEE, 28 | 0xFF 29 | ]); 30 | final params = ParametersWithIV(null, iv); 31 | 32 | registry.register(NullBlockCipher.factoryConfig); 33 | 34 | runBlockCipherTests(BlockCipher('Null/ECB'), params, [ 35 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit ........', 36 | '4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c6974202e2e2e2e2e2e2e2e', 37 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme ...', 38 | '456e20756e206c75676172206465204c61204d616e6368612c206465206375796f206e6f6d627265206e6f2071756965726f2061636f726461726d65202e2e2e', 39 | ]); 40 | } 41 | -------------------------------------------------------------------------------- /test/modes/gctr_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | import 'package:pointycastle/src/registry/registry.dart'; 7 | 8 | import '../test/runners/block_cipher.dart'; 9 | import '../test/src/null_block_cipher.dart'; 10 | 11 | void main() { 12 | final iv = Uint8List.fromList([ 13 | 0x00, 14 | 0x11, 15 | 0x22, 16 | 0x33, 17 | 0x44, 18 | 0x55, 19 | 0x66, 20 | 0x77, 21 | 0x88, 22 | 0x99, 23 | 0xAA, 24 | 0xBB, 25 | 0xCC, 26 | 0xDD, 27 | 0xEE, 28 | 0xFF 29 | ]); 30 | final params = ParametersWithIV(null, iv); 31 | 32 | registry.register(NullBlockCipher.factoryConfig); 33 | 34 | runBlockCipherTests(BlockCipher('Null-8/GCTR'), params, [ 35 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit ........', 36 | '4d7d515125760e0871664915283804167134565f2478081761610a17373604086075535d2c2f195c6773414935280f14697f095f0c35195e263704154a734051', 37 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme ...', 38 | '447c034126760b0d6572561528324835623468573e3b011b28354252743a1f026a36495735381919267947192d2e05187577095b03331f1a696b475e44734051', 39 | ]); 40 | } 41 | -------------------------------------------------------------------------------- /test/modes/ige_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/block_cipher.dart'; 6 | import '../test/src/helpers.dart'; 7 | 8 | void main() { 9 | final key1 = createUint8ListFromHexString( 10 | '000102030405060708090A0B0C0D0E0F'.toLowerCase()); 11 | final iv1 = createUint8ListFromHexString( 12 | '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F' 13 | .toLowerCase()); 14 | final params1 = ParametersWithIV(KeyParameter(key1), iv1); 15 | 16 | final data1 = String.fromCharCodes(createUint8ListFromHexString( 17 | '0000000000000000000000000000000000000000000000000000000000000000')); 18 | final ct1 = '1A8519A6557BE652E9DA8E43DA4EF4453CF456B4CA488AA383C79C98B34797CB' 19 | .toLowerCase(); 20 | 21 | runBlockCipherTests(BlockCipher('AES/IGE'), params1, [data1, ct1]); 22 | 23 | final key2 = createUint8ListFromHexString( 24 | '5468697320697320616E20696D706C65'.toLowerCase()); 25 | final iv2 = createUint8ListFromHexString( 26 | '6D656E746174696F6E206F6620494745206D6F646520666F72204F70656E5353' 27 | .toLowerCase()); 28 | final params2 = ParametersWithIV(KeyParameter(key2), iv2); 29 | 30 | final data2 = String.fromCharCodes(createUint8ListFromHexString( 31 | '99706487A1CDE613BC6DE0B6F24B1C7AA448C8B9C3403E3467A8CAD89340F53B')); 32 | final ct2 = '4C2E204C6574277320686F70652042656E20676F74206974207269676874210A' 33 | .toLowerCase(); 34 | 35 | runBlockCipherTests(BlockCipher('AES/IGE'), params2, [data2, ct2]); 36 | } 37 | -------------------------------------------------------------------------------- /test/modes/ofb_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | import 'package:pointycastle/src/registry/registry.dart'; 7 | 8 | import '../test/runners/block_cipher.dart'; 9 | import '../test/src/null_block_cipher.dart'; 10 | 11 | void main() { 12 | final iv = Uint8List.fromList([ 13 | 0x00, 14 | 0x11, 15 | 0x22, 16 | 0x33, 17 | 0x44, 18 | 0x55, 19 | 0x66, 20 | 0x77, 21 | 0x88, 22 | 0x99, 23 | 0xAA, 24 | 0xBB, 25 | 0xCC, 26 | 0xDD, 27 | 0xEE, 28 | 0xFF 29 | ]); 30 | final params = ParametersWithIV(null, iv); 31 | 32 | registry.register(NullBlockCipher.factoryConfig); 33 | 34 | runBlockCipherTests(BlockCipher('Null/OFB-128'), params, [ 35 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit ........', 36 | '4c7e505629750f07fbecc79ba8b282907231515a3075071aeded869bafb2808c6572565630201457e9fdc3cba5ae8d966e760256283c1257a6b78495e2f3c0d1', 37 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme ...', 38 | '457f02462a750a02eff8d89ba8b8ceb361316f522a360e16a4b9cedeecbe9b866f314c5c29371412a8f7c59bbda8879a727e0252273a1413e9ebc7deecf3c0d1', 39 | ]); 40 | } 41 | -------------------------------------------------------------------------------- /test/paddings/iso7816d4_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import '../test/runners/padding.dart'; 6 | import '../test/src/helpers.dart'; 7 | 8 | void main() { 9 | runPaddingTest(Padding('ISO7816-4'), null, 10 | createUint8ListFromHexString('ffffff'), 8, 'ffffff8000000000'); 11 | runPaddingTest(Padding('ISO7816-4'), null, 12 | createUint8ListFromHexString('00000000'), 8, '0000000080000000'); 13 | } 14 | -------------------------------------------------------------------------------- /test/paddings/pkcs7_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data' show Uint8List; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | 7 | import '../test/runners/padding.dart'; 8 | import '../test/src/helpers.dart'; 9 | 10 | void main() { 11 | runPaddingTest(Padding('PKCS7'), null, createUint8ListFromString('123456789'), 12 | 16, '31323334353637383907070707070707'); 13 | runPaddingTest(Padding('PKCS7'), null, Uint8List.fromList([]), 16, 14 | '10101010101010101010101010101010'); 15 | } 16 | -------------------------------------------------------------------------------- /test/platform/platform_native_test.dart: -------------------------------------------------------------------------------- 1 | @TestOn('vm') 2 | import 'package:pointycastle/src/platform_check/platform_check.dart'; 3 | import 'package:test/test.dart'; 4 | 5 | void main() { 6 | test('is native', () { 7 | expect(Platform.instance.platform, isNot(equals('web'))); 8 | expect(Platform.instance.isNative, equals(true)); 9 | expect(Platform.instance.fullWidthInteger, equals(true)); 10 | }); 11 | 12 | test('width assertion', () { 13 | expect(() => {Platform.instance.assertFullWidthInteger()}, returnsNormally); 14 | }); 15 | } 16 | -------------------------------------------------------------------------------- /test/platform/platform_web_test.dart: -------------------------------------------------------------------------------- 1 | @TestOn('browser') 2 | import 'package:pointycastle/src/platform_check/platform_check.dart'; 3 | import 'package:test/test.dart'; 4 | 5 | void main() { 6 | test('is not native', () { 7 | expect(Platform.instance.platform, equals('web')); 8 | expect(Platform.instance.isNative, equals(false)); 9 | expect(Platform.instance.fullWidthInteger, equals(false)); 10 | }); 11 | 12 | test('width assertion', () { 13 | expect(() => {Platform.instance.assertFullWidthInteger()}, 14 | throwsA(TypeMatcher())); 15 | }); 16 | } 17 | -------------------------------------------------------------------------------- /test/random/auto_seed_block_ctr_random_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | 7 | import 'package:test/test.dart'; 8 | 9 | void main() { 10 | group('AutoSeedBlockCtrRandom:', () { 11 | final rnd = SecureRandom('AES/CTR/AUTO-SEED-PRNG'); 12 | 13 | test(rnd.algorithmName, () { 14 | final key = Uint8List(16); 15 | final keyParam = KeyParameter(key); 16 | final params = ParametersWithIV(keyParam, Uint8List(16)); 17 | 18 | rnd.seed(params); 19 | 20 | final firstExpected = [ 21 | 102, 22 | 233, 23 | 75, 24 | 212, 25 | 239, 26 | 138, 27 | 44, 28 | 59, 29 | 136, 30 | 76, 31 | 250, 32 | 89, 33 | 202, 34 | 52, 35 | 43, 36 | 46, 37 | 88 38 | ]; 39 | var firstBytes = rnd.nextBytes(17); 40 | expect(firstBytes, firstExpected); 41 | 42 | final lastExpected = [ 43 | 156, 44 | 238, 45 | 41, 46 | 193, 47 | 135, 48 | 66, 49 | 23, 50 | 87, 51 | 208, 52 | 14, 53 | 88, 54 | 227, 55 | 93, 56 | 31, 57 | 171, 58 | 110, 59 | 221 60 | ]; 61 | var lastBytes = rnd.nextBytes(17); 62 | expect(lastBytes, lastExpected); 63 | }); 64 | }); 65 | } 66 | -------------------------------------------------------------------------------- /test/random/fixed_rng_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:pointycastle/api.dart'; 4 | import 'package:test/test.dart'; 5 | 6 | import '../test/src/fixed_secure_random.dart'; 7 | 8 | void main() { 9 | group('FixedSecureRandom:', () { 10 | test('No seed', () { 11 | final rng = FixedSecureRandom(); 12 | try { 13 | rng.nextUint8(); 14 | fail('expected StateError from uninitialized FixedSecureRandom'); 15 | } on StateError catch (e) { 16 | expect(e.message, 'fixed secure random has no values'); 17 | } 18 | }); 19 | 20 | test('Seed Exhaustion', () { 21 | final rng = FixedSecureRandom(); 22 | rng.seed(KeyParameter(Uint8List.fromList([1, 2]))); 23 | try { 24 | expect(rng.nextUint8(), 1); 25 | expect(rng.nextUint8(), 2); 26 | rng.nextUint8(); 27 | fail('expected StateError from running out of entropy'); 28 | } on StateError catch (e) { 29 | expect(e.message, 'fixed secure random unexpectedly exhausted'); 30 | } 31 | }); 32 | }); 33 | } 34 | -------------------------------------------------------------------------------- /test/random/fortuna_random_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | 7 | import 'package:test/test.dart'; 8 | 9 | void main() { 10 | group('Fortuna:', () { 11 | final rnd = SecureRandom('Fortuna'); 12 | 13 | test(rnd.algorithmName, () { 14 | final key = Uint8List(32); 15 | final keyParam = KeyParameter(key); 16 | 17 | rnd.seed(keyParam); 18 | 19 | final firstExpected = [ 20 | 83, 21 | 15, 22 | 138, 23 | 251, 24 | 199, 25 | 69, 26 | 54, 27 | 185, 28 | 169, 29 | 99, 30 | 180, 31 | 241, 32 | 196, 33 | 203, 34 | 115, 35 | 139, 36 | 206 37 | ]; 38 | var firstBytes = rnd.nextBytes(17); 39 | expect(firstBytes, firstExpected); 40 | 41 | final lastExpected = [ 42 | 227, 43 | 7, 44 | 53, 45 | 32, 46 | 144, 47 | 169, 48 | 73, 49 | 217, 50 | 239, 51 | 226, 52 | 233, 53 | 123, 54 | 220, 55 | 80, 56 | 210, 57 | 0, 58 | 229 59 | ]; 60 | var lastBytes = rnd.nextBytes(17); 61 | expect(lastBytes, lastExpected); 62 | }); 63 | }); 64 | } 65 | -------------------------------------------------------------------------------- /test/src/ct_nonvm_test.dart: -------------------------------------------------------------------------------- 1 | @OnPlatform({ 2 | 'vm': Skip(), 3 | }) 4 | import 'dart:math'; 5 | import 'dart:typed_data'; 6 | 7 | import 'package:pointycastle/src/ct.dart'; 8 | import 'package:test/test.dart'; 9 | 10 | import '../digests/cshake_test.dart'; 11 | 12 | void main() { 13 | // 14 | // Not using a secure random otherwise so as not to 15 | // invoke the platform selection logic. 16 | // 17 | var rand = Random(); 18 | 19 | group('ct', () { 20 | test('xor monte', () { 21 | for (var j = 0; j < 1000; j++) { 22 | var len = rand.nextInt(256); 23 | var x = Uint8List.fromList( 24 | List.generate(len, (index) => rand.nextInt(256))); 25 | var y = Uint8List.fromList( 26 | List.generate(len, (index) => rand.nextInt(256))); 27 | var enable = rand.nextInt(10) >= 5; 28 | 29 | var reason = 30 | '$enable ${formatBytesAsHexString(x)} ${formatBytesAsHexString(y)}'; 31 | 32 | var xExpected = Uint8List.fromList(x); 33 | _xor(xExpected, y, enable); 34 | 35 | CT_xor(x, y, enable); 36 | expect(xExpected, equals(x), reason: reason); 37 | 38 | // 39 | // Should be all zero 40 | // 41 | CT_xor(y, y, true); 42 | for (var element in y) { 43 | expect(element, equals(0)); 44 | } 45 | } 46 | }); 47 | 48 | test('assertion', () { 49 | var x = Uint8List(1); 50 | var y = Uint8List(2); 51 | expect(() { 52 | CT_xor(x, y, true); 53 | }, throwsA(isA())); 54 | }); 55 | }); 56 | } 57 | 58 | // naive non ct xor 59 | void _xor(Uint8List x, Uint8List y, bool enable) { 60 | if (enable) { 61 | for (var t = 0; t < x.length; t++) { 62 | x[t] = x[t] ^ y[t]; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /test/stream/rc4_engine_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:pointycastle/export.dart'; 2 | 3 | import 'package:test/test.dart'; 4 | 5 | import '../test/src/helpers.dart'; 6 | 7 | void main() { 8 | group('RC4 Engine', () { 9 | streamCipherTest( 10 | 0, 11 | RC4Engine(), 12 | KeyParameter( 13 | createUint8ListFromHexString('0123456789ABCDEF'), 14 | ), 15 | '4e6f772069732074', 16 | '3afbb5c77938280d'); 17 | streamCipherTest( 18 | 1, 19 | RC4Engine(), 20 | KeyParameter( 21 | createUint8ListFromHexString('0123456789ABCDEF'), 22 | ), 23 | '68652074696d6520', 24 | '1cf1e29379266d59'); 25 | streamCipherTest( 26 | 3, 27 | RC4Engine(), 28 | KeyParameter( 29 | createUint8ListFromHexString('0123456789ABCDEF'), 30 | ), 31 | '666f7220616c6c20', 32 | '12fbb0c771276459'); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /test/stream/salsa20_test.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/pointycastle.dart'; 6 | 7 | import '../test/runners/stream_cipher.dart'; 8 | 9 | void main() { 10 | final keyBytes = Uint8List.fromList([ 11 | 0x00, 12 | 0x11, 13 | 0x22, 14 | 0x33, 15 | 0x44, 16 | 0x55, 17 | 0x66, 18 | 0x77, 19 | 0x88, 20 | 0x99, 21 | 0xAA, 22 | 0xBB, 23 | 0xCC, 24 | 0xDD, 25 | 0xEE, 26 | 0xFF 27 | ]); 28 | final key = KeyParameter(keyBytes); 29 | final iv = 30 | Uint8List.fromList([0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77]); 31 | final params = ParametersWithIV(key, iv); 32 | 33 | runStreamCipherTests(StreamCipher('Salsa20'), params, [ 34 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit ........', 35 | '9d8d611ee047b47fc5e2bd5db4284463008aa89c174093d3ce4b3e8cc2594acfe9a62a84388fe060f75247d425c2fe0cd283cfce887f5c6b5dfea86d927efb36', 36 | 'En un lugar de La Mancha, de cuyo nombre no quiero acordarme ...', 37 | '948c330ee347b17ad1f6a25db4220840138a96940d039adf871f76c9815551c5e3e5308e2198e025b65841843dc4f400ce8bcfca87795a2f12a2eb269c7efb36', 38 | ]); 39 | } 40 | -------------------------------------------------------------------------------- /test/test/runners/digest.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:test/test.dart'; 6 | import 'package:pointycastle/pointycastle.dart'; 7 | 8 | import '../src/helpers.dart'; 9 | 10 | void runDigestTests(Digest digest, List plainDigestTextPairs) { 11 | group('${digest.algorithmName}:', () { 12 | group('digest:', () { 13 | for (var i = 0; i < plainDigestTextPairs.length; i += 2) { 14 | var plainText = plainDigestTextPairs[i]; 15 | var digestText = plainDigestTextPairs[i + 1]; 16 | 17 | test(formatAsTruncated(plainText), 18 | () => _runDigestTest(digest, plainText, digestText)); 19 | } 20 | }); 21 | }); 22 | } 23 | 24 | void _runDigestTest( 25 | Digest digest, String plainTextString, String expectedHexDigestText) { 26 | digest.reset(); 27 | 28 | var plainText = createUint8ListFromString(plainTextString); 29 | var out = digest.process(plainText); 30 | var hexOut = formatBytesAsHexString(out); 31 | 32 | expect(hexOut, equals(expectedHexDigestText)); 33 | 34 | for (var i = 0; i < plainText.length; ++i) { 35 | digest.updateByte(plainText[i]); 36 | } 37 | out = Uint8List(digest.digestSize); 38 | 39 | digest.doFinal(out, 0); 40 | hexOut = formatBytesAsHexString(out); 41 | 42 | expect(hexOut, equals(expectedHexDigestText)); 43 | } 44 | -------------------------------------------------------------------------------- /test/test/runners/key_derivators.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:test/test.dart'; 4 | import 'package:pointycastle/pointycastle.dart'; 5 | 6 | import '../src/helpers.dart'; 7 | 8 | void runKeyDerivatorTests( 9 | KeyDerivator keyDerivator, List paramsPasswordKeyTuples) { 10 | group('${keyDerivator.algorithmName}:', () { 11 | group('deriveKey:', () { 12 | for (var i = 0; i < paramsPasswordKeyTuples.length; i += 3) { 13 | var params = paramsPasswordKeyTuples[i]; 14 | var password = paramsPasswordKeyTuples[i + 1]; 15 | var key = paramsPasswordKeyTuples[i + 2]; 16 | 17 | test( 18 | formatAsTruncated(password as String), 19 | () => _runKeyDerivatorTest(keyDerivator, params as CipherParameters, 20 | password, key as String)); 21 | } 22 | }); 23 | }); 24 | } 25 | 26 | void _runKeyDerivatorTest(KeyDerivator keyDerivator, CipherParameters params, 27 | String password, String expectedHexKey) { 28 | keyDerivator.init(params); 29 | 30 | var passwordBytes = createUint8ListFromString(password); 31 | var out = keyDerivator.process(passwordBytes); 32 | var hexOut = formatBytesAsHexString(out); 33 | 34 | expect(hexOut, equals(expectedHexKey)); 35 | } 36 | -------------------------------------------------------------------------------- /test/test/runners/key_generators.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:test/test.dart'; 4 | import 'package:pointycastle/pointycastle.dart'; 5 | 6 | void runKeyGeneratorTests( 7 | KeyGenerator keyGenerator, List expectedKeyPairs) { 8 | group('${keyGenerator.algorithmName}:', () { 9 | group('generateKeyPair:', () { 10 | for (var i = 0; i < expectedKeyPairs.length; i++) { 11 | test('$i', 12 | () => _runKeyGeneratorTest(keyGenerator, expectedKeyPairs[i])); 13 | } 14 | }); 15 | }); 16 | } 17 | 18 | void _runKeyGeneratorTest( 19 | KeyGenerator keyGenerator, AsymmetricKeyPair expectedKeyPair) { 20 | var keyPair = keyGenerator.generateKeyPair(); 21 | 22 | expect(keyPair.privateKey, equals(expectedKeyPair.privateKey)); 23 | expect(keyPair.publicKey, equals(expectedKeyPair.publicKey)); 24 | } 25 | -------------------------------------------------------------------------------- /test/test/runners/padding.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data' show Uint8List; 4 | 5 | import 'package:test/test.dart'; 6 | import 'package:pointycastle/pointycastle.dart'; 7 | 8 | import '../src/helpers.dart'; 9 | 10 | void runPaddingTest(Padding pad, CipherParameters? params, Uint8List unpadData, 11 | int padLength, String padData) { 12 | group('${pad.algorithmName}:', () { 13 | test('addPadding: ${unpadData.toString()}', () { 14 | var expectedBytes = createUint8ListFromHexString(padData); 15 | var dataBytes = Uint8List(padLength)..setAll(0, unpadData); 16 | 17 | pad.init(params); 18 | var ret = pad.addPadding(dataBytes, unpadData.length); 19 | 20 | expect(ret, equals(padLength - unpadData.length)); 21 | expect(dataBytes, equals(expectedBytes)); 22 | }); 23 | 24 | test('padCount: $padData', () { 25 | var dataBytes = createUint8ListFromHexString(padData); 26 | 27 | pad.init(params); 28 | var ret = pad.padCount(dataBytes); 29 | 30 | expect(ret, equals(padLength - unpadData.length)); 31 | }); 32 | }); 33 | } 34 | -------------------------------------------------------------------------------- /test/test/src/null_asymmetric_block_cipher.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | import 'package:pointycastle/src/registry/registry.dart'; 7 | import 'package:pointycastle/src/impl/base_asymmetric_block_cipher.dart'; 8 | 9 | /// An implementation of a null [AsymmetricBlockCipher], that is, a cipher that does not encrypt, neither decrypt. It can be used 10 | /// for testing or benchmarking chaining algorithms. 11 | class NullAsymmetricBlockCipher extends BaseAsymmetricBlockCipher { 12 | /// Intended for internal use. 13 | static final FactoryConfig factoryConfig = DynamicFactoryConfig.regex( 14 | AsymmetricBlockCipher, 15 | r'^Null$', 16 | (s, m) => () { 17 | return NullAsymmetricBlockCipher(70, 70); 18 | }, 19 | ); 20 | 21 | @override 22 | final int inputBlockSize; 23 | @override 24 | final int outputBlockSize; 25 | 26 | NullAsymmetricBlockCipher(this.inputBlockSize, this.outputBlockSize); 27 | 28 | @override 29 | String get algorithmName => 'Null'; 30 | 31 | @override 32 | void reset() {} 33 | 34 | @override 35 | void init(bool forEncryption, CipherParameters params) {} 36 | 37 | @override 38 | int processBlock( 39 | Uint8List? inp, int inpOff, int len, Uint8List out, int outOff) { 40 | out.setRange(outOff, outOff + len, inp!.sublist(inpOff)); 41 | return len; 42 | } 43 | } 44 | 45 | class NullAsymmetricKey implements AsymmetricKey {} 46 | 47 | class NullPublicKey extends NullAsymmetricKey implements PublicKey {} 48 | 49 | class NullPrivateKey extends NullAsymmetricKey implements PrivateKey {} 50 | -------------------------------------------------------------------------------- /test/test/src/null_block_cipher.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | import 'package:pointycastle/src/impl/base_block_cipher.dart'; 7 | import 'package:pointycastle/src/registry/registry.dart'; 8 | 9 | /// An implementation of a null [BlockCipher], that is, a cipher that does not encrypt, neither decrypt. It can be used for 10 | /// testing or benchmarking chaining algorithms. 11 | class NullBlockCipher extends BaseBlockCipher { 12 | static final FactoryConfig factoryConfig = DynamicFactoryConfig.regex( 13 | BlockCipher, r'^Null(?:-([0-9]+))?$', (_, Match match) { 14 | final blockSize = match.group(1) == null ? 16 : int.parse(match.group(1)!); 15 | return () => NullBlockCipher(blockSize); 16 | }); 17 | 18 | @override 19 | final int blockSize; 20 | 21 | NullBlockCipher([this.blockSize = 16]); 22 | 23 | @override 24 | String get algorithmName => 'Null'; 25 | 26 | @override 27 | void reset() {} 28 | 29 | @override 30 | void init(bool forEncryption, CipherParameters? params) {} 31 | 32 | @override 33 | int processBlock(Uint8List? inp, int inpOff, Uint8List? out, int outOff) { 34 | out!.setRange(outOff, outOff + blockSize, inp!.sublist(inpOff)); 35 | return blockSize; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/test/src/null_digest.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | import 'package:pointycastle/src/impl/base_digest.dart'; 7 | import 'package:pointycastle/src/registry/registry.dart'; 8 | 9 | /// An implementation of a null [Digest], that is, a digest that returns an empty string. It can be 10 | /// used for testing or benchmarking chaining algorithms. 11 | class NullDigest extends BaseDigest { 12 | static final FactoryConfig factoryConfig = 13 | StaticFactoryConfig(Digest, 'Null', () => NullDigest()); 14 | 15 | @override 16 | final int digestSize; 17 | 18 | NullDigest([this.digestSize = 32]); 19 | @override 20 | final String algorithmName = 'Null'; 21 | @override 22 | void reset() {} 23 | @override 24 | void updateByte(int inp) {} 25 | @override 26 | void update(Uint8List? inp, int inpOff, int? len) {} 27 | @override 28 | int doFinal(Uint8List? out, int? outOff) { 29 | out!.fillRange(0, digestSize, 0); 30 | return digestSize; 31 | } 32 | 33 | @override 34 | // TODO: implement byteLength 35 | int get byteLength => throw UnimplementedError(); 36 | } 37 | -------------------------------------------------------------------------------- /test/test/src/null_secure_random.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'package:pointycastle/api.dart'; 4 | import 'package:pointycastle/src/impl/secure_random_base.dart'; 5 | import 'package:pointycastle/src/registry/registry.dart'; 6 | import 'package:pointycastle/src/ufixnum.dart'; 7 | 8 | /// An implementation of [SecureRandom] that return numbers in growing sequence. 9 | class NullSecureRandom extends SecureRandomBase { 10 | static final FactoryConfig factoryConfig = 11 | StaticFactoryConfig(SecureRandom, 'Null', () => NullSecureRandom()); 12 | 13 | var _nextValue = 0; 14 | @override 15 | String get algorithmName => 'Null'; 16 | @override 17 | void seed(CipherParameters params) {} 18 | @override 19 | int nextUint8() => clip8(_nextValue++); 20 | } 21 | -------------------------------------------------------------------------------- /test/test/src/null_stream_cipher.dart: -------------------------------------------------------------------------------- 1 | // See file LICENSE for more information. 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:pointycastle/api.dart'; 6 | import 'package:pointycastle/src/impl/base_stream_cipher.dart'; 7 | import 'package:pointycastle/src/registry/registry.dart'; 8 | 9 | /// An implementation of a null [StreamCipher], that is, a cipher that does not encrypt, neither decrypt. It can be used for 10 | /// testing or benchmarking chaining algorithms. 11 | class NullStreamCipher extends BaseStreamCipher { 12 | static final FactoryConfig factoryConfig = 13 | StaticFactoryConfig(StreamCipher, 'Null', () => NullStreamCipher()); 14 | @override 15 | String get algorithmName => 'Null'; 16 | @override 17 | void reset() {} 18 | @override 19 | void init(bool forEncryption, CipherParameters? params) {} 20 | @override 21 | void processBytes( 22 | Uint8List? inp, int inpOff, int len, Uint8List? out, int outOff) { 23 | out!.setRange(outOff, outOff + len, inp!.sublist(inpOff)); 24 | } 25 | 26 | @override 27 | int returnByte(int inp) { 28 | return inp; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tutorials/examples/README.md: -------------------------------------------------------------------------------- 1 | Tutorial examples 2 | ================= 3 | 4 | These programs were used during the development of the code fragments 5 | used in the tutorials. 6 | 7 | They are not officially a part of the tutorials, and are only provided 8 | on an as-is basis. 9 | 10 | ## Running the examples 11 | 12 | Run "dart pub get" in the parent directory, and then run the example Dart 13 | Dart programs. For example: 14 | 15 | ```sh 16 | dart aes-cbc-direct.dart 17 | dart digest-direct.dart "foobar" 18 | dart rsa-demo.dart 19 | ``` 20 | 21 | All of these example programs accept the "-h" or "--help" option. 22 | 23 | ## Checking the text in the tutorials 24 | 25 | Fragments of the Dart code are copied into the MarkDown tutorial files 26 | in the parent directory. 27 | 28 | The fragments between comment lines containing "BEGIN EXAMPLE" and 29 | "END EXAMPLE" should appear literally the same in the MarkDown file. 30 | Other fragments have been modified to make them more readable in the 31 | tutorial and more functional in the example code. 32 | -------------------------------------------------------------------------------- /tutorials/examples/import-demo/README.md: -------------------------------------------------------------------------------- 1 | Import tests 2 | ============ 3 | 4 | These examples illustrate the effect of the different ways of 5 | importing Pointy Castle classes. 6 | 7 | The programs are essentially the same, except for the imports they 8 | use. In import-demo-1.dart and import-demo-4.dart, the imports used 9 | does not allow all/some of the constructors to be available: so in 10 | those examples the `useConstructors` function have been commented out. 11 | 12 | Run `differences-show.sh` to see what the differences are. 13 | -------------------------------------------------------------------------------- /tutorials/examples/import-demo/differences-show.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Show how these examples are different. 4 | 5 | echo "----------------------------------------------------------------" 6 | echo "===== DIFFERENCE BETWEEN import-demo-1 AND import-demo-2 =====" 7 | diff import-demo-1.dart import-demo-2.dart 8 | 9 | echo 10 | echo "----------------------------------------------------------------" 11 | echo "===== DIFFERENCE BETWEEN import-demo-2 AND import-demo-3 =====" 12 | diff import-demo-2.dart import-demo-3.dart 13 | 14 | echo 15 | echo "----------------------------------------------------------------" 16 | echo "===== DIFFERENCE BETWEEN import-demo-3 AND import-demo-4 =====" 17 | diff import-demo-3.dart import-demo-4.dart 18 | --------------------------------------------------------------------------------