├── .gitignore ├── LICENSE ├── README.md ├── certstore ├── README ├── csr │ ├── homut_intermediate.csr │ ├── homut_root.csr │ ├── homut_rsa_intermediate.csr │ └── homut_rsa_root.csr ├── index.txt ├── index.txt.attr ├── install_dir ├── newcerts │ └── dummy.crt ├── openssl.cnf ├── personal │ └── homut_intermediate.crt ├── prime256v1.pem ├── privkeys │ ├── homut_intermediate.key │ └── homut_rsa_intermediate.key ├── serial └── trusted │ ├── homut_bundle.crt │ ├── homut_intermediate.crt │ ├── homut_root.crt │ ├── homut_rsa_bundle.crt │ ├── homut_rsa_intermediate.crt │ └── homut_rsa_root.crt ├── client-server ├── Makefile ├── client-tls2.c ├── exchange-tls12.c ├── server-tls2.c ├── tlsutil.c └── tlsutil.h ├── cryptoauthlib ├── Makefile ├── README.md ├── app │ ├── README.md │ ├── cert_def_1_signer.c │ ├── cert_def_1_signer.h │ ├── cert_def_2_device.c │ ├── cert_def_2_device.h │ ├── cert_def_3_device_csr.c │ └── cert_def_3_device_csr.h ├── lib │ ├── atca_bool.h │ ├── atca_cfgs.c │ ├── atca_cfgs.h │ ├── atca_command.c │ ├── atca_command.h │ ├── atca_compiler.h │ ├── atca_device.c │ ├── atca_device.h │ ├── atca_devtypes.h │ ├── atca_iface.c │ ├── atca_iface.h │ ├── atca_status.h │ ├── atcacert │ │ ├── atcacert.h │ │ ├── atcacert_client.c │ │ ├── atcacert_client.h │ │ ├── atcacert_date.c │ │ ├── atcacert_date.h │ │ ├── atcacert_def.c │ │ ├── atcacert_def.h │ │ ├── atcacert_der.c │ │ ├── atcacert_der.h │ │ ├── atcacert_host_hw.c │ │ ├── atcacert_host_hw.h │ │ ├── atcacert_host_sw.c │ │ └── atcacert_host_sw.h │ ├── basic │ │ ├── README.md │ │ ├── atca_basic.c │ │ ├── atca_basic.h │ │ ├── atca_helpers.c │ │ └── atca_helpers.h │ ├── crypto │ │ ├── README.md │ │ ├── atca_crypto_sw.h │ │ ├── atca_crypto_sw_ecdsa.c │ │ ├── atca_crypto_sw_ecdsa.h │ │ ├── atca_crypto_sw_rand.c │ │ ├── atca_crypto_sw_rand.h │ │ ├── atca_crypto_sw_sha1.c │ │ ├── atca_crypto_sw_sha1.h │ │ ├── atca_crypto_sw_sha2.c │ │ ├── atca_crypto_sw_sha2.h │ │ └── hashes │ │ │ ├── sha1_routines.c │ │ │ ├── sha1_routines.h │ │ │ ├── sha2_routines.c │ │ │ └── sha2_routines.h │ ├── cryptoauthlib.h │ ├── hal │ │ ├── README.md │ │ ├── atca_hal.c │ │ ├── atca_hal.h │ │ ├── atca_start_config.h │ │ ├── atca_start_iface.h │ │ ├── hal_at90usb1287_i2c_asf.c │ │ ├── hal_at90usb1287_i2c_asf.h │ │ ├── hal_at90usb1287_timer_asf.c │ │ ├── hal_i2c_bitbang.c │ │ ├── hal_i2c_bitbang.h │ │ ├── hal_linux_i2c_userspace.c │ │ ├── hal_linux_i2c_userspace.h │ │ ├── hal_linux_kit_cdc.c │ │ ├── hal_linux_kit_cdc.h │ │ ├── hal_linux_kit_hid.c │ │ ├── hal_linux_kit_hid.h │ │ ├── hal_linux_os.c │ │ ├── hal_linux_timer.c │ │ ├── hal_pic32mx695f512h_i2c.c │ │ ├── hal_pic32mx695f512h_i2c.h │ │ ├── hal_pic32mx695f512h_timer.c │ │ ├── hal_sam4s_i2c_asf.c │ │ ├── hal_sam4s_i2c_asf.h │ │ ├── hal_sam4s_timer_asf.c │ │ ├── hal_samb11_i2c_asf.c │ │ ├── hal_samb11_i2c_asf.h │ │ ├── hal_samb11_timer_asf.c │ │ ├── hal_samd21_i2c_asf.c │ │ ├── hal_samd21_i2c_asf.h │ │ ├── hal_samd21_i2c_start.c │ │ ├── hal_samd21_i2c_start.h │ │ ├── hal_samd21_timer_asf.c │ │ ├── hal_samd21_timer_start.c │ │ ├── hal_samg55_i2c_asf.c │ │ ├── hal_samg55_i2c_asf.h │ │ ├── hal_samg55_timer_asf.c │ │ ├── hal_samv71_i2c_asf.c │ │ ├── hal_samv71_i2c_asf.h │ │ ├── hal_samv71_timer_asf.c │ │ ├── hal_swi_bitbang.c │ │ ├── hal_swi_bitbang.h │ │ ├── hal_swi_uart.c │ │ ├── hal_swi_uart.h │ │ ├── hal_uboot_i2c.c │ │ ├── hal_uboot_i2c.h │ │ ├── hal_uboot_timer.c │ │ ├── hal_win_kit_cdc.c │ │ ├── hal_win_kit_cdc.h │ │ ├── hal_win_kit_hid.c │ │ ├── hal_win_kit_hid.h │ │ ├── hal_win_os.c │ │ ├── hal_win_timer.c │ │ ├── hal_xmega_a3bu_i2c_asf.c │ │ ├── hal_xmega_a3bu_i2c_asf.h │ │ ├── hal_xmega_a3bu_timer_asf.c │ │ ├── i2c_bitbang_samd21.c │ │ ├── i2c_bitbang_samd21.h │ │ ├── kit_phy.h │ │ ├── kit_protocol.c │ │ ├── kit_protocol.h │ │ ├── swi_bitbang_samd21.c │ │ ├── swi_bitbang_samd21.h │ │ ├── swi_uart_at90usb1287_asf.c │ │ ├── swi_uart_at90usb1287_asf.h │ │ ├── swi_uart_samd21_asf.c │ │ ├── swi_uart_samd21_asf.h │ │ ├── swi_uart_samd21_start.c │ │ ├── swi_uart_samd21_start.h │ │ ├── swi_uart_xmega_a3bu_asf.c │ │ └── swi_uart_xmega_a3bu_asf.h │ ├── host │ │ ├── atca_host.c │ │ └── atca_host.h │ ├── openssl │ │ ├── README.md │ │ ├── eccx08_cert.c │ │ ├── eccx08_cipher.c │ │ ├── eccx08_cmd_defns.c │ │ ├── eccx08_ecdh.c │ │ ├── eccx08_ecdsa_sign.c │ │ ├── eccx08_eckey_meth.c │ │ ├── eccx08_engine.c │ │ ├── eccx08_engine.h │ │ ├── eccx08_engine_internal.h │ │ ├── eccx08_platform.c │ │ ├── eccx08_rand.c │ │ └── eccx08_sha256.c │ └── tls │ │ ├── atcatls.c │ │ ├── atcatls.h │ │ ├── atcatls_cfg.c │ │ ├── atcatls_cfg.h │ │ └── ec_cert-508.csr └── test │ ├── atca_basic_tests.c │ ├── atca_basic_tests.h │ ├── atca_crypto_sw_tests.c │ ├── atca_crypto_sw_tests.h │ ├── atca_test.c │ ├── atca_test.h │ ├── atca_unit_tests.c │ ├── atca_unit_tests.h │ ├── atcacert │ ├── all_atcacert_tests.c │ ├── test_atcacert_client.c │ ├── test_atcacert_client_runner.c │ ├── test_atcacert_date.c │ ├── test_atcacert_date_runner.c │ ├── test_atcacert_def.c │ ├── test_atcacert_def_runner.c │ ├── test_atcacert_der_ecdsa_sig_value.c │ ├── test_atcacert_der_ecdsa_sig_value_runner.c │ ├── test_atcacert_der_integer.c │ ├── test_atcacert_der_integer_runner.c │ ├── test_atcacert_der_length.c │ ├── test_atcacert_der_length_runner.c │ ├── test_atcacert_host_hw.c │ ├── test_atcacert_host_hw_runner.c │ ├── test_cert_def_0_device.c │ ├── test_cert_def_0_device.h │ ├── test_cert_def_1_signer.c │ └── test_cert_def_1_signer.h │ ├── cbuf.h │ ├── cmd-processor.c │ ├── cmd-processor.h │ ├── openssl │ └── test_engine.c │ ├── sha-byte-test-vectors │ ├── Readme.txt │ ├── SHA1LongMsg.rsp │ ├── SHA1Monte.rsp │ ├── SHA1Monte.txt │ ├── SHA1ShortMsg.rsp │ ├── SHA224LongMsg.rsp │ ├── SHA224Monte.rsp │ ├── SHA224Monte.txt │ ├── SHA224ShortMsg.rsp │ ├── SHA256LongMsg.rsp │ ├── SHA256Monte.rsp │ ├── SHA256Monte.txt │ ├── SHA256ShortMsg.rsp │ ├── SHA384LongMsg.rsp │ ├── SHA384Monte.rsp │ ├── SHA384Monte.txt │ ├── SHA384ShortMsg.rsp │ ├── SHA512LongMsg.rsp │ ├── SHA512Monte.rsp │ ├── SHA512Monte.txt │ └── SHA512ShortMsg.rsp │ ├── tls │ ├── atcatls_tests.c │ └── atcatls_tests.h │ ├── unity.c │ ├── unity.h │ ├── unity_fixture.c │ ├── unity_fixture.h │ ├── unity_fixture_internals.h │ ├── unity_fixture_malloc_overrides.h │ └── unity_internals.h └── scripts ├── TestMatrix.xlsx ├── archive ├── run_client ├── run_client_eng ├── run_der_client ├── run_der_server ├── run_rsa_client ├── run_rsa_server ├── run_server ├── run_server_eng ├── test_client ├── test_client_neg └── test_server ├── common.sh ├── mk_release_lite ├── run_cert_client.sh ├── run_cert_serv.sh ├── run_client.sh ├── run_eng_cmds ├── run_extract_certs.sh ├── run_rsa_ca.sh ├── run_server.sh ├── run_tests ├── test_engine_post.py └── test_engine_pre.py /.gitignore: -------------------------------------------------------------------------------- 1 | install_dir/ 2 | /Debug/ 3 | .*swp 4 | *.pydevproject 5 | .metadata 6 | .gradle 7 | bin/ 8 | tmp/ 9 | *.tmp 10 | *.bak 11 | *.swp 12 | *~.nib 13 | local.properties 14 | .settings/ 15 | .loadpath 16 | 17 | *.[0-9] 18 | *.o 19 | *.so 20 | .*swo 21 | .*swp 22 | .*.swp 23 | *.cmd 24 | *.a 25 | arm-eabi-4.7-master* 26 | ecc-test-main 27 | *.gnu 28 | *.out 29 | *.exp 30 | *.*~ 31 | 32 | newcerts/ 33 | *.old 34 | *.der 35 | *.pem 36 | personal/ 37 | csr/ 38 | exchange-tls12 39 | *homut_client_* 40 | *homut_server_* 41 | homut_rsa_* 42 | AT_* 43 | 44 | # Eclipse Core 45 | .project 46 | 47 | # External tool builders 48 | .externalToolBuilders/ 49 | 50 | # Locally stored "Eclipse launch configurations" 51 | *.launch 52 | 53 | # CDT-specific 54 | .cproject 55 | 56 | # JDT-specific (Eclipse Java Development Tools) 57 | .classpath 58 | 59 | # Java annotation processor (APT) 60 | .factorypath 61 | 62 | # PDT-specific 63 | .buildpath 64 | 65 | # sbteclipse plugin 66 | .target 67 | 68 | # TeXlipse plugin 69 | .texlipse 70 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 2 | 3 | You are permitted to use this software and its derivatives with Microchip 4 | products. Redistribution and use in source and binary forms, with or without 5 | modification, is permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | 3. The name of Microchip may not be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | 4. This software may only be redistributed and used in connection with a 18 | Microchip integrated circuit. 19 | 20 | THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 23 | EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | Configuration: 3 | 4 | Most of the configuration of the library can be done in lib/openssl/eccx08_engine.h or via defines during build 5 | 6 | The exception to this is in eccx08_platform.c where key slots are defaulted 7 | 8 | If the ATCA_OPENSSL_ENGINE_STATIC_CONFIG define is set to 1 then device and signer certificate definitions will 9 | have to be linked into the library at build. 10 | 11 | e.g. see the line in the makefile: #LIBATECCSSL_OBJECTS += cert_def_1_signer.c cert_def_2_signer.c 12 | 13 | 14 | Makfile: 15 | 16 | The makefile included in this archive is fairly basic and is not what one would consider appropriate for a package 17 | so there is likely some manual configuration that would be needed at this stage 18 | 19 | 20 | To build the library: 21 | 22 | > make libateccssl 23 | 24 | To run the test program: 25 | 26 | > make test 27 | 28 | To extract certificates (if the engine is added to the openssl.cnf file): 29 | 30 | > openssl engine ateccx08 -t -post GET_DEVICE_CERT:./device.der 31 | > openssl engine ateccx08 -t -post GET_SIGNER_CERT:./signer.der 32 | 33 | Otherwise you'll have to use an interactive openssl session (see openssl engine -h and engine -vvv for details) 34 | 35 | > openssl 36 | 37 | OpenSSL> engine dynamic -pre SO_PATH:/ -pre LIST_ADD:1 -pre ID:ateccx08 -pre LOAD 38 | OpenSSL> engine ateccx08 -t -post GET_DEVICE_CERT:./device.der 39 | OpenSSL> engine ateccx08 -t -post GET_SIGNER_CERT:./signer.der 40 | 41 | Then to verify the certs: 42 | > openssl x509 -in device.der -inform der -text -noout 43 | > openssl x509 -in signer.der -inform der -text -noout 44 | 45 | To set up your openssl.cnf file 46 | 47 | Find which openssl.cnf file your instance is using you can: 48 | 49 | > openssl version -a | grep OPENSSLDIR 50 | OPENSSLDIR: "/usr/lib/ssl" 51 | 52 | will tell you the base location where openssl is looking for the openssl.cnf file. It may be a symbolic link to another location 53 | 54 | > ls -l /usr/lib/ssl 55 | lrwxrwxrwx 1 root root 14 Apr 24 15:22 certs -> /etc/ssl/certs 56 | lrwxrwxrwx 1 root root 20 Jan 31 05:53 openssl.cnf -> /etc/ssl/openssl.cnf 57 | 58 | To set up the openssl.cnf to use the engine: 59 | 60 | # At the top: 61 | 62 | openssl_conf = openssl_init 63 | 64 | # Append to the end: 65 | 66 | [ openssl_init ] 67 | engines = engine_section 68 | 69 | [ engine_section ] 70 | ateccx08 = ateccx08_config 71 | 72 | [ ateccx08_config ] 73 | engine_id = ateccx08 74 | # Or if you sym link the libateccssl.so to the engine directory the next line is not needed 75 | dynamic_path = 76 | device_key_slot = 0 77 | init = 0 78 | 79 | To use the engine in an application you can reference the openssl tests (test/openssl/test_engine.c) but the basic principle is that 80 | if the openssl.cnf file is configured correctly all an application really needs to do is add a call to OPENSSL_config if it is not already 81 | doing so and then to decide what functionality that the application wants and register it. 82 | -------------------------------------------------------------------------------- /certstore/csr/homut_intermediate.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIBGjCBwQIBADBfMQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExEjAQBgNVBAcM 3 | CVN1bm55dmFsZTESMBAGA1UECgwJSG9tdXQgTExDMRswGQYDVQQDDBJob211dF9p 4 | bnRlcm1lZGlhdGUwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARS9WRclU3pr3YO 5 | jozHcBckLczEHetX745msiiTOUWxzo4iB2zISgCgo2kmvwsN2cBSNCmOwr5CQ0E8 6 | a2jXUtZuoAAwCgYIKoZIzj0EAwIDSAAwRQIgHY9a/Sg6KryakS3LnMixx3uM+2BR 7 | UwfneVvhHeLpwDACIQDgbQsRzZ0SKbTKPEQbzrrnI6nSwjPCOBwURj0zNsXY7w== 8 | -----END CERTIFICATE REQUEST----- 9 | -------------------------------------------------------------------------------- /certstore/csr/homut_root.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIBETCBuQIBADBXMQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExEjAQBgNVBAcM 3 | CVN1bm55dmFsZTESMBAGA1UECgwJSG9tdXQgTExDMRMwEQYDVQQDDApIb211dCBS 4 | b290MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEqExIvPpHing52nv6IkKLaRjx 5 | YLaHOmVUnj92j/R/vXYCp/+P4Iv5AY6GYkxHFPOOm2VbicSHGAOyGvMhS687eKAA 6 | MAoGCCqGSM49BAMCA0cAMEQCIFL16MGi173advvd9lVAq/4ab8jfW+7snrHviNv3 7 | AO1oAiAdEMF3R37oPwElj8ki3quf2yyrjLq9w1kXT3v4IHhtKw== 8 | -----END CERTIFICATE REQUEST----- 9 | -------------------------------------------------------------------------------- /certstore/csr/homut_rsa_intermediate.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICqDCCAZACAQAwYzELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQH 3 | DAlTdW5ueXZhbGUxEjAQBgNVBAoMCUhvbXV0IExMQzEfMB0GA1UEAwwWSG9tdXQg 4 | UlNBIEludGVybWVkaWF0ZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB 5 | AO+ftI8hIm32MF4hP8tAHreZ8E2eo8HWKKGX9dKNBCjtsQ9e/cS9Wm3Kxs/k+b8U 6 | Fhlr8hknBEjyWayig0Hf8tJuh+oPFxBgpUuSHG2DbPbY5OVf3nZBqexdE+OSYaub 7 | QNwcvJIgd4Q3L+xrSNNF9LqhFvIhmfraOC+cfl4LfjjyPv2b/Z4KA9Yslv0HJAmF 8 | dPFh1tJ2/zwLilVaoj53A2cQjPL1lwZIs4UXDyM6bWqKGJqhuFdf5k9vV723P9A6 9 | vQFUW2cxaZM7SWnwcQ0pcj8C0ZjXaxfSrlaNOpg0S/ybb5vmkOVBQQywXTrAU9Xk 10 | NlCiDAq7XUXA3LpVsoG4nKcCAwEAAaAAMA0GCSqGSIb3DQEBCwUAA4IBAQBVTqLI 11 | Z4xijmOeXyAGm8F3H+xhiJh3x97aSjeTwV4fwmVrh9jjjAdr78NpiyPU5WYWP2Up 12 | iwXgK3cgHSwe9hg/DrdcnmFfwx9XeZ8OfySkjJBco366Hdc2G+Cn4AwUITtrNJbP 13 | t0sTyanlev4cVXawgaJAupB/z8O6fNGwqWRlJ/hGOlgQh2kwlEB5hG1zVT9qhtZn 14 | PeYojp7SeQr0FMdF13YI4irw+OkAEuyf0naLDL8ScQyhbgmr+ZgjxQb8srbjkN9K 15 | SpHNT7Yn3H2cB5oIXcOG9FLMx7zcFp/i7c1+aATpB+tjhYWIK2CaTR45E1Kh4uan 16 | c7Jvg+YspzBaQ1fa 17 | -----END CERTIFICATE REQUEST----- 18 | -------------------------------------------------------------------------------- /certstore/csr/homut_rsa_root.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICoDCCAYgCAQAwWzELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQH 3 | DAlTdW5ueXZhbGUxEjAQBgNVBAoMCUhvbXV0IExMQzEXMBUGA1UEAwwOSG9tdXQg 4 | UlNBIFJvb3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC0AI9Gyt3z 5 | YhsxFTYhg3lU7K1sEBjbdJCHJB+78Svkv+mbOSGk094gerXC3t5+3VPd5ZZRtRat 6 | zk1O190ymabLHWzw7AE7HFOvEueON8WJsIc0IRjSJHaHhq2kkI2MttLM053tMrL2 7 | 9uOnaP+fz6b2oEQLdaAPnaABvUoiWU4we1+xTud5M2qqx9kjdbWj4uz5EW7mplk7 8 | PBs/eDq1zeRnrkKaCJjnr9rQReCLQNOmsflAvblxK9NYOcqtHBdESyQd85IuMeNy 9 | eGiMAymHldQ+uoQBeS3qzmdW5ujGfQYOz34lPa6M8z4G9PJ3eEd70NM9ofcC21AX 10 | B+7zyToG/CwFAgMBAAGgADANBgkqhkiG9w0BAQsFAAOCAQEAp2uI0I1d/5clDyJ3 11 | hFygU/l/Tcx3wOO5I5AZoOw3Nwk82zwnVNzEF4tXd29fhRDGQUFF2wkWzk40CN4B 12 | lap0pC/rGAKyCTmMck6h3e+ao2+jX50HJnexSOXhP65zVUDwjHzbuGYzi85d82Mh 13 | oOmC1EYUgJBTIsOLT9jfpcET298pOFpunNhwO13buaeBhMyFXbizpmJJ1xW33fuq 14 | ECE429xgivs1hRQpkA58/yJ6kfRubblcfZaqRpiSoWNIiRphzuWrSXeJ9ELGmVl+ 15 | MQkCtWAdsetZxPqs56Pms/vgBegGns3Nw82XIdckpEhnke0bZjqnvLbE8FgsLGXi 16 | 9tQaOQ== 17 | -----END CERTIFICATE REQUEST----- 18 | -------------------------------------------------------------------------------- /certstore/index.txt: -------------------------------------------------------------------------------- 1 | V 160814201525Z 90811C unknown /C=US/ST=CA/O=Homut LLC/CN=homut_server 2 | V 160814201756Z 90811D unknown /C=US/ST=CA/O=Homut LLC/CN=homut_server 3 | V 160814201827Z 90811E unknown /C=US/ST=CA/O=Homut LLC/CN=homut_client 4 | V 160814202029Z 90811F unknown /C=US/ST=CA/O=Homut LLC/CN=homut_client 5 | V 160814202052Z 908120 unknown /C=US/ST=CA/O=Homut LLC/CN=homut_client 6 | V 160814211831Z 908121 unknown /C=US/ST=CA/O=Homut LLC/CN=homut_intermediate 7 | V 160814212255Z 908122 unknown /C=US/ST=CA/O=Homut LLC/CN=homut_intermediate 8 | V 160814212315Z 908123 unknown /C=US/ST=CA/O=Homut LLC/CN=homut_server 9 | V 160814212330Z 908124 unknown /C=US/ST=CA/O=Homut LLC/CN=homut_client 10 | V 161006034901Z 908125 unknown /C=US/ST=CA/O=Homut LLC/CN=homut_server_eccx08 11 | V 161006043835Z 908126 unknown /C=US/ST=CA/O=Homut LLC/CN=homut_server_eccx08 12 | V 161006043840Z 908127 unknown /C=US/ST=CA/O=Homut LLC/CN=homut_client_eccx08 13 | -------------------------------------------------------------------------------- /certstore/index.txt.attr: -------------------------------------------------------------------------------- 1 | unique_subject = no 2 | -------------------------------------------------------------------------------- /certstore/install_dir: -------------------------------------------------------------------------------- 1 | ../install_dir -------------------------------------------------------------------------------- /certstore/newcerts/dummy.crt: -------------------------------------------------------------------------------- 1 | # It is a dummy certificate to commit the directory into git 2 | -------------------------------------------------------------------------------- /certstore/personal/homut_intermediate.crt: -------------------------------------------------------------------------------- 1 | Certificate: 2 | Data: 3 | Version: 3 (0x2) 4 | Serial Number: 9470241 (0x908121) 5 | Signature Algorithm: ecdsa-with-SHA256 6 | Issuer: C=US, ST=CA, O=Homut LLC, CN=Homut Root 7 | Validity 8 | Not Before: Aug 15 21:18:31 2015 GMT 9 | Not After : Aug 14 21:18:31 2016 GMT 10 | Subject: C=US, ST=CA, O=Homut LLC, CN=homut_intermediate 11 | Subject Public Key Info: 12 | Public Key Algorithm: id-ecPublicKey 13 | Public-Key: (256 bit) 14 | pub: 15 | 04:52:f5:64:5c:95:4d:e9:af:76:0e:8e:8c:c7:70: 16 | 17:24:2d:cc:c4:1d:eb:57:ef:8e:66:b2:28:93:39: 17 | 45:b1:ce:8e:22:07:6c:c8:4a:00:a0:a3:69:26:bf: 18 | 0b:0d:d9:c0:52:34:29:8e:c2:be:42:43:41:3c:6b: 19 | 68:d7:52:d6:6e 20 | ASN1 OID: prime256v1 21 | NIST CURVE: P-256 22 | X509v3 extensions: 23 | X509v3 Subject Key Identifier: 24 | 48:AD:13:D9:B9:44:56:46:FC:D2:9B:57:04:4D:5E:1D:D9:86:30:F5 25 | X509v3 Authority Key Identifier: 26 | keyid:89:6D:BB:6D:EA:10:4D:81:8B:E7:29:32:13:C9:5E:67:0C:CA:96:44 27 | DirName:/C=US/ST=CA/O=Homut LLC/CN=Homut Root 28 | serial:90:81:1A 29 | 30 | X509v3 Basic Constraints: 31 | CA:TRUE 32 | X509v3 Subject Alternative Name: 33 | 34 | 35 | Signature Algorithm: ecdsa-with-SHA256 36 | 30:44:02:20:16:59:1f:2e:82:a9:0f:ee:ba:8c:d9:b3:9d:71: 37 | 74:08:d2:e2:d0:15:66:81:e9:11:be:70:90:9f:25:ff:8a:bc: 38 | 02:20:02:7e:08:9a:1f:94:ae:35:ca:29:78:78:08:2f:b1:86: 39 | 71:0e:7f:3f:1f:d3:a6:9e:b6:df:98:62:2e:a7:24:5b 40 | -----BEGIN CERTIFICATE----- 41 | MIICKzCCAdKgAwIBAgIEAJCBITAKBggqhkjOPQQDAjBDMQswCQYDVQQGEwJVUzEL 42 | MAkGA1UECAwCQ0ExEjAQBgNVBAoMCUhvbXV0IExMQzETMBEGA1UEAwwKSG9tdXQg 43 | Um9vdDAeFw0xNTA4MTUyMTE4MzFaFw0xNjA4MTQyMTE4MzFaMEsxCzAJBgNVBAYT 44 | AlVTMQswCQYDVQQIDAJDQTESMBAGA1UECgwJSG9tdXQgTExDMRswGQYDVQQDDBJo 45 | b211dF9pbnRlcm1lZGlhdGUwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARS9WRc 46 | lU3pr3YOjozHcBckLczEHetX745msiiTOUWxzo4iB2zISgCgo2kmvwsN2cBSNCmO 47 | wr5CQ0E8a2jXUtZuo4GrMIGoMB0GA1UdDgQWBBRIrRPZuURWRvzSm1cETV4d2YYw 48 | 9TBuBgNVHSMEZzBlgBSJbbtt6hBNgYvnKTITyV5nDMqWRKFHpEUwQzELMAkGA1UE 49 | BhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQKDAlIb211dCBMTEMxEzARBgNVBAMM 50 | CkhvbXV0IFJvb3SCBACQgRowDAYDVR0TBAUwAwEB/zAJBgNVHREEAjAAMAoGCCqG 51 | SM49BAMCA0cAMEQCIBZZHy6CqQ/uuozZs51xdAjS4tAVZoHpEb5wkJ8l/4q8AiAC 52 | fgiaH5SuNcopeHgIL7GGcQ5/Px/Tpp6235hiLqckWw== 53 | -----END CERTIFICATE----- 54 | -------------------------------------------------------------------------------- /certstore/prime256v1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PARAMETERS----- 2 | BggqhkjOPQMBBw== 3 | -----END EC PARAMETERS----- 4 | -------------------------------------------------------------------------------- /certstore/privkeys/homut_intermediate.key: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PARAMETERS----- 2 | BggqhkjOPQMBBw== 3 | -----END EC PARAMETERS----- 4 | -----BEGIN EC PRIVATE KEY----- 5 | MHcCAQEEIPA7KpgRuI59P9Bua0wo3HWzHxz+0kEPpU7hyilTqvG+oAoGCCqGSM49 6 | AwEHoUQDQgAEUvVkXJVN6a92Do6Mx3AXJC3MxB3rV++OZrIokzlFsc6OIgdsyEoA 7 | oKNpJr8LDdnAUjQpjsK+QkNBPGto11LWbg== 8 | -----END EC PRIVATE KEY----- 9 | -------------------------------------------------------------------------------- /certstore/privkeys/homut_rsa_intermediate.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEA75+0jyEibfYwXiE/y0Aet5nwTZ6jwdYooZf10o0EKO2xD179 3 | xL1abcrGz+T5vxQWGWvyGScESPJZrKKDQd/y0m6H6g8XEGClS5IcbYNs9tjk5V/e 4 | dkGp7F0T45Jhq5tA3By8kiB3hDcv7GtI00X0uqEW8iGZ+to4L5x+Xgt+OPI+/Zv9 5 | ngoD1iyW/QckCYV08WHW0nb/PAuKVVqiPncDZxCM8vWXBkizhRcPIzptaooYmqG4 6 | V1/mT29Xvbc/0Dq9AVRbZzFpkztJafBxDSlyPwLRmNdrF9KuVo06mDRL/Jtvm+aQ 7 | 5UFBDLBdOsBT1eQ2UKIMCrtdRcDculWygbicpwIDAQABAoIBAGu1K6HSUPmAWYlW 8 | BKjFb4kzhpI9JnpwWt8XwQUdIauL+7RfDE4slsMXDHpR//hlfPF8Vdv8b66iULCK 9 | c9leYnU3/Zu1oLZZ2rK3QFPxaT8jiu+XQhWBunFl/RSjrYdHR8YonJJKSa6CZ+Yq 10 | 6xccML7avcekVuQsxmiQPTTkkZ3iVseERXixGyUDbbFj8MyiA6wGhrJPjKiLbLqG 11 | xHbDY4EDVwtm9L5gYtuAPEkqwpAITqInlAfCgiz7mHe4bbvtNMJkp1NgezYxD8Zh 12 | LW78dDcUXNoF14/HKadRdxHGhcajZ1Zs17ngfDkdLp2JxgwxgA7UXTwp1mScV0MS 13 | 9FD2qqECgYEA+ckPd0RgEcyo4WKP3JrhWBw5tEyRQPplQBrm8DdqUJKCvfjg3jC2 14 | r7hN+4cZkVF+FTR6nuFXA9FlfwguRcB6FkNc4902p7peAPH41t197AyGIZUWIW9o 15 | 4na00Y0qdnQsbjBwwphdEU7NohmUX4V2+B2k7PY5We5yiq87unWIDj8CgYEA9ZXs 16 | eZWfRm/Ld9NJW43VEkPM6i9bXgBd9ThIoocuZbnieCL11dS+YIJr4h1qBHLqM7sO 17 | NW6tkTUTjLoL1zXO3N50zSxebic/tcxFyD5bkAnqYKskbkPOv5CP9tvRk6ZsI1BG 18 | dacT7ir9RgwNAMJPEWOQZ5rnQCtlXk1EjpCjp5kCgYBUp3qxXh/9CFKYCDJffrIu 19 | jWpVG7oCvpoADt4DvZQveGgNAEMdqn7PsPPk8hWNNYQ4pY+FNzOpXJc8ZUZhZ2k5 20 | EF1z8G3sjHH9egRutaROkrQGv6M/c6WlUrvXZTNl79t7ALnGiaLJEd8JOAgcE3yN 21 | fGZ/1Lb9Lp3tOJRSjjCtOwKBgQCygmCaXBSjKV3XYoA/CVBob1oCm5upL1EcjuXV 22 | Jbem/7/LHXZeEL60/fgXKtRGGZV9Nql0U1fcZZ0pPI6gxx7vUs/J10dogCUCK1JJ 23 | 5HG/uEViMORRNf6RJi5O/KdQ0LZn0ND2chS9mQfyo43MEHFSrXForaML9L9BFZ8Q 24 | lbgveQKBgDVWoMgS6pMqcx2Jxsx5FR+vlBHPo1YNGUpJW/WWtv0amhZAJnGQbAsb 25 | 9Dg4Bal2zZ1CycikSu7SnYEnqkf4WRiPgg8LBWQAJ/yHxD0YFkcxYhRaDm+it6NN 26 | t0AJc/NNFQ6KMg2oGbScgWglw0tRrnIvRbcnOfosDndpgWfARZFE 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /certstore/serial: -------------------------------------------------------------------------------- 1 | 908128 2 | -------------------------------------------------------------------------------- /certstore/trusted/homut_intermediate.crt: -------------------------------------------------------------------------------- 1 | Certificate: 2 | Data: 3 | Version: 3 (0x2) 4 | Serial Number: 9470242 (0x908122) 5 | Signature Algorithm: ecdsa-with-SHA256 6 | Issuer: C=US, ST=CA, O=Homut LLC, CN=Homut Root 7 | Validity 8 | Not Before: Aug 15 21:22:55 2015 GMT 9 | Not After : Aug 14 21:22:55 2016 GMT 10 | Subject: C=US, ST=CA, O=Homut LLC, CN=homut_intermediate 11 | Subject Public Key Info: 12 | Public Key Algorithm: id-ecPublicKey 13 | Public-Key: (256 bit) 14 | pub: 15 | 04:52:f5:64:5c:95:4d:e9:af:76:0e:8e:8c:c7:70: 16 | 17:24:2d:cc:c4:1d:eb:57:ef:8e:66:b2:28:93:39: 17 | 45:b1:ce:8e:22:07:6c:c8:4a:00:a0:a3:69:26:bf: 18 | 0b:0d:d9:c0:52:34:29:8e:c2:be:42:43:41:3c:6b: 19 | 68:d7:52:d6:6e 20 | ASN1 OID: prime256v1 21 | NIST CURVE: P-256 22 | X509v3 extensions: 23 | X509v3 Subject Key Identifier: 24 | 48:AD:13:D9:B9:44:56:46:FC:D2:9B:57:04:4D:5E:1D:D9:86:30:F5 25 | X509v3 Authority Key Identifier: 26 | keyid:89:6D:BB:6D:EA:10:4D:81:8B:E7:29:32:13:C9:5E:67:0C:CA:96:44 27 | DirName:/C=US/ST=CA/O=Homut LLC/CN=Homut Root 28 | serial:90:81:1A 29 | 30 | X509v3 Basic Constraints: 31 | CA:TRUE 32 | X509v3 Subject Alternative Name: 33 | 34 | 35 | Signature Algorithm: ecdsa-with-SHA256 36 | 30:45:02:20:1e:42:b1:2f:a2:1a:81:c3:36:3d:7d:e3:83:ab: 37 | e7:12:be:5e:ab:36:cb:65:b6:10:64:17:f8:db:80:d3:c9:f9: 38 | 02:21:00:88:20:e0:8c:33:1f:e7:b7:46:9b:fc:48:9f:ca:7c: 39 | 08:df:51:12:37:c4:a2:bd:c7:1b:9e:1b:69:ea:2a:04:d2 40 | -----BEGIN CERTIFICATE----- 41 | MIICLDCCAdKgAwIBAgIEAJCBIjAKBggqhkjOPQQDAjBDMQswCQYDVQQGEwJVUzEL 42 | MAkGA1UECAwCQ0ExEjAQBgNVBAoMCUhvbXV0IExMQzETMBEGA1UEAwwKSG9tdXQg 43 | Um9vdDAeFw0xNTA4MTUyMTIyNTVaFw0xNjA4MTQyMTIyNTVaMEsxCzAJBgNVBAYT 44 | AlVTMQswCQYDVQQIDAJDQTESMBAGA1UECgwJSG9tdXQgTExDMRswGQYDVQQDDBJo 45 | b211dF9pbnRlcm1lZGlhdGUwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARS9WRc 46 | lU3pr3YOjozHcBckLczEHetX745msiiTOUWxzo4iB2zISgCgo2kmvwsN2cBSNCmO 47 | wr5CQ0E8a2jXUtZuo4GrMIGoMB0GA1UdDgQWBBRIrRPZuURWRvzSm1cETV4d2YYw 48 | 9TBuBgNVHSMEZzBlgBSJbbtt6hBNgYvnKTITyV5nDMqWRKFHpEUwQzELMAkGA1UE 49 | BhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQKDAlIb211dCBMTEMxEzARBgNVBAMM 50 | CkhvbXV0IFJvb3SCBACQgRowDAYDVR0TBAUwAwEB/zAJBgNVHREEAjAAMAoGCCqG 51 | SM49BAMCA0gAMEUCIB5CsS+iGoHDNj1944Or5xK+Xqs2y2W2EGQX+NuA08n5AiEA 52 | iCDgjDMf57dGm/xIn8p8CN9REjfEor3HG54baeoqBNI= 53 | -----END CERTIFICATE----- 54 | -------------------------------------------------------------------------------- /certstore/trusted/homut_root.crt: -------------------------------------------------------------------------------- 1 | Certificate: 2 | Data: 3 | Version: 3 (0x2) 4 | Serial Number: 9470234 (0x90811a) 5 | Signature Algorithm: ecdsa-with-SHA256 6 | Issuer: C=US, ST=CA, O=Homut LLC, CN=Homut Root 7 | Validity 8 | Not Before: Aug 15 20:04:16 2015 GMT 9 | Not After : May 11 20:04:16 2018 GMT 10 | Subject: C=US, ST=CA, O=Homut LLC, CN=Homut Root 11 | Subject Public Key Info: 12 | Public Key Algorithm: id-ecPublicKey 13 | Public-Key: (256 bit) 14 | pub: 15 | 04:a8:4c:48:bc:fa:47:8a:78:39:da:7b:fa:22:42: 16 | 8b:69:18:f1:60:b6:87:3a:65:54:9e:3f:76:8f:f4: 17 | 7f:bd:76:02:a7:ff:8f:e0:8b:f9:01:8e:86:62:4c: 18 | 47:14:f3:8e:9b:65:5b:89:c4:87:18:03:b2:1a:f3: 19 | 21:4b:af:3b:78 20 | ASN1 OID: prime256v1 21 | NIST CURVE: P-256 22 | X509v3 extensions: 23 | X509v3 Subject Key Identifier: 24 | 89:6D:BB:6D:EA:10:4D:81:8B:E7:29:32:13:C9:5E:67:0C:CA:96:44 25 | X509v3 Authority Key Identifier: 26 | keyid:89:6D:BB:6D:EA:10:4D:81:8B:E7:29:32:13:C9:5E:67:0C:CA:96:44 27 | DirName:/C=US/ST=CA/O=Homut LLC/CN=Homut Root 28 | serial:90:81:1A 29 | 30 | X509v3 Basic Constraints: 31 | CA:TRUE 32 | Signature Algorithm: ecdsa-with-SHA256 33 | 30:44:02:20:13:15:63:cb:23:90:3a:83:d8:5e:fa:fb:c0:81: 34 | 81:ef:89:b7:72:d6:b4:a5:f3:1c:e6:65:fe:6c:3d:94:7b:13: 35 | 02:20:46:6c:31:68:5e:e3:a8:7f:6c:82:4e:70:1d:49:82:7b: 36 | 09:c0:29:35:77:f4:5f:44:96:98:59:0c:0f:33:4d:30 37 | -----BEGIN CERTIFICATE----- 38 | MIICGDCCAb+gAwIBAgIEAJCBGjAKBggqhkjOPQQDAjBDMQswCQYDVQQGEwJVUzEL 39 | MAkGA1UECAwCQ0ExEjAQBgNVBAoMCUhvbXV0IExMQzETMBEGA1UEAwwKSG9tdXQg 40 | Um9vdDAeFw0xNTA4MTUyMDA0MTZaFw0xODA1MTEyMDA0MTZaMEMxCzAJBgNVBAYT 41 | AlVTMQswCQYDVQQIDAJDQTESMBAGA1UECgwJSG9tdXQgTExDMRMwEQYDVQQDDApI 42 | b211dCBSb290MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEqExIvPpHing52nv6 43 | IkKLaRjxYLaHOmVUnj92j/R/vXYCp/+P4Iv5AY6GYkxHFPOOm2VbicSHGAOyGvMh 44 | S687eKOBoDCBnTAdBgNVHQ4EFgQUiW27beoQTYGL5ykyE8leZwzKlkQwbgYDVR0j 45 | BGcwZYAUiW27beoQTYGL5ykyE8leZwzKlkShR6RFMEMxCzAJBgNVBAYTAlVTMQsw 46 | CQYDVQQIDAJDQTESMBAGA1UECgwJSG9tdXQgTExDMRMwEQYDVQQDDApIb211dCBS 47 | b290ggQAkIEaMAwGA1UdEwQFMAMBAf8wCgYIKoZIzj0EAwIDRwAwRAIgExVjyyOQ 48 | OoPYXvr7wIGB74m3cta0pfMc5mX+bD2UexMCIEZsMWhe46h/bIJOcB1JgnsJwCk1 49 | d/RfRJaYWQwPM00w 50 | -----END CERTIFICATE----- 51 | -------------------------------------------------------------------------------- /client-server/Makefile: -------------------------------------------------------------------------------- 1 | # To compile exchange-tls12 utility 2 | CC= gcc 3 | CWD:= $(shell pwd) 4 | OPENSSL_VER?= _1_0_2 5 | OPENSSL= openssl$(OPENSSL_VER) 6 | #HW?= -DECC_DEBUG 7 | HW?= -DUSE_ECCX08 -DECC_DEBUG 8 | 9 | CFLAGS += -g -O0 -ggdb -Wall \ 10 | -I$(CWD)/../engine_atecc \ 11 | -I$(CWD)/../install_dir/include \ 12 | -I$(CWD)/../$(OPENSSL)/crypto \ 13 | -I$(CWD)/../$(OPENSSL)/crypto/bn \ 14 | -I$(CWD)/../engine_atecc/cryptoauthlib \ 15 | -I$(CWD)/../engine_atecc/cryptoauthlib/lib \ 16 | -I$(CWD)/../engine_atecc/cryptoauthlib/lib/tls \ 17 | ${HW} 18 | 19 | LDFLAGS += -L$(CWD)/../install_dir/lib -lssl -lcrypto 20 | 21 | .SILENT: 22 | 23 | SRC= $(wildcard *.c) 24 | APPS= $(patsubst %.c,%.o,$(SRC)) 25 | 26 | all: $(APPS) 27 | @$(CC) $(CFLAGS) $(OFLAGS) $(APPS) $(LDFLAGS) -o exchange-tls12 28 | 29 | %.o: %.c 30 | @echo "Compiling $<. CFLAGS = $(CFLAGS)" 31 | @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -c $< 32 | 33 | clean: 34 | echo "Deleting -> rm -f $(APPS)" 35 | rm -f $(APPS) exchange-tls12 36 | 37 | list: 38 | echo $(APPS) 39 | -------------------------------------------------------------------------------- /cryptoauthlib/app/README.md: -------------------------------------------------------------------------------- 1 | app directory - Purpose 2 | =================== 3 | 4 | This directory is for application specific implementation of various use cases. 5 | 6 | Methods in this directory provide a simple API to perform potentially complex 7 | combinations of calls to the main atca crypto library or API. 8 | 9 | -------------------------------------------------------------------------------- /cryptoauthlib/app/cert_def_1_signer.h: -------------------------------------------------------------------------------- 1 | #ifndef CERT_DEF_1_SIGNER_H 2 | #define CERT_DEF_1_SIGNER_H 3 | 4 | #include "atcacert/atcacert_def.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | extern uint8_t g_signer_1_ca_public_key[]; 11 | extern const atcacert_def_t g_cert_def_1_signer; 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif // CERT_DEF_1_SIGNER_H 18 | -------------------------------------------------------------------------------- /cryptoauthlib/app/cert_def_2_device.h: -------------------------------------------------------------------------------- 1 | #ifndef CERT_DEF_2_DEVICE_H 2 | #define CERT_DEF_2_DEVICE_H 3 | 4 | #include "atcacert/atcacert_def.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | extern const atcacert_def_t g_cert_def_2_device; 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif // CERT_DEF_2_DEVICE_H 17 | -------------------------------------------------------------------------------- /cryptoauthlib/app/cert_def_3_device_csr.h: -------------------------------------------------------------------------------- 1 | #ifndef CERT_DEF_3_DEVICE_CSR_H 2 | #define CERT_DEF_3_DEVICE_CSR_H 3 | 4 | #include "atcacert/atcacert_def.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | extern const atcacert_def_t g_csr_def_3_device; 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif // CERT_DEF_3_DEVICE_CSR_H 17 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/atca_bool.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief Atmel Crypto Auth status codes 5 | * 6 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 7 | * 8 | * \page License 9 | * 10 | * You are permitted to use this software and its derivatives with Microchip 11 | * products. Redistribution and use in source and binary forms, with or without 12 | * modification, is permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 21 | * 3. The name of Microchip may not be used to endorse or promote products derived 22 | * from this software without specific prior written permission. 23 | * 24 | * 4. This software may only be redistributed and used in connection with a 25 | * Microchip integrated circuit. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 28 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 29 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 30 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 31 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 35 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 36 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | #ifndef _ATCA_BOOL_H 41 | #define _ATCA_BOOL_H 42 | 43 | #if defined(_MSC_VER) && (_MSC_VER <= 1700) 44 | // VS2012 and earlier don't support stdbool.h 45 | #ifndef __cplusplus 46 | #define bool unsigned char 47 | #define false 0 48 | #define true 1 49 | #endif 50 | #else 51 | #include 52 | #endif 53 | 54 | #endif -------------------------------------------------------------------------------- /cryptoauthlib/lib/atca_compiler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA is meant to be portable across architectures, even non-Atmel architectures and compiler environments. 4 | * This file is for isolating compiler specific macros. 5 | * 6 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 7 | * 8 | * \page License 9 | * 10 | * You are permitted to use this software and its derivatives with Microchip 11 | * products. Redistribution and use in source and binary forms, with or without 12 | * modification, is permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 21 | * 3. The name of Microchip may not be used to endorse or promote products derived 22 | * from this software without specific prior written permission. 23 | * 24 | * 4. This software may only be redistributed and used in connection with a 25 | * Microchip integrated circuit. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 28 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 29 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 30 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 31 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 35 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 36 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | 41 | #ifndef ATCA_COMPILER_H_ 42 | #define ATCA_COMPILER_H_ 43 | 44 | #if defined(__clang__) 45 | /* Clang/LLVM. ---------------------------------------------- */ 46 | 47 | #elif defined(__ICC) || defined(__INTEL_COMPILER) 48 | /* Intel ICC/ICPC. ------------------------------------------ */ 49 | 50 | #elif defined(__GNUC__) || defined(__GNUG__) 51 | /* GNU GCC/G++. --------------------------------------------- */ 52 | 53 | #elif defined(__HP_cc) || defined(__HP_aCC) 54 | /* Hewlett-Packard C/aC++. ---------------------------------- */ 55 | 56 | #elif defined(__IBMC__) || defined(__IBMCPP__) 57 | /* IBM XL C/C++. -------------------------------------------- */ 58 | 59 | #elif defined(_MSC_VER) 60 | /* Microsoft Visual Studio. --------------------------------- */ 61 | 62 | #elif defined(__PGI) 63 | /* Portland Group PGCC/PGCPP. ------------------------------- */ 64 | 65 | #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) 66 | /* Oracle Solaris Studio. ----------------------------------- */ 67 | 68 | #endif 69 | 70 | #endif /* ATCA_COMPILER_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/atca_device.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief Atmel Crypto Auth device object 5 | * 6 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 7 | * 8 | * \page License 9 | * 10 | * You are permitted to use this software and its derivatives with Microchip 11 | * products. Redistribution and use in source and binary forms, with or without 12 | * modification, is permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 21 | * 3. The name of Microchip may not be used to endorse or promote products derived 22 | * from this software without specific prior written permission. 23 | * 24 | * 4. This software may only be redistributed and used in connection with a 25 | * Microchip integrated circuit. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 28 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 29 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 30 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 31 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 35 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 36 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | #ifndef ATCA_DEVICE_H 41 | #define ATCA_DEVICE_H 42 | 43 | #include "atca_command.h" 44 | #include "atca_iface.h" 45 | /** \defgroup device ATCADevice (atca_) 46 | @{ */ 47 | 48 | #ifdef __cplusplus 49 | extern "C" { 50 | #endif 51 | 52 | typedef struct atca_device * ATCADevice; 53 | ATCADevice newATCADevice(ATCAIfaceCfg *cfg); // constructor 54 | 55 | /* member functions here */ 56 | ATCACommand atGetCommands(ATCADevice dev); 57 | ATCAIface atGetIFace(ATCADevice dev); 58 | 59 | void deleteATCADevice(ATCADevice *dev); // destructor 60 | /*---- end of OATCADevice ----*/ 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | /** @} */ 66 | #endif 67 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/atca_devtypes.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Atmel Crypto Auth 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | 40 | #ifndef ATCA_DEVTYPES_H_ 41 | #define ATCA_DEVTYPES_H_ 42 | 43 | /** \defgroup device ATCADevice (atca_) 44 | @{ */ 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | typedef enum 51 | { 52 | ATSHA204A, 53 | ATECC108A, 54 | ATECC508A, 55 | ATCA_DEV_UNKNOWN = 0x20 56 | } ATCADeviceType; 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | /** @} */ 62 | #endif /* ATCA_DEVTYPES_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/basic/README.md: -------------------------------------------------------------------------------- 1 | basic directory - Purpose 2 | ========================= 3 | The purpose of this directory is to contain the files implementing the APIs for a basic 4 | interface to the core CryptoAuthLib library. 5 | 6 | High-level functions like these make it very convenient to use the library when standard configurations 7 | and defaults are in play. They are the easiest to use when developing examples or trying to 8 | understand the "flow" of an authentication operation without getting overwhelmed by the details. 9 | 10 | This makes simple jobs easy and if you need more sophistication and power, you can employ 11 | the full power of the CryptoAuthLib object model. 12 | 13 | See the Doxygen documentation in cryptoauthlib/docs for details on the API of the Basic commands. 14 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/crypto/README.md: -------------------------------------------------------------------------------- 1 | crypto directory - Purpose 2 | =========================== 3 | This directory contains software implementations of cryptographics functions. The functions at the 4 | base level are wrappers that will point to the final implementations of the software crypto 5 | functions. 6 | 7 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/crypto/atca_crypto_sw.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Common defines for CryptoAuthLib software crypto wrappers. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef ATCA_CRYPTO_SW_H 40 | #define ATCA_CRYPTO_SW_H 41 | 42 | #include "atca_status.h" 43 | 44 | #endif -------------------------------------------------------------------------------- /cryptoauthlib/lib/crypto/atca_crypto_sw_ecdsa.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief API wrapper for software ECDSA verify. Currently unimplemented but could be 4 | * implemented via a 3rd party library such as MicroECC. 5 | * 6 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 7 | * 8 | * \page License 9 | * 10 | * You are permitted to use this software and its derivatives with Microchip 11 | * products. Redistribution and use in source and binary forms, with or without 12 | * modification, is permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 21 | * 3. The name of Microchip may not be used to endorse or promote products derived 22 | * from this software without specific prior written permission. 23 | * 24 | * 4. This software may only be redistributed and used in connection with a 25 | * Microchip integrated circuit. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 28 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 29 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 30 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 31 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 35 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 36 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | 41 | #include "atca_crypto_sw_ecdsa.h" 42 | 43 | /** \brief return software generated ECDSA verification result 44 | * \param[in] msg ptr to message or challenge 45 | * \param[in] signature ptr to the signature to verify 46 | * \param[in] public_key ptr to public key of device which signed the challenge 47 | * return ATCA_STATUS 48 | */ 49 | 50 | int atcac_sw_ecdsa_verify_p256(const uint8_t msg[ATCA_ECC_P256_FIELD_SIZE], 51 | const uint8_t signature[ATCA_ECC_P256_SIGNATURE_SIZE], 52 | const uint8_t public_key[ATCA_ECC_P256_PUBLIC_KEY_SIZE]) 53 | { 54 | return ATCA_UNIMPLEMENTED; 55 | } -------------------------------------------------------------------------------- /cryptoauthlib/lib/crypto/atca_crypto_sw_ecdsa.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | 40 | #ifndef ATCA_CRYPTO_SW_ECDSA_H 41 | #define ATCA_CRYPTO_SW_ECDSA_H 42 | 43 | #include "atca_crypto_sw.h" 44 | #include 45 | #include 46 | 47 | /** \defgroup atcac_ Software crypto methods (atcac_) 48 | * 49 | * \brief 50 | * These methods provide a software implementation of various crypto 51 | * algorithms 52 | * 53 | @{ */ 54 | 55 | #define ATCA_ECC_P256_FIELD_SIZE (256 / 8) 56 | #define ATCA_ECC_P256_PRIVATE_KEY_SIZE (ATCA_ECC_P256_FIELD_SIZE) 57 | #define ATCA_ECC_P256_PUBLIC_KEY_SIZE (ATCA_ECC_P256_FIELD_SIZE * 2) 58 | #define ATCA_ECC_P256_SIGNATURE_SIZE (ATCA_ECC_P256_FIELD_SIZE * 2) 59 | 60 | #ifdef __cplusplus 61 | extern "C" { 62 | #endif 63 | 64 | int atcac_sw_ecdsa_verify_p256(const uint8_t msg[ATCA_ECC_P256_FIELD_SIZE], 65 | const uint8_t signature[ATCA_ECC_P256_SIGNATURE_SIZE], 66 | const uint8_t public_key[ATCA_ECC_P256_PUBLIC_KEY_SIZE]); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | /** @} */ 73 | #endif -------------------------------------------------------------------------------- /cryptoauthlib/lib/crypto/atca_crypto_sw_rand.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief API wrapper for software random 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #include "atca_crypto_sw_rand.h" 40 | 41 | /** \brief return software generated random number 42 | * \param[out] data ptr to space to receive the random number 43 | * \param[in] data_size size of data buffer 44 | * return ATCA_STATUS 45 | */ 46 | 47 | int atcac_sw_random(uint8_t* data, size_t data_size) 48 | { 49 | return ATCA_UNIMPLEMENTED; 50 | } -------------------------------------------------------------------------------- /cryptoauthlib/lib/crypto/atca_crypto_sw_rand.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef ATCA_CRYPTO_SW_RAND_H 40 | #define ATCA_CRYPTO_SW_RAND_H 41 | 42 | #include "atca_crypto_sw.h" 43 | #include 44 | #include 45 | 46 | /** \defgroup atcac_ Software crypto methods (atcac_) 47 | * 48 | * \brief 49 | * These methods provide a software implementation of various crypto 50 | * algorithms 51 | * 52 | @{ */ 53 | #ifdef __cplusplus 54 | extern "C" { 55 | #endif 56 | 57 | int atcac_sw_random(uint8_t* data, size_t data_size); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | /** @} */ 63 | 64 | #endif -------------------------------------------------------------------------------- /cryptoauthlib/lib/crypto/atca_crypto_sw_sha1.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Wrapper API for SHA 1 routines 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | 40 | #include "atca_crypto_sw_sha1.h" 41 | #include "hashes/sha1_routines.h" 42 | 43 | int atcac_sw_sha1_init(atcac_sha1_ctx* ctx) 44 | { 45 | if (sizeof(CL_HashContext) > sizeof(atcac_sha1_ctx)) 46 | return ATCA_ASSERT_FAILURE; // atcac_sha1_ctx isn't large enough for this implementation 47 | CL_hashInit((CL_HashContext*)ctx); 48 | 49 | return ATCA_SUCCESS; 50 | } 51 | 52 | int atcac_sw_sha1_update(atcac_sha1_ctx* ctx, const uint8_t* data, size_t data_size) 53 | { 54 | CL_hashUpdate((CL_HashContext*)ctx, data, (int)data_size); 55 | 56 | return ATCA_SUCCESS; 57 | } 58 | 59 | int atcac_sw_sha1_finish(atcac_sha1_ctx* ctx, uint8_t digest[ATCA_SHA1_DIGEST_SIZE]) 60 | { 61 | CL_hashFinal((CL_HashContext*)ctx, digest); 62 | 63 | return ATCA_SUCCESS; 64 | } 65 | 66 | int atcac_sw_sha1(const uint8_t* data, size_t data_size, uint8_t digest[ATCA_SHA1_DIGEST_SIZE]) 67 | { 68 | int ret; 69 | atcac_sha1_ctx ctx; 70 | 71 | ret = atcac_sw_sha1_init(&ctx); 72 | if (ret != ATCA_SUCCESS) 73 | return ret; 74 | 75 | ret = atcac_sw_sha1_update(&ctx, data, data_size); 76 | if (ret != ATCA_SUCCESS) 77 | return ret; 78 | 79 | ret = atcac_sw_sha1_finish(&ctx, digest); 80 | if (ret != ATCA_SUCCESS) 81 | return ret; 82 | 83 | return ATCA_SUCCESS; 84 | } -------------------------------------------------------------------------------- /cryptoauthlib/lib/crypto/atca_crypto_sw_sha1.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Wrapper API for SHA 1 routines 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef ATCA_CRYPTO_SW_SHA1_H 40 | #define ATCA_CRYPTO_SW_SHA1_H 41 | 42 | #include "atca_crypto_sw.h" 43 | #include 44 | #include 45 | 46 | /** \defgroup atcac_ Software crypto methods (atcac_) 47 | * 48 | * \brief 49 | * These methods provide a software implementation of various crypto 50 | * algorithms 51 | * 52 | @{ */ 53 | 54 | #define ATCA_SHA1_DIGEST_SIZE (20) 55 | 56 | typedef struct 57 | { 58 | uint32_t pad[32]; //!< Filler value to make sure the actual implementation has enough room to store its context. uint32_t is used to remove some alignment warnings. 59 | } atcac_sha1_ctx; 60 | 61 | #ifdef __cplusplus 62 | extern "C" { 63 | #endif 64 | 65 | int atcac_sw_sha1_init(atcac_sha1_ctx* ctx); 66 | int atcac_sw_sha1_update(atcac_sha1_ctx* ctx, const uint8_t* data, size_t data_size); 67 | int atcac_sw_sha1_finish(atcac_sha1_ctx * ctx, uint8_t digest[ATCA_SHA1_DIGEST_SIZE]); 68 | int atcac_sw_sha1(const uint8_t * data, size_t data_size, uint8_t digest[ATCA_SHA1_DIGEST_SIZE]); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | /** @} */ 75 | #endif -------------------------------------------------------------------------------- /cryptoauthlib/lib/crypto/atca_crypto_sw_sha2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Wrapper API for software SHA 256 routines 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef ATCA_CRYPTO_SW_SHA2_H 40 | #define ATCA_CRYPTO_SW_SHA2_H 41 | 42 | #include "atca_crypto_sw.h" 43 | #include 44 | #include 45 | 46 | /** \defgroup atcac_ Software crypto methods (atcac_) 47 | * 48 | * \brief 49 | * These methods provide a software implementation of various crypto 50 | * algorithms 51 | * 52 | @{ */ 53 | 54 | #define ATCA_SHA2_256_DIGEST_SIZE (32) 55 | 56 | typedef struct 57 | { 58 | uint32_t pad[48]; //!< Filler value to make sure the actual implementation has enough room to store its context. uint32_t is used to remove some alignment warnings. 59 | } atcac_sha2_256_ctx; 60 | 61 | #ifdef __cplusplus 62 | extern "C" { 63 | #endif 64 | 65 | int atcac_sw_sha2_256_init(atcac_sha2_256_ctx* ctx); 66 | int atcac_sw_sha2_256_update(atcac_sha2_256_ctx* ctx, const uint8_t* data, size_t data_size); 67 | int atcac_sw_sha2_256_finish(atcac_sha2_256_ctx * ctx, uint8_t digest[ATCA_SHA2_256_DIGEST_SIZE]); 68 | int atcac_sw_sha2_256(const uint8_t * data, size_t data_size, uint8_t digest[ATCA_SHA2_256_DIGEST_SIZE]); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | /** @} */ 75 | #endif -------------------------------------------------------------------------------- /cryptoauthlib/lib/crypto/hashes/sha1_routines.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Software implementation of the SHA1 algorithm. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef __SHA1_ROUTINES_DOT_H__ 40 | #define __SHA1_ROUTINES_DOT_H__ 41 | 42 | #include 43 | #include 44 | #include 45 | 46 | #ifdef WIN32 47 | #include 48 | #include 49 | #endif 50 | 51 | #include 52 | 53 | 54 | #ifndef U8 55 | #define U8 uint8_t 56 | #endif 57 | 58 | #ifndef U16 59 | #define U16 uint16_t 60 | #endif 61 | 62 | #ifndef U32 63 | #define U32 uint32_t 64 | #endif 65 | 66 | 67 | #ifndef memcpy_P 68 | #define memcpy_P memmove 69 | #endif 70 | 71 | #ifndef strcpy_P 72 | #define strcpy_P strcpy 73 | #endif 74 | 75 | #ifndef _WDRESET 76 | #define _WDRESET() 77 | #define _NOP() 78 | #endif 79 | 80 | typedef struct 81 | { 82 | U32 h[20 / 4]; // Ensure it's word aligned 83 | U32 buf[64 / 4]; // Ensure it's word aligned 84 | U32 byteCount; 85 | U32 byteCountHi; 86 | } CL_HashContext; 87 | 88 | #define leftRotate(x, n) (x) = (((x) << (n)) | ((x) >> (32 - (n)))) 89 | 90 | void shaEngine(U32 *buf, U32 *h); 91 | void CL_hashInit(CL_HashContext *ctx); 92 | void CL_hashUpdate(CL_HashContext *ctx, const U8 *src, int nbytes); 93 | void CL_hashFinal(CL_HashContext *ctx, U8 *dest); 94 | void CL_hash(U8 *msg, int msgBytes, U8 *dest); 95 | 96 | #endif // __SHA1_ROUTINES_DOT_H__ 97 | 98 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/crypto/hashes/sha2_routines.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Software implementation of the SHA256 algorithm. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef SHA2_ROUTINES_H 40 | #define SHA2_ROUTINES_H 41 | 42 | #include 43 | 44 | #define SHA256_DIGEST_SIZE (32) 45 | #define SHA256_BLOCK_SIZE (64) 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | typedef struct 52 | { 53 | uint32_t total_msg_size; //!< Total number of message bytes processed 54 | uint32_t block_size; //!< Number of bytes in current block 55 | uint8_t block[SHA256_BLOCK_SIZE * 2]; //!< Unprocessed message storage 56 | uint32_t hash[8]; //!< Hash state 57 | } sw_sha256_ctx; 58 | 59 | void sw_sha256_init(sw_sha256_ctx* ctx); 60 | 61 | void sw_sha256_update(sw_sha256_ctx* ctx, const uint8_t* message, uint32_t len); 62 | 63 | void sw_sha256_final(sw_sha256_ctx * ctx, uint8_t digest[SHA256_DIGEST_SIZE]); 64 | 65 | void sw_sha256(const uint8_t * message, unsigned int len, uint8_t digest[SHA256_DIGEST_SIZE]); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif // SHA2_ROUTINES_H 72 | 73 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/cryptoauthlib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Single aggregation point for all CryptoAuthLib header files 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef _ATCA_LIB_H 40 | #define _ATCA_LIB_H 41 | 42 | #include 43 | #include 44 | 45 | #include "hal/atca_hal.h" 46 | #include "atca_status.h" 47 | #include "atca_device.h" 48 | #include "atca_command.h" 49 | #include "atca_cfgs.h" 50 | #include "basic/atca_basic.h" 51 | #include "basic/atca_helpers.h" 52 | 53 | #ifdef ATCAPRINTF 54 | #include 55 | //#define BREAK(status, message) {printf(__FUNCTION__": "message" -- Status: %02X\r\n", status); break;} 56 | #define BREAK(status, message) { printf(": "message " -- Status: %02X\r\n", status); break; } 57 | #define RETURN(status, message) { printf(": "message " -- Status: %02X\r\n", status); return status; } 58 | #define PRINTSTAT(status, message) { printf(": "message " -- Status: %02X\r\n", status); } 59 | #define PRINT(message) { printf(": "message "\r\n"); break; } 60 | #define DBGOUT(message) { printf(": "message "\r\n"); break; } 61 | #else 62 | #define BREAK(status, message) { break; } 63 | #define RETURN(status, message) { return status; } 64 | #define PRINT(message) { break; } 65 | #define DBGOUT(message) { break; } 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/atca_start_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | this is a placeholder include used to satisfy the include 3 | 4 | when used with Atmel START, this file will be overwritten 5 | with the user configuration generated by Atmel START 6 | */ 7 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/atca_start_iface.h: -------------------------------------------------------------------------------- 1 | /* 2 | this is a placeholder include used to satisfy the include 3 | 4 | when used with Atmel START, this file will be overwritten 5 | with the user configuration generated by Atmel START 6 | */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_at90usb1287_i2c_asf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for AT90USB1287 I2C over ASF drivers. 4 | * 5 | * Prerequisite: add I2C Master Polled support to application in Atmel Studio 6 | * 7 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 8 | * 9 | * \page License 10 | * 11 | * You are permitted to use this software and its derivatives with Microchip 12 | * products. Redistribution and use in source and binary forms, with or without 13 | * modification, is permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Microchip may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with a 26 | * Microchip integrated circuit. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #ifndef HAL_AT90USB1287_I2C_ASF_H_ 42 | #define HAL_AT90USB1287_I2C_ASF_H_ 43 | 44 | #include 45 | #include "twi_megarf.h" 46 | 47 | /** \defgroup hal_ Hardware abstraction layer (hal_) 48 | * 49 | * \brief 50 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 51 | * using I2C driver of ASF. 52 | * 53 | @{ */ 54 | 55 | 56 | #define MAX_I2C_BUSES 1 // AT90USB1287 has only 1 PORT that can be configured as I2C 57 | 58 | /** \brief this is the hal_data for ATCA HAL created using ASF 59 | */ 60 | typedef struct atcaI2Cmaster 61 | { 62 | /*twi_master_t*/ int* i2c_master_instance; 63 | int ref_ct; 64 | // for conveniences during interface release phase 65 | int bus_index; 66 | } ATCAI2CMaster_t; 67 | 68 | void change_i2c_speed(ATCAIface iface, uint32_t speed); 69 | 70 | /** @} */ 71 | #endif /* HAL_AT90USB1287_I2C_ASF_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_at90usb1287_timer_asf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for AT90USB1287 timer/delay over ASF drivers. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #include 40 | #include 41 | #include "atca_hal.h" 42 | 43 | /** \defgroup hal_ Hardware abstraction layer (hal_) 44 | * 45 | * \brief 46 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 47 | * 48 | @{ */ 49 | 50 | void atca_delay_us(uint32_t delay) 51 | { 52 | // use ASF supplied delay 53 | delay_us(delay); 54 | } 55 | 56 | /** \brief This function delays for a number of tens of microseconds. 57 | * 58 | * \param[in] delay number of 0.01 milliseconds to delay 59 | */ 60 | void atca_delay_10us(uint32_t delay) 61 | { 62 | // use ASF supplied delay 63 | delay_us(delay * 10); 64 | 65 | } 66 | 67 | /** \brief This function delays for a number of milliseconds. 68 | * 69 | * You can override this function if you like to do 70 | * something else in your system while delaying. 71 | * \param[in] delay number of milliseconds to delay 72 | */ 73 | 74 | /* ASF already has delay_ms - see delay.h */ 75 | void atca_delay_ms(uint32_t delay) 76 | { 77 | // use ASF supplied delay 78 | delay_ms(delay); 79 | } 80 | 81 | /** @} */ 82 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_i2c_bitbang.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for I2C bit banging. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef HAL_I2C_BITBANG_H_ 40 | #define HAL_I2C_BITBANG_H_ 41 | 42 | 43 | 44 | 45 | 46 | #if BOARD == AT88CK9000 47 | # include "i2c_bitbang_at88ck9000.h" 48 | #endif 49 | 50 | #if (SAMD21 == 1) 51 | #include "i2c_bitbang_samd21.h" 52 | #endif 53 | 54 | 55 | /** 56 | * \defgroup hal_ Hardware abstraction layer (hal_) 57 | * 58 | * \brief These methods define the hardware abstraction layer for 59 | * communicating with a CryptoAuth device using I2C bit banging. 60 | @{ */ 61 | 62 | /** 63 | * \brief This enumeration lists flags for I2C read or write addressing. 64 | */ 65 | enum i2c_read_write_flag 66 | { 67 | I2C_WRITE = (uint8_t)0x00, //!< write command flag 68 | I2C_READ = (uint8_t)0x01 //!< read command flag 69 | }; 70 | 71 | /** 72 | * \brief This is the hal_data for ATCA HAL. 73 | */ 74 | typedef struct atcaI2Cmaster 75 | { 76 | uint32_t pin_sda; 77 | uint32_t pin_scl; 78 | int ref_ct; 79 | //! for conveniences during interface release phase 80 | int bus_index; 81 | } ATCAI2CMaster_t; 82 | 83 | /** @} */ 84 | 85 | #endif /* HAL_AT88CK900X_I2C_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_linux_i2c_userspace.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for Linux using kit protocol over a USB CDC device. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef HAL_LINUX_I2C_USERSPACE_H_ 40 | #define HAL_LINUX_I2C_USERSPACE_H_ 41 | 42 | /** \defgroup hal_ Hardware abstraction layer (hal_) 43 | * 44 | * \brief 45 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 46 | * 47 | @{ */ 48 | 49 | #define MAX_I2C_BUSES 2 // Raspberry Pi has 2 TWI 50 | 51 | // A structure to hold I2C information 52 | typedef struct atcaI2Cmaster 53 | { 54 | char i2c_file[16]; 55 | int ref_ct; 56 | // for conveniences during interface release phase 57 | int bus_index; 58 | } ATCAI2CMaster_t; 59 | 60 | /** @} */ 61 | 62 | #endif /* HAL_LINUX_I2C_H_ */ 63 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_linux_kit_cdc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for Linux using kit protocol over a USB CDC device. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef HAL_LINUX_KIT_CDC_H_ 40 | #define HAL_LINUX_KIT_CDC_H_ 41 | 42 | /** \defgroup hal_ Hardware abstraction layer (hal_) 43 | * 44 | * \brief 45 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 46 | * 47 | @{ */ 48 | 49 | // Kit USB defines 50 | #define CDC_DEVICES_MAX 10 //! Maximum number of supported Kit USB devices 51 | #define CDC_BUFFER_MAX 1024 //! Maximum number of bytes read per port read 52 | 53 | 54 | // Each device that is found will have a read handle and a write handle 55 | typedef int HANDLE; 56 | #define INVALID_HANDLE_VALUE ((int)(-1)) 57 | typedef struct cdc_device 58 | { 59 | HANDLE read_handle; //! The kit USB read file handle 60 | HANDLE write_handle; //! The kit USB write file handle 61 | } cdc_device_t; 62 | 63 | 64 | // A structure to hold CDC information 65 | typedef struct atcacdc 66 | { 67 | cdc_device_t kits[CDC_DEVICES_MAX]; 68 | int8_t num_kits_found; 69 | } atcacdc_t; 70 | 71 | /** @} */ 72 | 73 | #endif /* HAL_LINUX_KIT_CDC_H_ */ 74 | 75 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_linux_kit_hid.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for Linux using kit protocol over a USB HID device. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef HAL_LINUX_KIT_HID_H_ 40 | #define HAL_LINUX_KIT_HID_H_ 41 | 42 | /** \defgroup hal_ Hardware abstraction layer (hal_) 43 | * 44 | * \brief 45 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 46 | * 47 | @{ */ 48 | 49 | // Kit USB defines 50 | #define HID_DEVICES_MAX 10 //! Maximum number of supported Kit USB devices 51 | #define HID_PACKET_MAX 512 //! Maximum number of bytes for a HID send/receive packet (typically 64) 52 | 53 | // Each device that is found will have a read handle and a write handle 54 | typedef struct hid_device 55 | { 56 | FILE *read_handle; //! The kit USB read file handle 57 | FILE *write_handle; //! The kit USB write file handle 58 | } hid_device_t; 59 | 60 | 61 | // A structure to hold HID information 62 | typedef struct atcahid 63 | { 64 | hid_device_t kits[HID_DEVICES_MAX]; 65 | int8_t num_kits_found; 66 | } atcahid_t; 67 | 68 | /** @} */ 69 | #endif /* HAL_LINUX_KIT_HID_H_ */ 70 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_linux_timer.c: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \brief Timer Utility Functions 3 | * 4 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 5 | * 6 | * \page License 7 | * 8 | * You are permitted to use this software and its derivatives with Microchip 9 | * products. Redistribution and use in source and binary forms, with or without 10 | * modification, is permitted provided that the following conditions are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 19 | * 3. The name of Microchip may not be used to endorse or promote products derived 20 | * from this software without specific prior written permission. 21 | * 22 | * 4. This software may only be redistributed and used in connection with a 23 | * Microchip integrated circuit. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 28 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 29 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #include 39 | #include 40 | #include "atca_hal.h" 41 | 42 | /** \defgroup hal_ Hardware abstraction layer (hal_) 43 | * 44 | * \brief 45 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 46 | * 47 | @{ */ 48 | 49 | void atca_delay_us(uint32_t delay) 50 | { 51 | usleep(delay); 52 | } 53 | 54 | /** \brief This function delays for a number of tens of microseconds. 55 | * 56 | * \param[in] delay number of 0.01 milliseconds to delay 57 | */ 58 | void atca_delay_10us(uint32_t delay) 59 | { 60 | atca_delay_us(delay * 10); 61 | } 62 | 63 | 64 | /** \brief This function delays for a number of milliseconds. 65 | * 66 | * You can override this function if you like to do 67 | * something else in your system while delaying. 68 | * \param[in] delay number of milliseconds to delay 69 | */ 70 | 71 | /* ASF already has delay_ms - see delay.h */ 72 | void atca_delay_ms(uint32_t delay) 73 | { 74 | atca_delay_us(delay * 1000); 75 | } 76 | 77 | /** @} */ 78 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_pic32mx695f512h_i2c.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for PIC32MX695F512H I2C over xxx drivers. 4 | * 5 | * This code is structured in two parts. Part 1 is the connection of the ATCA HAL API to the physical I2C 6 | * implementation. Part 2 is the xxx I2C primitives to set up the interface. 7 | * 8 | * Prerequisite: 9 | * 10 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 11 | * 12 | * \page License 13 | * 14 | * You are permitted to use this software and its derivatives with Microchip 15 | * products. Redistribution and use in source and binary forms, with or without 16 | * modification, is permitted provided that the following conditions are met: 17 | * 18 | * 1. Redistributions of source code must retain the above copyright notice, 19 | * this list of conditions and the following disclaimer. 20 | * 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 25 | * 3. The name of Microchip may not be used to endorse or promote products derived 26 | * from this software without specific prior written permission. 27 | * 28 | * 4. This software may only be redistributed and used in connection with a 29 | * Microchip integrated circuit. 30 | * 31 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 32 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 33 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 34 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 35 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 40 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 | * POSSIBILITY OF SUCH DAMAGE. 42 | */ 43 | 44 | #ifndef HAL_PIC32MX695F512H_I2C_ASF_H_ 45 | #define HAL_PIC32MX695F512H_I2C_ASF_H_ 46 | 47 | 48 | /** 49 | * \defgroup hal_ Hardware abstraction layer (hal_) 50 | * 51 | * \brief 52 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 53 | * using I2C driver of ASF. 54 | * 55 | @{ */ 56 | 57 | // Clock Constants 58 | #define GetSystemClock() (80000000ul) 59 | #define GetPeripheralClock() (GetSystemClock() / (1 << OSCCONbits.PBDIV)) 60 | #define GetInstructionClock() (GetSystemClock()) 61 | 62 | #define MAX_I2C_BUSES 4 // PIC32MX695F512H has 4 TWI 63 | 64 | /** 65 | * \brief this is the hal_data for ATCA HAL 66 | */ 67 | typedef struct atcaI2Cmaster 68 | { 69 | I2C_MODULE id; 70 | int ref_ct; 71 | // for conveniences during interface release phase 72 | int bus_index; 73 | } ATCAI2CMaster_t; 74 | 75 | void i2c_write(I2C_MODULE i2c_id, uint8_t address, uint8_t *data, int len); 76 | void i2c_read(I2C_MODULE i2c_id, uint8_t address, uint8_t *data, uint16_t len); 77 | 78 | void change_i2c_speed(ATCAIface iface, uint32_t speed); 79 | 80 | /** @} */ 81 | 82 | #endif /* HAL_PIC32MX695F512H_I2C_ASF_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_sam4s_i2c_asf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for SAM4S I2C over ASF drivers. 4 | * 5 | * Prerequisite: add "TWI - Two-Wire Interface (Common API) (service)" module to application in Atmel Studio 6 | * 7 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 8 | * 9 | * \page License 10 | * 11 | * You are permitted to use this software and its derivatives with Microchip 12 | * products. Redistribution and use in source and binary forms, with or without 13 | * modification, is permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Microchip may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with a 26 | * Microchip integrated circuit. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #ifndef HAL_SAM4S_I2C_ASF_H_ 42 | #define HAL_SAM4S_I2C_ASF_H_ 43 | 44 | #include 45 | 46 | 47 | /** 48 | * \defgroup hal_ Hardware abstraction layer (hal_) 49 | * 50 | * \brief 51 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 52 | * using I2C driver of ASF. 53 | * 54 | @{ */ 55 | 56 | #define MAX_I2C_BUSES 2 // SAM4S has 2 TWI 57 | 58 | /** 59 | * \brief this is the hal_data for ATCA HAL 60 | */ 61 | typedef struct atcaI2Cmaster 62 | { 63 | uint32_t twi_id; 64 | Twi * twi_master_instance; 65 | int ref_ct; 66 | // for conveniences during interface release phase 67 | int bus_index; 68 | } ATCAI2CMaster_t; 69 | 70 | void change_i2c_speed(ATCAIface iface, uint32_t speed); 71 | 72 | /** @} */ 73 | 74 | #endif /* HAL_SAM4S_I2C_ASF_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_sam4s_timer_asf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for SAM4S I2C over ASF drivers. 4 | * 5 | * Prerequisite: add "Delay routines (service)" module to application in Atmel Studio 6 | * 7 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 8 | * 9 | * \page License 10 | * 11 | * You are permitted to use this software and its derivatives with Microchip 12 | * products. Redistribution and use in source and binary forms, with or without 13 | * modification, is permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Microchip may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with a 26 | * Microchip integrated circuit. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #include 42 | #include 43 | #include "atca_hal.h" 44 | 45 | 46 | /* ASF already have delay_us and delay_ms - see delay.h */ 47 | 48 | /** 49 | * \defgroup hal_ Hardware abstraction layer (hal_) 50 | * 51 | * \brief 52 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 53 | * 54 | @{ */ 55 | 56 | /** 57 | * \brief This function delays for a number of microseconds. 58 | * 59 | * \param[in] delay number of 0.001 milliseconds to delay 60 | */ 61 | void atca_delay_us(uint32_t delay) 62 | { 63 | // use ASF supplied delay 64 | delay_us(delay); 65 | } 66 | 67 | /** 68 | * \brief This function delays for a number of tens of microseconds. 69 | * 70 | * \param[in] delay number of 0.01 milliseconds to delay 71 | */ 72 | void atca_delay_10us(uint32_t delay) 73 | { 74 | // use ASF supplied delay 75 | delay_us(delay * 10); 76 | 77 | } 78 | 79 | /** 80 | * \brief This function delays for a number of milliseconds. 81 | * 82 | * You can override this function if you like to do 83 | * something else in your system while delaying. 84 | * 85 | * \param[in] delay number of milliseconds to delay 86 | */ 87 | void atca_delay_ms(uint32_t delay) 88 | { 89 | // use ASF supplied delay 90 | delay_ms(delay); 91 | } 92 | 93 | /** @} */ 94 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_samb11_i2c_asf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for SAMB11 I2C over ASF drivers. 4 | * 5 | * Prerequisite: add SERCOM I2C Master Polled support to application in Atmel Studio 6 | * 7 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 8 | * 9 | * \page License 10 | * 11 | * You are permitted to use this software and its derivatives with Microchip 12 | * products. Redistribution and use in source and binary forms, with or without 13 | * modification, is permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Microchip may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with a 26 | * Microchip integrated circuit. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #ifndef HAL_SAMB11_I2C_ASF_H_ 42 | #define HAL_SAMB11_I2C_ASF_H_ 43 | 44 | #include 45 | 46 | /** \defgroup hal_ Hardware abstraction layer (hal_) 47 | * 48 | * \brief 49 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 50 | * using I2C driver of ASF. 51 | * 52 | @{ */ 53 | 54 | #define MAX_I2C_BUSES 2 // SAMB11 has up to 2 I2C address that can be configured as I2C 55 | 56 | /** \brief this is the hal_data for ATCA HAL for ASF 57 | */ 58 | typedef struct atcaI2Cmaster 59 | { 60 | struct i2c_master_module i2c_master_instance; 61 | int ref_ct; 62 | // for conveniences during interface release phase 63 | int bus_index; 64 | } ATCAI2CMaster_t; 65 | 66 | /** @} */ 67 | #endif /* HAL_SAMB11_I2C_ASF_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_samb11_timer_asf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for SAMB11 timer/delay over ASF drivers. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #include 40 | #include 41 | #include "atca_hal.h" 42 | 43 | /** \defgroup hal_ Hardware abstraction layer (hal_) 44 | * 45 | * \brief 46 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 47 | * 48 | @{ */ 49 | 50 | void atca_delay_us(uint32_t delay) 51 | { 52 | // use ASF supplied delay 53 | delay_us(delay); 54 | } 55 | 56 | /** \brief This function delays for a number of tens of microseconds. 57 | * 58 | * \param[in] delay number of 0.01 milliseconds to delay 59 | */ 60 | void atca_delay_10us(uint32_t delay) 61 | { 62 | // use ASF supplied delay 63 | delay_us(delay * 10); 64 | 65 | } 66 | 67 | /** \brief This function delays for a number of milliseconds. 68 | * 69 | * You can override this function if you like to do 70 | * something else in your system while delaying. 71 | * \param[in] delay number of milliseconds to delay 72 | */ 73 | 74 | /* ASF already has delay_ms - see delay.h */ 75 | void atca_delay_ms(uint32_t delay) 76 | { 77 | // use ASF supplied delay 78 | delay_ms(delay); 79 | } 80 | 81 | /** @} */ 82 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_samd21_i2c_asf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for SAMD21 I2C over ASF drivers. 4 | * 5 | * Prerequisite: add SERCOM I2C Master Polled support to application in Atmel Studio 6 | * 7 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 8 | * 9 | * \page License 10 | * 11 | * You are permitted to use this software and its derivatives with Microchip 12 | * products. Redistribution and use in source and binary forms, with or without 13 | * modification, is permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Microchip may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with a 26 | * Microchip integrated circuit. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #ifndef HAL_SAMD21_I2C_ASF_H_ 42 | #define HAL_SAMD21_I2C_ASF_H_ 43 | 44 | #include 45 | 46 | /** \defgroup hal_ Hardware abstraction layer (hal_) 47 | * 48 | * \brief 49 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 50 | * using I2C driver of ASF. 51 | * 52 | @{ */ 53 | 54 | 55 | #define MAX_I2C_BUSES 6 // SAMD21 has up to 6 SERCOMS that can be configured as I2C 56 | 57 | /** \brief this is the hal_data for ATCA HAL for ASF SERCOM 58 | */ 59 | typedef struct atcaI2Cmaster 60 | { 61 | struct i2c_master_module i2c_master_instance; 62 | int ref_ct; 63 | // for conveniences during interface release phase 64 | int bus_index; 65 | } ATCAI2CMaster_t; 66 | 67 | void change_i2c_speed(ATCAIface iface, uint32_t speed); 68 | 69 | /** @} */ 70 | #endif /* HAL_SAMD21_I2C_ASF_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_samd21_i2c_start.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for SAMD21 I2C over START drivers. 4 | * 5 | * Prerequisite: add SERCOM I2C Master Polled support to application in Atmel Studio 6 | * 7 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 8 | * 9 | * \page License 10 | * 11 | * You are permitted to use this software and its derivatives with Microchip 12 | * products. Redistribution and use in source and binary forms, with or without 13 | * modification, is permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Microchip may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with a 26 | * Microchip integrated circuit. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #ifndef HAL_SAMD21_I2C_START_H_ 42 | #define HAL_SAMD21_I2C_START_H_ 43 | 44 | #include "atmel_start.h" 45 | #include 46 | 47 | /** \defgroup hal_ Hardware abstraction layer (hal_) 48 | * 49 | * \brief 50 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 51 | * 52 | @{ */ 53 | 54 | 55 | #define MAX_I2C_BUSES 6 // SAMD21 has up to 6 SERCOMS that can be configured as I2C 56 | 57 | /** \brief this is the hal_data for ATCA HAL for Atmel START SERCOM 58 | */ 59 | typedef struct atcaI2Cmaster 60 | { 61 | struct i2c_m_sync_desc i2c_master_instance; 62 | int ref_ct; 63 | // for conveniences during interface release phase 64 | int bus_index; 65 | } ATCAI2CMaster_t; 66 | 67 | void change_i2c_speed(ATCAIface iface, uint32_t speed); 68 | 69 | /** @} */ 70 | 71 | #endif /* HAL_SAMD21_I2C_START_H_ */ 72 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_samd21_timer_asf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for SAMD21 timer/delay over ASF drivers. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #include 40 | #include 41 | #include "atca_hal.h" 42 | 43 | /** \defgroup hal_ Hardware abstraction layer (hal_) 44 | * 45 | * \brief 46 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 47 | * 48 | @{ */ 49 | 50 | void atca_delay_us(uint32_t delay) 51 | { 52 | // use ASF supplied delay 53 | delay_us(delay); 54 | } 55 | 56 | /** \brief This function delays for a number of tens of microseconds. 57 | * 58 | * \param[in] delay number of 0.01 milliseconds to delay 59 | */ 60 | void atca_delay_10us(uint32_t delay) 61 | { 62 | // use ASF supplied delay 63 | delay_us(delay * 10); 64 | 65 | } 66 | 67 | /** \brief This function delays for a number of milliseconds. 68 | * 69 | * You can override this function if you like to do 70 | * something else in your system while delaying. 71 | * \param[in] delay number of milliseconds to delay 72 | */ 73 | 74 | /* ASF already has delay_ms - see delay.h */ 75 | void atca_delay_ms(uint32_t delay) 76 | { 77 | // use ASF supplied delay 78 | delay_ms(delay); 79 | } 80 | 81 | /** @} */ 82 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_samd21_timer_start.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for SAMD21 I2C over START drivers. 4 | * 5 | * Prerequisite: add SERCOM I2C Master Polled support to application in Atmel Studio 6 | * 7 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 8 | * 9 | * \page License 10 | * 11 | * You are permitted to use this software and its derivatives with Microchip 12 | * products. Redistribution and use in source and binary forms, with or without 13 | * modification, is permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Microchip may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with a 26 | * Microchip integrated circuit. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #include 42 | #include "atca_hal.h" 43 | 44 | /** \defgroup hal_ Hardware abstraction layer (hal_) 45 | * 46 | * \brief 47 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 48 | * 49 | @{ */ 50 | 51 | 52 | /** \brief This function delays for a number of microseconds. 53 | * 54 | * \param[in] delay number of 1 microseconds to delay 55 | */ 56 | 57 | void atca_delay_us(uint32_t delay) 58 | { 59 | // use START supplied delay 60 | delay_us(delay); 61 | } 62 | 63 | /** \brief This function delays for a number of tens of microseconds. 64 | * 65 | * \param[in] delay number of 0.01 milliseconds to delay 66 | */ 67 | 68 | void atca_delay_10us(uint32_t delay) 69 | { 70 | // use START supplied delay 71 | delay_us(delay * 10); 72 | } 73 | 74 | /** \brief This function delays for a number of milliseconds. 75 | * 76 | * You can override this function if you like to do 77 | * something else in your system while delaying. 78 | * \param[in] delay number of milliseconds to delay 79 | */ 80 | 81 | void atca_delay_ms(uint32_t delay) 82 | { 83 | // use START supplied delay 84 | delay_ms(delay); 85 | } 86 | 87 | /** @} */ 88 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_samg55_i2c_asf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for SAM4S I2C over ASF drivers. 4 | * 5 | * Prerequisite: add "TWI - Two-Wire Interface (Common API) (service)" module to application in Atmel Studio 6 | * 7 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 8 | * 9 | * \page License 10 | * 11 | * You are permitted to use this software and its derivatives with Microchip 12 | * products. Redistribution and use in source and binary forms, with or without 13 | * modification, is permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Microchip may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with a 26 | * Microchip integrated circuit. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #ifndef HAL_SAMG55_I2C_ASF_H_ 42 | #define HAL_SAMG55_I2C_ASF_H_ 43 | 44 | #include 45 | 46 | 47 | /** 48 | * \defgroup hal_ Hardware abstraction layer (hal_) 49 | * 50 | * \brief 51 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 52 | * using I2C driver of ASF. 53 | * 54 | @{ */ 55 | 56 | #define MAX_I2C_BUSES 2 // SAM4S has 2 TWI 57 | 58 | /** 59 | * \brief this is the hal_data for ATCA HAL 60 | */ 61 | typedef struct atcaI2Cmaster 62 | { 63 | uint32_t twi_id; 64 | Twi * twi_master_instance; 65 | int ref_ct; 66 | // for conveniences during interface release phase 67 | int bus_index; 68 | } ATCAI2CMaster_t; 69 | 70 | void change_i2c_speed(ATCAIface iface, uint32_t speed); 71 | 72 | /** @} */ 73 | 74 | #endif /* HAL_SAMG55_I2C_ASF_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_samg55_timer_asf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief 4 | * 5 | * Prerequisite: add "Delay routines (service)" module to application in Atmel Studio 6 | * 7 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 8 | * 9 | * \page License 10 | * 11 | * You are permitted to use this software and its derivatives with Microchip 12 | * products. Redistribution and use in source and binary forms, with or without 13 | * modification, is permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Microchip may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with a 26 | * Microchip integrated circuit. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #include 42 | #include 43 | #include "atca_hal.h" 44 | 45 | 46 | /* ASF already have delay_us and delay_ms - see delay.h */ 47 | 48 | /** 49 | * \defgroup hal_ Hardware abstraction layer (hal_) 50 | * 51 | * \brief 52 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 53 | * 54 | @{ */ 55 | 56 | /** 57 | * \brief This function delays for a number of microseconds. 58 | * 59 | * \param[in] delay number of 0.001 milliseconds to delay 60 | */ 61 | void atca_delay_us(uint32_t delay) 62 | { 63 | // use ASF supplied delay 64 | delay_us(delay); 65 | } 66 | 67 | /** 68 | * \brief This function delays for a number of tens of microseconds. 69 | * 70 | * \param[in] delay number of 0.01 milliseconds to delay 71 | */ 72 | void atca_delay_10us(uint32_t delay) 73 | { 74 | // use ASF supplied delay 75 | delay_us(delay * 10); 76 | 77 | } 78 | 79 | /** 80 | * \brief This function delays for a number of milliseconds. 81 | * 82 | * You can override this function if you like to do 83 | * something else in your system while delaying. 84 | * 85 | * \param[in] delay number of milliseconds to delay 86 | */ 87 | void atca_delay_ms(uint32_t delay) 88 | { 89 | // use ASF supplied delay 90 | delay_ms(delay); 91 | } 92 | 93 | /** @} */ 94 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_samv71_i2c_asf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for SAMV71 I2C over ASF drivers. 4 | * 5 | * Prerequisite: add SERCOM I2C Master Polled support to application in Atmel Studio 6 | * 7 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 8 | * 9 | * \page License 10 | * 11 | * You are permitted to use this software and its derivatives with Microchip 12 | * products. Redistribution and use in source and binary forms, with or without 13 | * modification, is permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Microchip may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with a 26 | * Microchip integrated circuit. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #ifndef HAL_SAMV71_I2C_ASF_H_ 42 | #define HAL_SAMV71_I2C_ASF_H_ 43 | 44 | #include 45 | 46 | /** \defgroup hal_ Hardware abstraction layer (hal_) 47 | * 48 | * \brief 49 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 50 | * using I2C driver of ASF. 51 | * 52 | @{ */ 53 | 54 | 55 | #define MAX_I2C_BUSES 3 56 | 57 | /** \brief this is the hal_data for ATCA HAL for ASF SERCOM 58 | */ 59 | typedef struct atcaI2Cmaster 60 | { 61 | int ref_ct; 62 | // for conveniences during interface release phase 63 | int bus_index; 64 | uint32_t twi_module; 65 | } ATCAI2CMaster_t; 66 | 67 | ATCA_STATUS change_i2c_speed(ATCAIface iface, uint32_t speed); 68 | 69 | /** @} */ 70 | #endif /* HAL_SAMD21_I2C_ASF_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_samv71_timer_asf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for SAMD21 timer/delay over ASF drivers. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #include 40 | #include 41 | #include "atca_hal.h" 42 | 43 | /** \defgroup hal_ Hardware abstraction layer (hal_) 44 | * 45 | * \brief 46 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 47 | * 48 | @{ */ 49 | 50 | void atca_delay_us(uint32_t delay) 51 | { 52 | // use ASF supplied delay 53 | delay_us(delay); 54 | } 55 | 56 | /** \brief This function delays for a number of tens of microseconds. 57 | * 58 | * \param[in] delay number of 0.01 milliseconds to delay 59 | */ 60 | void atca_delay_10us(uint32_t delay) 61 | { 62 | // use ASF supplied delay 63 | delay_us(delay * 10); 64 | 65 | } 66 | 67 | /** \brief This function delays for a number of milliseconds. 68 | * 69 | * You can override this function if you like to do 70 | * something else in your system while delaying. 71 | * \param[in] delay number of milliseconds to delay 72 | */ 73 | 74 | /* ASF already has delay_ms - see delay.h */ 75 | void atca_delay_ms(uint32_t delay) 76 | { 77 | // use ASF supplied delay 78 | delay_ms(delay); 79 | } 80 | 81 | /** @} */ 82 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_swi_bitbang.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for SWI bit banging. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef HAL_SWI_BITBANG_H_ 40 | #define HAL_SWI_BITBANG_H_ 41 | 42 | 43 | #if BOARD == AT88CK9000 44 | #include "swi_bitbang_at88ck9000.h" 45 | #endif 46 | 47 | #if (SAMD21 == 1) 48 | #include "swi_bitbang_samd21.h" 49 | #endif 50 | 51 | 52 | 53 | /** 54 | * \defgroup hal_ Hardware abstraction layer (hal_) 55 | * 56 | * \brief These methods define the hardware abstraction layer for 57 | * communicating with a CryptoAuth device using SWI bit banging. 58 | @{ */ 59 | 60 | /** 61 | * \brief This enumeration lists flags for SWI. 62 | */ 63 | enum swi_flag 64 | { 65 | SWI_FLAG_CMD = (uint8_t)0x77, //!< flag preceding a command 66 | SWI_FLAG_TX = (uint8_t)0x88, //!< flag requesting a response 67 | SWI_FLAG_IDLE = (uint8_t)0xBB, //!< flag requesting to go into Idle mode 68 | SWI_FLAG_SLEEP = (uint8_t)0xCC //!< flag requesting to go into Sleep mode 69 | }; 70 | 71 | /** 72 | * \brief This is the hal_data for ATCA HAL. 73 | */ 74 | typedef struct atcaSWImaster 75 | { 76 | uint8_t pin_sda; 77 | //! for conveniences during interface release phase 78 | int bus_index; 79 | } ATCASWIMaster_t; 80 | 81 | /** @} */ 82 | 83 | #endif /* HAL_SWI_BITBANG_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_swi_uart.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for SWI over UART drivers. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef HAL_SWI_UART_H_ 40 | #define HAL_SWI_UART_H_ 41 | 42 | #ifdef SAMD21_START 43 | #include "swi_uart_samd21_start.h" 44 | #elif defined (SAMD21_ASF) 45 | #include "swi_uart_samd21_asf.h" 46 | #elif defined (XMEGA_ASF) 47 | #include "swi_uart_xmega_a3bu_asf.h" 48 | #elif defined (AT90USB_ASF) 49 | #include "swi_uart_at90usb1287_asf.h" 50 | #endif 51 | 52 | 53 | /** \defgroup hal_ Hardware abstraction layer (hal_) 54 | * 55 | * \brief 56 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 57 | * using SWI interface. 58 | * 59 | @{ */ 60 | #define SWI_WAKE_TOKEN ((uint8_t)0x00) //!< flag preceding a command 61 | #define SWI_FLAG_CMD ((uint8_t)0x77) //!< flag preceding a command 62 | #define SWI_FLAG_TX ((uint8_t)0x88) //!< flag requesting a response 63 | #define SWI_FLAG_IDLE ((uint8_t)0xBB) //!< flag requesting to go into Idle mode 64 | #define SWI_FLAG_SLEEP ((uint8_t)0xCC) //!< flag requesting to go into Sleep mode 65 | 66 | ATCA_STATUS hal_swi_send_flag(ATCAIface iface, uint8_t flag); 67 | 68 | /** @} */ 69 | #endif /* HAL_SWI_UART_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_uboot_i2c.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef HAL_UBOOT_I2C_H_ 40 | #define HAL_UBOOT_I2C_H_ 41 | 42 | /** \defgroup hal_ Hardware abstraction layer (hal_) 43 | * 44 | * \brief 45 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 46 | * 47 | @{ */ 48 | 49 | #define MAX_I2C_BUSES 2 // Raspberry Pi has 2 TWI 50 | 51 | // A structure to hold I2C information 52 | typedef struct atcaI2Cmaster 53 | { 54 | int ref_ct; 55 | // for conveniences during interface release phase 56 | int bus_index; 57 | } ATCAI2CMaster_t; 58 | 59 | /** @} */ 60 | void change_i2c_speed(ATCAIface iface, uint32_t speed); 61 | 62 | #endif /* HAL_UBOOT_I2C_H_ */ 63 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_uboot_timer.c: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \brief 3 | * 4 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 5 | * 6 | * \page License 7 | * 8 | * You are permitted to use this software and its derivatives with Microchip 9 | * products. Redistribution and use in source and binary forms, with or without 10 | * modification, is permitted provided that the following conditions are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 19 | * 3. The name of Microchip may not be used to endorse or promote products derived 20 | * from this software without specific prior written permission. 21 | * 22 | * 4. This software may only be redistributed and used in connection with a 23 | * Microchip integrated circuit. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 28 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 29 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #include "atca_hal.h" 39 | 40 | 41 | /** \defgroup hal_ Hardware abstraction layer (hal_) 42 | * 43 | * \brief 44 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 45 | * 46 | @{ */ 47 | 48 | void atca_delay_us(uint32_t delay) 49 | { 50 | udelay(delay); 51 | } 52 | 53 | /** \brief This function delays for a number of tens of microseconds. 54 | * 55 | * \param[in] delay number of 0.01 milliseconds to delay 56 | */ 57 | void atca_delay_10us(uint32_t delay) 58 | { 59 | udelay(delay * 10); 60 | } 61 | 62 | 63 | /** \brief This function delays for a number of milliseconds. 64 | * 65 | * You can override this function if you like to do 66 | * something else in your system while delaying. 67 | * \param[in] delay number of milliseconds to delay 68 | */ 69 | 70 | /* ASF already has delay_ms - see delay.h */ 71 | void atca_delay_ms(uint32_t delay) 72 | { 73 | udelay(delay * 1000); 74 | } 75 | 76 | /** @} */ 77 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_win_kit_cdc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for Windows using kit protocol over a USB CDC device. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef HAL_WIN_KIT_CDC_H_ 40 | #define HAL_WIN_KIT_CDC_H_ 41 | 42 | #include 43 | 44 | // Kit USB defines 45 | #define CDC_DEVICES_MAX 10 //! Maximum number of supported Kit USB devices 46 | #define CDC_BUFFER_MAX 1024 //! Maximum number of bytes read per port read 47 | 48 | 49 | // Each device that is found will have a read handle and a write handle 50 | typedef struct cdc_device 51 | { 52 | HANDLE read_handle; //! The kit USB read file handle 53 | HANDLE write_handle; //! The kit USB write file handle 54 | } cdc_device_t; 55 | 56 | 57 | // A structure to hold CDC information 58 | typedef struct atcacdc 59 | { 60 | cdc_device_t kits[CDC_DEVICES_MAX]; 61 | int8_t num_kits_found; 62 | } atcacdc_t; 63 | 64 | #endif /* HAL_WIN_KIT_CDC_H_ */ 65 | 66 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_win_kit_hid.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for Windows using kit protocol over a USB HID device. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef HAL_WIN_KIT_HID_H_ 40 | #define HAL_WIN_KIT_HID_H_ 41 | 42 | #include 43 | 44 | /** \defgroup hal_ Hardware abstraction layer (hal_) 45 | * 46 | * \brief 47 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 48 | * 49 | @{ */ 50 | 51 | // Kit USB defines 52 | #define HID_DEVICES_MAX 10 //! Maximum number of supported Kit USB devices 53 | #define HID_PACKET_MAX 512 //! Maximum number of bytes for a HID send/receive packet (typically 64) 54 | 55 | // Each device that is found will have a read handle and a write handle 56 | typedef struct hid_device 57 | { 58 | HANDLE read_handle; //! The kit USB read file handle 59 | HANDLE write_handle; //! The kit USB write file handle 60 | } hid_device_t; 61 | 62 | 63 | // A structure to hold HID information 64 | typedef struct atcahid 65 | { 66 | hid_device_t kits[HID_DEVICES_MAX]; 67 | int8_t num_kits_found; 68 | } atcahid_t; 69 | 70 | /** @} */ 71 | #endif /* HAL_WIN_KIT_HID_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_win_timer.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for windows timer functions. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #include 40 | #include 41 | #include "atca_hal.h" 42 | 43 | /** \defgroup hal_ Hardware abstraction layer (hal_) 44 | * 45 | * \brief 46 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 47 | * 48 | @{ */ 49 | 50 | void atca_delay_us(uint32_t delay) 51 | { 52 | // divide by 1000 to convert us to ms 53 | // todo: use a timer with us accuracy 54 | long ms = (long)(delay / 1.0e3 + 0.5); // Miliseconds 55 | 56 | // use Windows supplied delay 57 | Sleep(delay); 58 | } 59 | 60 | /** \brief This function delays for a number of tens of microseconds. 61 | * 62 | * \param[in] delay number of 0.01 milliseconds to delay 63 | */ 64 | void atca_delay_10us(uint32_t delay) 65 | { 66 | // divide by 100 to convert 10's of us to ms 67 | // todo: use a timer with us accuracy 68 | long ms = (long)(delay / 1.0e2 + 0.5); // Miliseconds 69 | 70 | // use Windows supplied delay 71 | Sleep(delay); 72 | } 73 | 74 | /** \brief This function delays for a number of milliseconds. 75 | * 76 | * You can override this function if you like to do 77 | * something else in your system while delaying. 78 | * \param[in] delay number of milliseconds to delay 79 | */ 80 | 81 | /* ASF already has delay_ms - see delay.h */ 82 | void atca_delay_ms(uint32_t delay) 83 | { 84 | // use Windows supplied delay 85 | Sleep(delay); 86 | } 87 | 88 | /** @} */ 89 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_xmega_a3bu_i2c_asf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for XMEGA-A3BU I2C over ASF drivers. 4 | * 5 | * Prerequisite: add I2C Master Polled support to application in Atmel Studio 6 | * 7 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 8 | * 9 | * \page License 10 | * 11 | * You are permitted to use this software and its derivatives with Microchip 12 | * products. Redistribution and use in source and binary forms, with or without 13 | * modification, is permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Microchip may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with a 26 | * Microchip integrated circuit. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #ifndef HAL_XMEGA_A3BU_I2C_ASF_H_ 42 | #define HAL_XMEGA_A3BU_I2C_ASF_H_ 43 | 44 | #include 45 | #include "twi_master.h" 46 | 47 | /** \defgroup hal_ Hardware abstraction layer (hal_) 48 | * 49 | * \brief 50 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 51 | * using I2C driver of ASF. 52 | * 53 | @{ */ 54 | 55 | 56 | #define MAX_I2C_BUSES 4 // XMEGA A3BU has up to 4 PORT that can be configured as I2C 57 | 58 | /** \brief this is the hal_data for ATCA HAL created using ASF 59 | */ 60 | typedef struct atcaI2Cmaster 61 | { 62 | twi_master_t i2c_master_instance; 63 | int ref_ct; 64 | // for conveniences during interface release phase 65 | int bus_index; 66 | } ATCAI2CMaster_t; 67 | 68 | void change_i2c_speed(ATCAIface iface, uint32_t speed); 69 | 70 | /** @} */ 71 | #endif /* HAL_XMEGA_A3BU_I2C_ASF_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/hal_xmega_a3bu_timer_asf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer for SAMD21 timer/delay over ASF drivers. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #include 40 | #include 41 | #include "atca_hal.h" 42 | 43 | /** \defgroup hal_ Hardware abstraction layer (hal_) 44 | * 45 | * \brief 46 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 47 | * 48 | @{ */ 49 | 50 | void atca_delay_us(uint32_t delay) 51 | { 52 | // use ASF supplied delay 53 | delay_us(delay); 54 | } 55 | 56 | /** \brief This function delays for a number of tens of microseconds. 57 | * 58 | * \param[in] delay number of 0.01 milliseconds to delay 59 | */ 60 | void atca_delay_10us(uint32_t delay) 61 | { 62 | // use ASF supplied delay 63 | delay_us(delay * 10); 64 | 65 | } 66 | 67 | /** \brief This function delays for a number of milliseconds. 68 | * 69 | * You can override this function if you like to do 70 | * something else in your system while delaying. 71 | * \param[in] delay number of milliseconds to delay 72 | */ 73 | 74 | /* ASF already has delay_ms - see delay.h */ 75 | void atca_delay_ms(uint32_t delay) 76 | { 77 | // use ASF supplied delay 78 | delay_ms(delay); 79 | } 80 | 81 | /** @} */ 82 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/kit_phy.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief ATCA Hardware abstraction layer physical send & receive function definitions. 4 | * 5 | * This is included for kit protocol implementations. 6 | * It is included in the kit protocol callback to actually send and recieve bytes. 7 | * 8 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 9 | * 10 | * \page License 11 | * 12 | * You are permitted to use this software and its derivatives with Microchip 13 | * products. Redistribution and use in source and binary forms, with or without 14 | * modification, is permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Microchip may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * 4. This software may only be redistributed and used in connection with a 27 | * Microchip integrated circuit. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 30 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 31 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 32 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 33 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 38 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 39 | * POSSIBILITY OF SUCH DAMAGE. 40 | */ 41 | 42 | #ifndef KIT_PHY_H_ 43 | #define KIT_PHY_H_ 44 | 45 | #include "cryptoauthlib.h" 46 | 47 | 48 | /** \defgroup hal_ Hardware abstraction layer (hal_) 49 | * 50 | * \brief 51 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 52 | * 53 | @{ */ 54 | 55 | #ifdef __cplusplus 56 | extern "C" { 57 | #endif 58 | 59 | ATCA_STATUS kit_phy_num_found(int8_t* num_found); 60 | ATCA_STATUS kit_phy_send(ATCAIface iface, const char *txdata, int txlength); 61 | ATCA_STATUS kit_phy_receive(ATCAIface iface, char* rxdata, int* rxlength); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | /** @} */ 68 | 69 | #endif /* ATCA_HAL_PHY_H_ */ 70 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/hal/kit_protocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief Atmel Crypto Auth hardware interface object 5 | * 6 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 7 | * 8 | * \page License 9 | * 10 | * You are permitted to use this software and its derivatives with Microchip 11 | * products. Redistribution and use in source and binary forms, with or without 12 | * modification, is permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 21 | * 3. The name of Microchip may not be used to endorse or promote products derived 22 | * from this software without specific prior written permission. 23 | * 24 | * 4. This software may only be redistributed and used in connection with a 25 | * Microchip integrated circuit. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 28 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 29 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 30 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 31 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 35 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 36 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | #ifndef KIT_PROTOCOL_H_ 41 | #define KIT_PROTOCOL_H_ 42 | 43 | #include "cryptoauthlib.h" 44 | 45 | // Define this for debugging communication 46 | //#define KIT_DEBUG 47 | 48 | /** \defgroup hal_ Hardware abstraction layer (hal_) 49 | * 50 | * \brief 51 | * These methods define the hardware abstraction layer for communicating with a CryptoAuth device 52 | * 53 | @{ */ 54 | 55 | // The number of bytes to wrap a command in kit protocol. sizeof("s:t()\n") 56 | #define KIT_TX_WRAP_SIZE (7) 57 | 58 | // The number of bytes to wrap a response in kit protocol. sizeof("00()\n") 59 | #define KIT_MSG_SIZE (32) 60 | #define KIT_RX_WRAP_SIZE (KIT_MSG_SIZE + 6) 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | ATCA_STATUS kit_init(ATCAIface iface); 67 | 68 | ATCA_STATUS kit_send(ATCAIface iface, const uint8_t* txdata, int txlength); 69 | ATCA_STATUS kit_receive(ATCAIface iface, uint8_t* rxdata, uint16_t* rxsize); 70 | 71 | ATCA_STATUS kit_wrap_cmd(const uint8_t* txdata, int txlength, char* pkitbuf, int* nkitbuf); 72 | ATCA_STATUS kit_parse_rsp(const char* pkitbuf, int nkitbuf, uint8_t* kitstatus, uint8_t* rxdata, int* nrxdata); 73 | 74 | ATCA_STATUS kit_wake(ATCAIface iface); 75 | ATCA_STATUS kit_idle(ATCAIface iface); 76 | ATCA_STATUS kit_sleep(ATCAIface iface); 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | 82 | /** @} */ 83 | 84 | #endif // KIT_PROTOCOL_H 85 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/openssl/README.md: -------------------------------------------------------------------------------- 1 | 2 | #CryptoAuthentication OpenSSL Engine 3 | [TOC] 4 | ##Overview 5 | This is an OpenSSL Engine implementation using ATECC508A for ECC key storage, ECDSA sign/verify, ECDH, and FIPS Random Number Generator 6 | 7 | The implementation integrates the [Atmel ATECC508A](http://www.atmel.com/devices/atecc508a.aspx) into the [OpenSSL ENGINE API](http://openssl.org/docs/manmaster/crypto/engine.html) to provide secure hardware key storage, [CAVP certified random numbers](http://csrc.nist.gov/groups/STM/cavp/documents/aes/aesval.html), P256 ECDSA & ECDH, and secure storage for data. 8 | 9 | This project will integrate the key creation and import capabilities of the ATECC508A into the OpenSSL key creation and certificate creation process. 10 | 11 | Also, secure key storage for RSA keys are implemented using the encrypted read/write feature of the ATECC508A. 12 | 13 | ###Supported Cipher Suites 14 | Many ECDH(E)-ECDSA and ECDHE-RSA cipher suites are supported with the OpenSSL Engine for ATECC508A implementation. 15 | 16 | Details for cipher suites can be found [here](https://github.com/AtmelCSO/cryptoauth-openssl-engine/wiki/Supported-Ciphers) 17 | 18 | ##Download and Make 19 | Build instructions for Linux can be found on the Wiki pages associate with this project. 20 | 21 | See: [Compile OpenSSL Engine for ATECC508A on Linux](https://github.com/AtmelCSO/cryptoauth-openssl-engine/wiki/Linux:-Compile-OpenSSL-Engine-for-ATECC508A) 22 | 23 | ##Platform Integration 24 | Follow the platform integration instructions found [here](https://github.com/AtmelCSO/cryptoauth-openssl-engine/wiki/Integrate-ATECC508A-onto-Your-Platform) 25 | 26 | ##Unit Tests 27 | Unit testing is provided for both integration of the ATECC508A device and OpenSSL Examples. 28 | For details see: 29 | [Platform Integration Tests](https://github.com/AtmelCSO/cryptoauth-openssl-engine/wiki/ATECC508A-Integration-Tests) 30 | [OpenSSL Engine Tests & Examples](https://github.com/AtmelCSO/cryptoauth-openssl-engine/wiki/Tests-And-Examples) 31 | 32 | Source-Level Documentation 33 | Full Doxygen source-level documentation is provided. 34 | See: /docs/doxygen/html/index.html 35 | 36 | ##Web Server Setup 37 | The OpenSSL Engine for ATECC508A can also be configured. 38 | See Details [here](https://github.com/AtmelCSO/cryptoauth-openssl-engine/wiki/Web-Server-For-The-Web-Browser). 39 | 40 | ##Wiki Topics: 41 | - [Linux Development Setup](https://github.com/AtmelCSO/cryptoauth-openssl-engine/wiki/Linux:-Development-Setup) 42 | - [Compiling on Linux](https://github.com/AtmelCSO/cryptoauth-openssl-engine/wiki/Linux:-Compile-OpenSSL-Engine-for-ATECC508A) 43 | - [Debugging on Linux](https://github.com/AtmelCSO/cryptoauth-openssl-engine/wiki/Linux:-Debugging) 44 | - [ATECC508A Integration](https://github.com/AtmelCSO/cryptoauth-openssl-engine/wiki/ATECC508A:-Platform-Integration) 45 | - [ATECC508A Certificate Provisioning](http://www.atmel.com/tools/at88ckeccroot-signer.aspx) 46 | - [Tests and Examples](https://github.com/AtmelCSO/cryptoauth-openssl-engine/wiki/Tests:-OpenSSL-Tests-and-Examples) 47 | 48 | 49 | -------------------------------------------------------------------------------- /cryptoauthlib/lib/tls/ec_cert-508.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIBojCCAUkCAQAwgagxCzAJBgNVBAYTAlVTMREwDwYDVQQIEwhDb2xvcmFkbzEZ 3 | MBcGA1UEBxMQQ29sb3JhZG8gU3ByaW5nczEOMAwGA1UEChMFQXRtZWwxGDAWBgNV 4 | BAsTD1NlY3VyZSBQcm9kdWN0czEbMBkGA1UEAxMSRUNDNTA4IENlcnRpZmljYXRl 5 | MSQwIgYJKoZIhvcNAQkBFhVzdGV2ZS5jbGFya0BhdG1lbC5jb20wWTATBgcqhkjO 6 | PQIBBggqhkjOPQMBBwNCAATXVlA1m/p++WZo5rxfuT+e9YA17EecXIpC1g0ofAMy 7 | 6FbRtTc4m4av/AabwZTjJHLtpiPi+4nsBRFyQpa0FkhEoD4wIQYJKoZIhvcNAQkC 8 | MRQTEkVDQzUwOCBDZXJ0aWZpY2F0ZTAZBgkqhkiG9w0BCQcxDBMKZWNjNTA4Y2Vy 9 | dDAJBgcqhkjOPQQBA0gAMEUCIQCihiBJ3ukUSRUda3EYc+cZdctW/tLlup5DV2Sk 10 | XPPQ+AIgFFAzisiV9rTTXmm6jfg1UjQcZtu+/qhDmNTJadoN/Gw= 11 | -----END CERTIFICATE REQUEST----- 12 | -------------------------------------------------------------------------------- /cryptoauthlib/test/atca_basic_tests.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Unity tests for the cryptoauthlib Basic API 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef ATCA_BASIC_TESTS_H_ 40 | #define ATCA_BASIC_TESTS_H_ 41 | 42 | // Helper tests 43 | void RunAllHelperTests(void); 44 | void test_base64encode_decode(void); 45 | 46 | void RunBasicOtpZero(void); 47 | void RunAllBasicTests(void); 48 | 49 | #endif /* ATCA_BASIC_TESTS_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/test/atca_crypto_sw_tests.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Unity tests for the CryptoAuthLib software crypto API. 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef ATCA_CRYPTO_TESTS_H_ 40 | #define ATCA_CRYPTO_TESTS_H_ 41 | 42 | #include "unity.h" 43 | 44 | void atca_crypto_sw_tests(void); 45 | 46 | void test_atcac_sw_sha1_nist1(void); 47 | void test_atcac_sw_sha1_nist2(void); 48 | void test_atcac_sw_sha1_nist3(void); 49 | void test_atcac_sw_sha1_nist_short(void); 50 | void test_atcac_sw_sha1_nist_long(void); 51 | void test_atcac_sw_sha1_nist_monte(void); 52 | void test_atcac_sw_sha2_256_nist1(void); 53 | void test_atcac_sw_sha2_256_nist2(void); 54 | void test_atcac_sw_sha2_256_nist3(void); 55 | void test_atcac_sw_sha2_256_nist_short(void); 56 | void test_atcac_sw_sha2_256_nist_long(void); 57 | void test_atcac_sw_sha2_256_nist_monte(void); 58 | 59 | 60 | #endif -------------------------------------------------------------------------------- /cryptoauthlib/test/atca_test.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Cryptoauthlib Testing: Common Resources & Functions 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | #include "atca_test.h" 39 | 40 | // gCfg must point to one of the cfg_ structures for any unit test to work. this allows 41 | // the command console to switch device types at runtime. 42 | ATCAIfaceCfg g_iface_config = { 43 | .iface_type = ATCA_I2C_IFACE, 44 | .devtype = ATECC508A, 45 | .atcai2c = { 46 | .slave_address = 0xC0, 47 | .bus = 2, 48 | .baud = 400000, 49 | }, 50 | .wake_delay = 1500, 51 | .rx_retries = 20 52 | }; 53 | 54 | ATCAIfaceCfg *gCfg = &g_iface_config; 55 | 56 | const uint8_t g_slot4_key[32] = { 57 | 0x37, 0x80, 0xe6, 0x3d, 0x49, 0x68, 0xad, 0xe5, 0xd8, 0x22, 0xc0, 0x13, 0xfc, 0xc3, 0x23, 0x84, 58 | 0x5d, 0x1b, 0x56, 0x9f, 0xe7, 0x05, 0xb6, 0x00, 0x06, 0xfe, 0xec, 0x14, 0x5a, 0x0d, 0xb1, 0xe3 59 | }; 60 | 61 | 62 | #if defined(_WIN32) || defined(__linux__) 63 | #include 64 | #include 65 | #include "cmd-processor.h" 66 | int main(int argc, char* argv[]) 67 | { 68 | 69 | char buffer[1024]; 70 | size_t bufsize = sizeof(buffer); 71 | 72 | if (!buffer) 73 | { 74 | fprintf(stderr, "Failed to allocated a buffer"); 75 | return 1; 76 | } 77 | 78 | while (true) 79 | { 80 | printf("$ "); 81 | if (fgets(buffer, bufsize, stdin)) 82 | parseCmd(buffer); 83 | } 84 | 85 | return 0; 86 | } 87 | #endif 88 | -------------------------------------------------------------------------------- /cryptoauthlib/test/atca_test.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Tests for the Cryptoauthlib Basic API 4 | * 5 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 6 | * 7 | * \page License 8 | * 9 | * You are permitted to use this software and its derivatives with Microchip 10 | * products. Redistribution and use in source and binary forms, with or without 11 | * modification, is permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 20 | * 3. The name of Microchip may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with a 24 | * Microchip integrated circuit. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef ATCA_TEST_H_ 40 | #define ATCA_TEST_H_ 41 | 42 | #include "test/unity.h" 43 | #include "test/unity_fixture.h" 44 | #include "cryptoauthlib.h" 45 | 46 | #define TEST_ASSERT_SUCCESS(x) TEST_ASSERT_EQUAL(ATCA_SUCCESS, x) 47 | 48 | extern ATCAIfaceCfg *gCfg; 49 | extern const uint8_t g_slot4_key[]; 50 | 51 | #endif /* ATCA_TEST_H_ */ 52 | -------------------------------------------------------------------------------- /cryptoauthlib/test/atca_unit_tests.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 5 | * 6 | * \page License 7 | * 8 | * You are permitted to use this software and its derivatives with Microchip 9 | * products. Redistribution and use in source and binary forms, with or without 10 | * modification, is permitted provided that the following conditions are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 19 | * 3. The name of Microchip may not be used to endorse or promote products derived 20 | * from this software without specific prior written permission. 21 | * 22 | * 4. This software may only be redistributed and used in connection with a 23 | * Microchip integrated circuit. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 28 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 29 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #ifndef _ATCA_UTESTS_H 39 | #define _ATCA_UTESTS_H 40 | 41 | 42 | int certdata_unit_tests(void); 43 | int certio_unit_tests(void); 44 | int atcau_get_addr(uint8_t zone, uint8_t slot, uint8_t block, uint8_t offset, uint16_t* addr); 45 | bool atcau_is_locked(uint8_t zone); 46 | void test_lock_zone(void); 47 | 48 | void RunAllFeatureTests(void); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /cryptoauthlib/test/atcacert/test_atcacert_client_runner.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 5 | * 6 | * \page License 7 | * 8 | * You are permitted to use this software and its derivatives with Microchip 9 | * products. Redistribution and use in source and binary forms, with or without 10 | * modification, is permitted provided that the following conditions are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 19 | * 3. The name of Microchip may not be used to endorse or promote products derived 20 | * from this software without specific prior written permission. 21 | * 22 | * 4. This software may only be redistributed and used in connection with a 23 | * Microchip integrated circuit. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 28 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 29 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #include "test/unity.h" 39 | #include "test/unity_fixture.h" 40 | 41 | #ifdef __GNUC__ 42 | // Unity macros trigger this warning 43 | #pragma GCC diagnostic ignored "-Wnested-externs" 44 | #endif 45 | 46 | TEST_GROUP_RUNNER(atcacert_client) 47 | { 48 | // Load certificate data onto the device 49 | RUN_TEST_CASE(atcacert_client, atcacert_client__init); 50 | 51 | RUN_TEST_CASE(atcacert_client, atcacert_client__atcacert_read_cert_signer); 52 | RUN_TEST_CASE(atcacert_client, atcacert_client__atcacert_read_cert_device); 53 | RUN_TEST_CASE(atcacert_client, atcacert_client__atcacert_read_cert_small_buf); 54 | RUN_TEST_CASE(atcacert_client, atcacert_client__atcacert_read_cert_bad_params); 55 | 56 | RUN_TEST_CASE(atcacert_client, atcacert_client__atcacert_get_response); 57 | RUN_TEST_CASE(atcacert_client, atcacert_client__atcacert_get_response_bad_params); 58 | } 59 | -------------------------------------------------------------------------------- /cryptoauthlib/test/atcacert/test_atcacert_der_length_runner.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 5 | * 6 | * \page License 7 | * 8 | * You are permitted to use this software and its derivatives with Microchip 9 | * products. Redistribution and use in source and binary forms, with or without 10 | * modification, is permitted provided that the following conditions are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 19 | * 3. The name of Microchip may not be used to endorse or promote products derived 20 | * from this software without specific prior written permission. 21 | * 22 | * 4. This software may only be redistributed and used in connection with a 23 | * Microchip integrated circuit. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 28 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 29 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #include "test/unity.h" 39 | #include "test/unity_fixture.h" 40 | 41 | #ifdef __GNUC__ 42 | // Unity macros trigger this warning 43 | #pragma GCC diagnostic ignored "-Wnested-externs" 44 | #endif 45 | 46 | TEST_GROUP_RUNNER(atcacert_der_enc_length) 47 | { 48 | RUN_TEST_CASE(atcacert_der_enc_length, short_form); 49 | RUN_TEST_CASE(atcacert_der_enc_length, long_form_2byte); 50 | RUN_TEST_CASE(atcacert_der_enc_length, long_form_3byte); 51 | RUN_TEST_CASE(atcacert_der_enc_length, long_form_4byte); 52 | RUN_TEST_CASE(atcacert_der_enc_length, long_form_5byte); 53 | RUN_TEST_CASE(atcacert_der_enc_length, small_buf); 54 | RUN_TEST_CASE(atcacert_der_enc_length, bad_params); 55 | } 56 | 57 | TEST_GROUP_RUNNER(atcacert_der_dec_length) 58 | { 59 | RUN_TEST_CASE(atcacert_der_dec_length, good); 60 | RUN_TEST_CASE(atcacert_der_dec_length, zero_size); 61 | RUN_TEST_CASE(atcacert_der_dec_length, not_enough_data); 62 | RUN_TEST_CASE(atcacert_der_dec_length, indefinite_form); 63 | RUN_TEST_CASE(atcacert_der_dec_length, too_large); 64 | RUN_TEST_CASE(atcacert_der_dec_length, bad_params); 65 | } -------------------------------------------------------------------------------- /cryptoauthlib/test/atcacert/test_atcacert_host_hw_runner.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 5 | * 6 | * \page License 7 | * 8 | * You are permitted to use this software and its derivatives with Microchip 9 | * products. Redistribution and use in source and binary forms, with or without 10 | * modification, is permitted provided that the following conditions are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 19 | * 3. The name of Microchip may not be used to endorse or promote products derived 20 | * from this software without specific prior written permission. 21 | * 22 | * 4. This software may only be redistributed and used in connection with a 23 | * Microchip integrated circuit. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 28 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 29 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #include "test/unity.h" 39 | #include "test/unity_fixture.h" 40 | 41 | #ifdef __GNUC__ 42 | // Unity macros trigger this warning 43 | #pragma GCC diagnostic ignored "-Wnested-externs" 44 | #endif 45 | 46 | TEST_GROUP_RUNNER(atcacert_host_hw) 47 | { 48 | RUN_TEST_CASE(atcacert_host_hw, atcacert_host_hw__atcacert_verify_cert_hw); 49 | RUN_TEST_CASE(atcacert_host_hw, atcacert_host_hw__atcacert_verify_cert_hw_verify_failed); 50 | RUN_TEST_CASE(atcacert_host_hw, atcacert_host_hw__atcacert_verify_cert_hw_short_cert); 51 | RUN_TEST_CASE(atcacert_host_hw, atcacert_host_hw__atcacert_verify_cert_hw_bad_sig); 52 | RUN_TEST_CASE(atcacert_host_hw, atcacert_host_hw__atcacert_verify_cert_hw_bad_params); 53 | 54 | RUN_TEST_CASE(atcacert_host_hw, atcacert_host_hw__atcacert_gen_challenge_hw); 55 | RUN_TEST_CASE(atcacert_host_hw, atcacert_host_hw__atcacert_gen_challenge_hw_bad_params); 56 | 57 | RUN_TEST_CASE(atcacert_host_hw, atcacert_host_hw__atcacert_verify_response_hw); 58 | RUN_TEST_CASE(atcacert_host_hw, atcacert_host_hw__atcacert_verify_response_hw_bad_challenge); 59 | RUN_TEST_CASE(atcacert_host_hw, atcacert_host_hw__atcacert_verify_response_hw_bad_response); 60 | RUN_TEST_CASE(atcacert_host_hw, atcacert_host_hw__atcacert_verify_response_hw_bad_public_key); 61 | RUN_TEST_CASE(atcacert_host_hw, atcacert_host_hw__atcacert_verify_response_hw_malformed_public_key); 62 | RUN_TEST_CASE(atcacert_host_hw, atcacert_host_hw__atcacert_verify_response_hw_bad_params); 63 | } 64 | -------------------------------------------------------------------------------- /cryptoauthlib/test/atcacert/test_cert_def_0_device.h: -------------------------------------------------------------------------------- 1 | #ifndef TEST_CERT_DEF_0_DEVICE_H 2 | #define TEST_CERT_DEF_0_DEVICE_H 3 | 4 | #include "atcacert/atcacert_def.h" 5 | 6 | extern const atcacert_def_t g_test_cert_def_0_device; 7 | 8 | #endif // TEST_CERT_DEF_0_DEVICE_H 9 | -------------------------------------------------------------------------------- /cryptoauthlib/test/atcacert/test_cert_def_1_signer.h: -------------------------------------------------------------------------------- 1 | #ifndef TEST_CERT_DEF_1_SIGNER_H 2 | #define TEST_CERT_DEF_1_SIGNER_H 3 | 4 | #include "atcacert/atcacert_def.h" 5 | 6 | extern const uint8_t g_test_signer_1_ca_public_key[]; 7 | extern const atcacert_def_t g_test_cert_def_1_signer; 8 | 9 | #endif // TEST_CERT_DEF_1_SIGNER_H 10 | -------------------------------------------------------------------------------- /cryptoauthlib/test/cmd-processor.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief simple command processor for test console 5 | * 6 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 7 | * 8 | * \page License 9 | * 10 | * You are permitted to use this software and its derivatives with Microchip 11 | * products. Redistribution and use in source and binary forms, with or without 12 | * modification, is permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 21 | * 3. The name of Microchip may not be used to endorse or promote products derived 22 | * from this software without specific prior written permission. 23 | * 24 | * 4. This software may only be redistributed and used in connection with a 25 | * Microchip integrated circuit. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 28 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 29 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 30 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 31 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 35 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 36 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | 41 | #ifndef CMD_PROCESSOR_H_ 42 | #define CMD_PROCESSOR_H_ 43 | 44 | #include "cryptoauthlib.h" 45 | 46 | #define cmdQ_SIZE 512 47 | 48 | int processCmd(void); 49 | 50 | volatile struct 51 | { 52 | uint8_t m_getIdx; 53 | uint8_t m_putIdx; 54 | uint8_t m_entry[ cmdQ_SIZE ]; 55 | } cmdQ; 56 | 57 | int parseCmd(const char *command); 58 | int help(void); 59 | int run_tests(int test); 60 | 61 | ATCA_STATUS isDeviceLocked(uint8_t zone, bool *isLocked); 62 | ATCA_STATUS lockstatus(void); 63 | ATCA_STATUS lock_config_zone(void); 64 | ATCA_STATUS lock_data_zone(void); 65 | ATCA_STATUS getinfo(uint8_t *revision); 66 | ATCA_STATUS getsernum(uint8_t *sernum); 67 | ATCA_STATUS doRandoms(void); 68 | 69 | 70 | #endif /* CMD-PROCESSOR_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/test/sha-byte-test-vectors/Readme.txt: -------------------------------------------------------------------------------- 1 | There are two sets of SHA example files: 2 | 3 | 1. The response (.rsp) files contain properly formatted CAVS response files. 4 | 5 | 2. The intermediate value (.txt) files for the Monte Carlo tests contain 6 | values for the inner loop as shown in the pseudocode in Figure 1 on page 9 7 | of the SHA Validation System. The inner loop variable 'i' ranges in value 8 | from 3 to 1002. The intermediate values for the first five iterations of 9 | the inner loop therefore correspond to 'i' values of 3 to 7. The message (M) 10 | and the message digest (MDi) for each of these i are printed out, indented 11 | by one tab space. The final message digest (MD), not indented, is the last 12 | value printed for each count. 13 | 14 | 15 | The SHA Validation System document can be found at: 16 | 17 | http://csrc.nist.gov/groups/STM/cavp/documents/shs/SHAVS.pdf. -------------------------------------------------------------------------------- /cryptoauthlib/test/tls/atcatls_tests.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \copyright Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved. 5 | * 6 | * \page License 7 | * 8 | * You are permitted to use this software and its derivatives with Microchip 9 | * products. Redistribution and use in source and binary forms, with or without 10 | * modification, is permitted provided that the following conditions are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 19 | * 3. The name of Microchip may not be used to endorse or promote products derived 20 | * from this software without specific prior written permission. 21 | * 22 | * 4. This software may only be redistributed and used in connection with a 23 | * Microchip integrated circuit. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 28 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR 29 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | 39 | #ifndef ATCA_TLS_TESTS_H_ 40 | #define ATCA_TLS_TESTS_H_ 41 | 42 | 43 | #include "test/unity.h" 44 | 45 | void atcatls_test_runner(ATCAIfaceCfg* pCfg); 46 | 47 | // TLS API Init/finish 48 | void test_atcatls_config_default(void); 49 | void test_atcatls_init_finish(void); 50 | 51 | // Core TLS definitions 52 | void test_atcatls_create_key(void); 53 | void test_atcatls_sign(void); 54 | void test_atcatls_verify(void); 55 | void test_atcatls_ecdh(void); 56 | void test_atcatls_ecdhe(void); 57 | void test_atcatls_calc_pubkey(void); 58 | void test_atcatls_read_pubkey(void); 59 | void test_atcatls_random(void); 60 | void test_atcatls_get_sn(void); 61 | 62 | // Certificate Handling 63 | void test_atcatls_verify_cert_chain(void); 64 | void test_atcatls_verify_default_certs(void); 65 | void test_atcatls_ca_pubkey_write_read(void); 66 | void test_atcatls_get_ca_cert(void); 67 | void test_atcatls_create_csr(void); 68 | 69 | // Encrypted Read/Write 70 | void test_atcatls_init_enc_key(void); 71 | void test_atcatls_enc_write_read(void); 72 | void test_atcatls_enc_rsakey_write_read(void); 73 | 74 | 75 | #endif /* ATCA_TLS_TESTS_H_ */ -------------------------------------------------------------------------------- /cryptoauthlib/test/unity_fixture_internals.h: -------------------------------------------------------------------------------- 1 | //- Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | /* ========================================== 3 | Unity Project - A Test Framework for C 4 | Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | [Released under MIT License. Please refer to license.txt for details] 6 | ========================================== */ 7 | 8 | #ifndef UNITY_FIXTURE_INTERNALS_H_ 9 | #define UNITY_FIXTURE_INTERNALS_H_ 10 | 11 | typedef struct _UNITY_FIXTURE_T 12 | { 13 | int Verbose; 14 | unsigned int RepeatCount; 15 | const char* NameFilter; 16 | const char* GroupFilter; 17 | } UNITY_FIXTURE_T; 18 | 19 | typedef void unityfunction (void); 20 | void UnityTestRunner(unityfunction * setup, 21 | unityfunction * body, 22 | unityfunction * teardown, 23 | const char * printableName, 24 | const char * group, 25 | const char * name, 26 | const char * file, int line); 27 | 28 | void UnityIgnoreTest(const char * printableName); 29 | void UnityMalloc_StartTest(void); 30 | void UnityMalloc_EndTest(void); 31 | int UnityFailureCount(void); 32 | int UnityGetCommandLineOptions(int argc, const char* argv[]); 33 | void UnityConcludeFixtureTest(void); 34 | 35 | void UnityPointer_Set(void ** ptr, void * newValue); 36 | void UnityPointer_UndoAllSets(void); 37 | void UnityPointer_Init(void); 38 | 39 | void UnityAssertEqualPointer(const void * expected, 40 | const void * actual, 41 | const char* msg, 42 | const UNITY_LINE_TYPE lineNumber); 43 | 44 | #endif /* UNITY_FIXTURE_INTERNALS_H_ */ 45 | -------------------------------------------------------------------------------- /cryptoauthlib/test/unity_fixture_malloc_overrides.h: -------------------------------------------------------------------------------- 1 | //- Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | /* ========================================== 3 | Unity Project - A Test Framework for C 4 | Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | [Released under MIT License. Please refer to license.txt for details] 6 | ========================================== */ 7 | 8 | #ifndef UNITY_FIXTURE_MALLOC_OVERRIDES_H_ 9 | #define UNITY_FIXTURE_MALLOC_OVERRIDES_H_ 10 | 11 | //#define malloc unity_malloc 12 | //#define calloc unity_calloc 13 | //#define realloc unity_realloc 14 | //#define free unity_free 15 | 16 | void* unity_malloc(size_t size); 17 | void* unity_calloc(size_t num, size_t size); 18 | void* unity_realloc(void * oldMem, size_t size); 19 | void unity_free(void * mem); 20 | 21 | #endif /* UNITY_FIXTURE_MALLOC_OVERRIDES_H_ */ 22 | -------------------------------------------------------------------------------- /scripts/TestMatrix.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MicrochipTech/cryptoauth-openssl-engine/a69a4f92af6bee9cb13035c2f859912744796380/scripts/TestMatrix.xlsx -------------------------------------------------------------------------------- /scripts/archive/run_client: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd $(dirname $0) 3 | TREE_TOP=../.. 4 | export LD_LIBRARY_PATH=$TREE_TOP/install_dir/lib 5 | export LD_PRELOAD=/lib/x86_64-linux-gnu/libpthread.so.0 6 | 7 | CMD="./exchange-tls12" 8 | #CMD="gdb --args ./exchange-tls12" 9 | 10 | # -c may specify many ciphers; just first available will be run 11 | #:ECDH-ECDSA-AES128-SHA256:ECDH-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256 12 | ${CMD} \ 13 | -c ":ECDHE-ECDSA-AES128-GCM-SHA256" \ 14 | -p $TREE_TOP/certstore/trusted \ 15 | -b $TREE_TOP/certstore/trusted/homut_bundle.crt \ 16 | -f $TREE_TOP/certstore/personal/homut_client.crt \ 17 | -k $TREE_TOP/certstore/privkeys/homut_client.key 18 | -------------------------------------------------------------------------------- /scripts/archive/run_client_eng: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd $(dirname $0) 3 | TREE_TOP=../.. 4 | export LD_LIBRARY_PATH=$TREE_TOP/install_dir/lib 5 | export LD_PRELOAD=/lib/x86_64-linux-gnu/libpthread.so.0 6 | 7 | CMD="./exchange-tls12" 8 | #CMD="gdb --args ./exchange-tls12" 9 | 10 | # -c may specify many ciphers; just first available will be run 11 | # :ECDH-ECDSA-AES128-SHA256:ECDH-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256 12 | ${CMD} \ 13 | -c ":ECDHE-ECDSA-AES128-GCM-SHA256" \ 14 | -p $TREE_TOP/certstore/trusted \ 15 | -b $TREE_TOP/certstore/trusted/homut_bundle.crt \ 16 | -f $TREE_TOP/certstore/personal/homut_client_eccx08.crt \ 17 | -k $TREE_TOP/certstore/privkeys/homut_client_eccx08.key \ 18 | -e ateccx08 19 | -------------------------------------------------------------------------------- /scripts/archive/run_der_client: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set -x 4 | cd $(dirname $0) 5 | TREE_TOP=.. 6 | export LD_LIBRARY_PATH=$TREE_TOP/install_dir/lib 7 | export LD_PRELOAD=/lib/x86_64-linux-gnu/libpthread.so.0 8 | PORT=49917 9 | 10 | # Certificate names 11 | TMP_CERT_DIR=/tmp 12 | DEVICE_CERT=${TMP_CERT_DIR}/dev_cert 13 | SIGNER_CERT=${TMP_CERT_DIR}/signer_cert 14 | ROOT_CERT=${TMP_CERT_DIR}/root_cert 15 | SIGNER_BUNDLE=${TMP_CERT_DIR}/signer_bundle 16 | 17 | if [ -z $USE_ENGINE ]; then 18 | USE_ENGINE=1 19 | fi 20 | 21 | if [ $USE_ENGINE = "0" ]; then 22 | ENGINE= 23 | else 24 | ENGINE="-engine ateccx08" 25 | fi 26 | 27 | if [ $USE_ENGINE = "0" ]; then 28 | TARGET="client" 29 | else 30 | TARGET="client_eccx08" 31 | fi 32 | 33 | BUNDLE=bundle 34 | 35 | if [ -z "$RSA" ]; then 36 | RSA= 37 | fi 38 | 39 | # Note this env var can be considered in OpenSSL s_client.c (see getenv) 40 | 41 | if [ -z "$SSL_CIPHER" ]; then 42 | #export SSL_CIPHER=ECDHE-ECDSA-AES128-GCM-SHA256 # define RSA to nothing on both client and server 43 | export SSL_CIPHER=ECDH-ECDSA-AES128-GCM-SHA256 # define RSA to nothing on both client and server 44 | #export SSL_CIPHER=ECDHE-RSA-AES128-SHA # define RSA=rsa_ on both client and server 45 | #export SSL_CIPHER=ECDHE-RSA-AES128-SHA256 # define RSA=rsa_ on both client and server 46 | fi 47 | 48 | #export SSL_CIPHER=ECDH-RSA-AES128-SHA256 # - dropped from SOW 49 | #export SSL_CIPHER=DH-RSA-AES256-SHA256 # requires TARGET="dh"on server side - dropped from SOW 50 | 51 | # Call TLS client (no engine for the test) 52 | 53 | CMD=../install_dir/bin/openssl 54 | #CMD=../cmd_openssl gdb 55 | CMD_GDB=../install_dir/bin/openssl 56 | #CMD_GDB="gdb --args ../install_dir/bin/openssl" 57 | 58 | set +e 59 | # Convert Signer and Root certificates from DER to PEM format and put them into the bundle 60 | ${CMD} x509 -inform DER -outform PEM -in ${SIGNER_CERT}.der -out ${SIGNER_CERT}.pem 61 | ${CMD} x509 -inform DER -outform PEM -in ${ROOT_CERT}.der -out ${ROOT_CERT}.pem 62 | cat ${SIGNER_CERT}.pem ${ROOT_CERT}.pem > ${SIGNER_BUNDLE}.pem 63 | 64 | ${CMD_GDB} s_client ${ENGINE} -connect localhost:${PORT} \ 65 | -certform DER -cert ${DEVICE_CERT}.der -key privkeys/homut_${RSA}${TARGET}.key \ 66 | -CApath /tmp -CAfile ${SIGNER_BUNDLE}.pem -cipher ${SSL_CIPHER} 67 | 68 | # -showcerts 69 | STATUS=$? 70 | echo "EXIT STATUS: ${STATUS}" 71 | exit ${STATUS} 72 | -------------------------------------------------------------------------------- /scripts/archive/run_der_server: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set -x 4 | cd $(dirname $0) 5 | TREE_TOP=.. 6 | export LD_LIBRARY_PATH=$TREE_TOP/install_dir/lib 7 | export LD_PRELOAD=/lib/x86_64-linux-gnu/libpthread.so.0 8 | PORT=49917 9 | 10 | # Certificate names 11 | TMP_CERT_DIR=/tmp 12 | DEVICE_CERT=${TMP_CERT_DIR}/dev_cert 13 | SIGNER_CERT=${TMP_CERT_DIR}/signer_cert 14 | ROOT_CERT=${TMP_CERT_DIR}/root_cert 15 | SIGNER_BUNDLE=${TMP_CERT_DIR}/signer_bundle 16 | 17 | if [ -z "$USE_ENGINE" ]; then 18 | USE_ENGINE=0 19 | fi 20 | 21 | if [ $USE_ENGINE = "0" ]; then 22 | ENGINE= 23 | else 24 | ENGINE="-engine ateccx08" 25 | fi 26 | 27 | #TARGET="dh" 28 | if [ -z "$TARGET" ]; then 29 | if [ $USE_ENGINE = "0" ]; then 30 | TARGET="server" 31 | else 32 | TARGET="server_eccx08" 33 | fi 34 | fi 35 | 36 | BUNDLE=bundle 37 | 38 | if [ -z "$RSA" ]; then 39 | RSA= 40 | fi 41 | 42 | #No need to specify cipher on server - it will pick correct one 43 | #export SSL_CIPHER=ECDHE-ECDSA-AES128-GCM-SHA256 # define RSA to nothing on both client and server 44 | #export SSL_CIPHER=ECDH-ECDSA-AES128-GCM-SHA256 # define RSA to nothing on both client and server 45 | #export SSL_CIPHER=ECDHE-RSA-AES128-SHA # define RSA=rsa_ on both client and server 46 | #export SSL_CIPHER=ECDHE-RSA-AES128-SHA256 # define RSA=rsa_ on both client and server 47 | 48 | #export SSL_CIPHER=ECDH-RSA-AES128-SHA256 # - dropped from SOW 49 | #export SSL_CIPHER=DH-RSA-AES256-SHA256 # requires TARGET="dh" - not required by SOW 50 | 51 | # Call TLS client with engine 52 | 53 | CMD=../install_dir/bin/openssl 54 | #CMD=../cmd_openssl gdb 55 | CMD_GDB=../install_dir/bin/openssl 56 | #CMD_GDB="gdb --args ../install_dir/bin/openssl" 57 | 58 | set +e 59 | # Convert Signer and Root certificates from DER to PEM format and put them into the bundle 60 | ${CMD} x509 -inform DER -outform PEM -in ${SIGNER_CERT}.der -out ${SIGNER_CERT}.pem 61 | ${CMD} x509 -inform DER -outform PEM -in ${ROOT_CERT}.der -out ${ROOT_CERT}.pem 62 | cat ${SIGNER_CERT}.pem ${ROOT_CERT}.pem > ${SIGNER_BUNDLE}.pem 63 | 64 | ${CMD_GDB} s_server ${ENGINE} -accept ${PORT} -Verify 4 \ 65 | -certform DER -cert ${DEVICE_CERT}.der -key privkeys/homut_${RSA}${TARGET}.key \ 66 | -CApath /tmp -CAfile ${SIGNER_BUNDLE}.pem 67 | STATUS=$? 68 | echo "EXIT STATUS: ${STATUS}" 69 | exit ${STATUS} 70 | 71 | -------------------------------------------------------------------------------- /scripts/archive/run_rsa_client: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd $(dirname $0) 3 | TREE_TOP=../.. 4 | export LD_LIBRARY_PATH=$TREE_TOP/install_dir/lib 5 | # -c may specify many ciphers; just first available will be run 6 | ./exchange-tls12 -c "ECDHE-RSA-AES256-GCM-SHA384:DH-RSA-AES128-SHA:DH-RSA-AES128-SHA256" \ 7 | -p $TREE_TOP/certstore/trusted \ 8 | -b $TREE_TOP/certstore/trusted/homut_rsa_bundle.crt \ 9 | -f $TREE_TOP/certstore/personal/homut_rsa_client.crt \ 10 | -k $TREE_TOP/certstore/privkeys/homut_rsa_client.key 11 | -------------------------------------------------------------------------------- /scripts/archive/run_rsa_server: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd $(dirname $0) 3 | TREE_TOP=../.. 4 | export LD_LIBRARY_PATH=$TREE_TOP/install_dir/lib 5 | # -c may specify many ciphers; just first available will be run 6 | gdb --args ./exchange-tls12 -s \ 7 | -p $TREE_TOP/certstore/trusted \ 8 | -b $TREE_TOP/certstore/trusted/homut_rsa_bundle.crt \ 9 | -f $TREE_TOP/certstore/personal/homut_rsa_dh.crt \ 10 | -k $TREE_TOP/certstore/privkeys/homut_rsa_dh.key 11 | 12 | # -f $TREE_TOP/certstore/personal/homut_rsa_server.crt \ 13 | # -k $TREE_TOP/certstore/privkeys/homut_rsa_server.key 14 | -------------------------------------------------------------------------------- /scripts/archive/run_server: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd $(dirname $0) 3 | TREE_TOP=../.. 4 | export LD_LIBRARY_PATH=$TREE_TOP/install_dir/lib 5 | export LD_PRELOAD=/lib/x86_64-linux-gnu/libpthread.so.0 6 | 7 | CMD="./exchange-tls12" 8 | #CMD="gdb --args ./exchange-tls12" 9 | 10 | ${CMD} \ 11 | -s -p $TREE_TOP/certstore/trusted \ 12 | -b $TREE_TOP/certstore/trusted/homut_bundle.crt \ 13 | -f $TREE_TOP/certstore/personal/homut_server.crt \ 14 | -k $TREE_TOP/certstore/privkeys/homut_server.key 15 | 16 | -------------------------------------------------------------------------------- /scripts/archive/run_server_eng: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd $(dirname $0) 3 | TREE_TOP=../.. 4 | export LD_LIBRARY_PATH=$TREE_TOP/install_dir/lib 5 | export LD_PRELOAD=/lib/x86_64-linux-gnu/libpthread.so.0 6 | 7 | CMD="./exchange-tls12" 8 | #CMD="gdb --args ./exchange-tls12" 9 | 10 | ${CMD} \ 11 | -s -p $TREE_TOP/certstore/trusted \ 12 | -b $TREE_TOP/certstore/trusted/homut_bundle.crt \ 13 | -f $TREE_TOP/certstore/personal/homut_server_eccx08.crt \ 14 | -k $TREE_TOP/certstore/privkeys/homut_server_eccx08.key \ 15 | -e ateccx08 16 | 17 | -------------------------------------------------------------------------------- /scripts/archive/test_client: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | set -e 4 | cd $(dirname $0) 5 | TREE_TOP=../.. 6 | cd $TREE_TOP/certstore 7 | ./run_cert_client 8 | #./run_cert_serv 9 | cd - 10 | ./run_client_eng 11 | -------------------------------------------------------------------------------- /scripts/archive/test_client_neg: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | set -e 4 | cd $(dirname $0) 5 | TREE_TOP=../.. 6 | cd $TREE_TOP/certstore 7 | cp -f privkeys/homut_client.key privkeys/homut_client_eccx08.key 8 | #./run_cert_client 9 | #./run_cert_serv 10 | cd - 11 | ./run_client_eng 12 | -------------------------------------------------------------------------------- /scripts/archive/test_server: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | set -e 4 | cd $(dirname $0) 5 | TREE_TOP=../.. 6 | cd $TREE_TOP/certstore 7 | #./run_cert_client 8 | #./run_cert_serv 9 | cd - 10 | ./run_server 11 | 12 | -------------------------------------------------------------------------------- /scripts/common.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set -x 4 | cd $(dirname $0) 5 | cd .. 6 | export TREE_TOP=${PWD} 7 | export CERTSTORE=$TREE_TOP/certstore 8 | export SCRIPTS=$TREE_TOP/scripts 9 | export BIN_DIR=$TREE_TOP/install_dir/bin 10 | export EX_DIR=$TREE_TOP/client-server 11 | 12 | # Certificate names 13 | export DEVICE_CERT=${CERTSTORE}/personal/AT_device 14 | export DEVICE_KEY=${CERTSTORE}/privkeys/AT_device.key 15 | export DEVICE_CSR=${CERTSTORE}/csr/AT_device.csr 16 | export SIGNER_CERT=${CERTSTORE}/trusted/AT_signer 17 | export SIGNER_PATH=${CERTSTORE}/trusted 18 | export ROOT_CERT=${CERTSTORE}/trusted/AT_root 19 | export SIGNER_BUNDLE=${CERTSTORE}/trusted/AT_bundle.crt 20 | 21 | export LD_LIBRARY_PATH=$TREE_TOP/install_dir/lib 22 | export LD_PRELOAD=/lib/x86_64-linux-gnu/libpthread.so.0 23 | 24 | if [ -z "$PORT_NUMBER" ]; then 25 | export PORT_NUMBER=49917 26 | fi 27 | 28 | if [ -z "$IP_ADDRESS" ]; then 29 | export IP_ADDRESS="127.0.0.1" 30 | fi 31 | 32 | export ENGINE="-engine ateccx08" 33 | export KEYGEN_ENGINE="-keygen_engine ateccx08" 34 | 35 | if [ -z "$COMPANY" ]; then 36 | export COMPANY="homut" 37 | fi 38 | 39 | if [ -z "$COMMON_NAME" ]; then 40 | export COMMON_NAME="homut" 41 | fi 42 | 43 | if [ -z "$USE_EXAMPLE" ]; then 44 | export USE_EXAMPLE=0 45 | fi 46 | 47 | if [ -z "$USE_ENGINE" ]; then 48 | export USE_ENGINE=0 49 | fi 50 | 51 | if [ -z "$USE_ATMEL_CA" ]; then 52 | export USE_ATMEL_CA=0 53 | fi 54 | 55 | if [ -z "$NEW_KEY" ]; then 56 | export NEW_KEY=0 57 | fi 58 | 59 | if [ -z "$NEW_ROOT" ]; then 60 | export NEW_ROOT=0 61 | fi 62 | 63 | if [ -z "$USE_WWW" ]; then 64 | USE_WWW=0 65 | fi 66 | 67 | if [ $USE_ENGINE = "0" ]; then 68 | export ENGINE= 69 | export ENGINE_EX= 70 | else 71 | export ENGINE="-engine ateccx08" 72 | export ENGINE_EX="-e ateccx08" 73 | fi 74 | 75 | if [ -z "$USE_RSA" ]; then 76 | export USE_RSA=0 77 | fi 78 | 79 | if [ $USE_RSA = "0" ]; then 80 | RSA= 81 | else 82 | RSA=rsa_ 83 | if [ $USE_ENGINE = "0" ]; then 84 | KEYFORM= 85 | else 86 | KEYFORM="-keyform ENG" 87 | fi 88 | fi 89 | 90 | export CMD=${BIN_DIR}/openssl 91 | #export CMD=${TREE_TOP}/cmd_openssl gdb 92 | #export CMD="gdb --args ${BIN_DIR}/openssl" 93 | export CMD_EX="${EX_DIR}/exchange-tls12" 94 | #export CMD_EX="gdb --args ${EX_DIR}/exchange-tls12" 95 | 96 | 97 | -------------------------------------------------------------------------------- /scripts/mk_release_lite: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | set -e 4 | 5 | function upfind() { 6 | startdir=`pwd` 7 | dir=$startdir 8 | while [ "$dir" != "/" ]; do 9 | p=`find "$dir" -maxdepth 1 -name $1` 10 | if [ ! -z $p ]; then 11 | echo "$dir" 12 | return 13 | fi 14 | dir=`dirname "$dir"` 15 | done 16 | echo "ERROR: Failed to locate base directory ${startdir}/$1" 17 | exit 1 18 | } 19 | 20 | # Prepare the base directory 21 | cd .. 22 | make init_submodule 23 | cd - 24 | 25 | TMP=/var/tmp 26 | BASEDIR="$(upfind .git)" 27 | DNAME=`basename ${BASEDIR}` 28 | TMPSB=${TMP}/${DNAME} 29 | 30 | #echo ${BASEDIR} 31 | #echo $dname 32 | #exit 0 33 | 34 | rm -rf ${TMPSB} 35 | cp -rf ${BASEDIR} ${TMP} 36 | rm -rf ${TMPSB}/trace_coverages 37 | mv ${TMPSB}/.git/modules ${TMPSB} 38 | rm -rf ${TMPSB}/.git 39 | mkdir -p ${TMPSB}/.git 40 | mv ${TMPSB}/modules ${TMPSB}/.git 41 | rm -f ${TMPSB}/.gitignore 42 | rm -f ${TMPSB}/.gitmodules 43 | #rm -rf ${TMPSB}/openssl* 44 | #rm -rf ${TMPSB}/openssl*/.git 45 | #rm -rf ${TMPSB}/unity 46 | rm -rf ${TMPSB}/ecc-crypto 47 | rm -f ${TMPSB}/Tasks-Schedule-*.xlsx 48 | rm -f ${TMPSB}/tools/*.exe 49 | rm -rf ${TMPSB}/tools/SignerModule 50 | rm -rf ${TMPSB}/tools/cryptoauth-kit-d21-host 51 | rm -rf ${TMPSB}/install_dir 52 | #rm -rf ${TMPSB}/engine_atecc/cryptoauthlib 53 | #exit 0 54 | 55 | cd ${TMP} 56 | TARBALL=${TMP}/${DNAME}.tgz 57 | tar cvfz ${TARBALL} ${DNAME} 58 | cd - 59 | echo "CREATED RELEASE TARBALL: ${TARBALL}" 60 | -------------------------------------------------------------------------------- /scripts/run_cert_client.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # With NEW_KEY=1 the script requires to enter the password 3 times. 3 | # It is required because by default "openssl req" 4 | # cannot do it without the password. 5 | # Then "openssl ec" removes the password 6 | # NOTE! Be careful with NEW_KEY=1. Atmel certificates may be invalidated! 7 | # A new key may be generated if key is not locked! 8 | 9 | set -e 10 | set -x 11 | cd $(dirname $0) 12 | source ./common.sh 13 | 14 | cd .. 15 | cd ${CERTSTORE} 16 | 17 | if [ -z "$COMPANY" ]; then 18 | COMPANY="homut" 19 | fi 20 | 21 | if [ -z "$NEW_KEY" ]; then 22 | NEW_KEY=0 23 | fi 24 | 25 | if [ $NEW_KEY = "1" ]; then 26 | 27 | # generate a new key then generate and sign client certificate using engine 28 | rm -f ${CERTSTORE}/privkeys/${COMPANY}_client_eccx08.key \ 29 | ${CERTSTORE}/csr/${COMPANY}_client_eccx08.csr \ 30 | ${CERTSTORE}/personal/${COMPANY}_client_eccx08.crt \ 31 | ${CERTSTORE}/privkeys/${COMPANY}_client_eccx08.der 32 | 33 | ${CMD} req ${KEYGEN_ENGINE} \ 34 | -new -newkey ec:${CERTSTORE}/prime256v1.pem \ 35 | -keyout ${CERTSTORE}/privkeys/${COMPANY}_client_eccx08.key \ 36 | -out ${CERTSTORE}/csr/${COMPANY}_client_eccx08.csr \ 37 | -sha256 -config ${CERTSTORE}/openssl.cnf \ 38 | -subj /C=US/ST=CA/L=Sunnyvale/O=Homut\ LLC/CN=${COMPANY}_client_eccx08/ \ 39 | -verify 40 | 41 | # generate a new key then generate and sign server certificate without using engine 42 | ${CMD} ecparam -out ${CERTSTORE}/privkeys/${COMPANY}_client.key \ 43 | -name prime256v1 -genkey 44 | ${CMD} req -new -key ${CERTSTORE}/privkeys/${COMPANY}_client.key \ 45 | -out ${CERTSTORE}/csr/${COMPANY}_client.csr -sha256 \ 46 | -config ${CERTSTORE}/openssl.cnf \ 47 | -subj /C=US/ST=CA/L=Sunnyvale/O=Homut\ LLC/CN=${COMPANY}_client/ \ 48 | -verify 49 | ${CMD} ca -batch \ 50 | -config ${CERTSTORE}/openssl.cnf -extensions usr_cert \ 51 | -days 365 -in ${CERTSTORE}/csr/${COMPANY}_client.csr \ 52 | -cert ${CERTSTORE}/trusted/${COMPANY}_intermediate.crt \ 53 | -keyfile ${CERTSTORE}/privkeys/${COMPANY}_intermediate.key \ 54 | -out ${CERTSTORE}/personal/${COMPANY}_client.crt 55 | 56 | else 57 | 58 | # generate and sign certificates using engine, use existing key 59 | ${CMD} req ${ENGINE} \ 60 | -new -key ${CERTSTORE}/privkeys/${COMPANY}_client_eccx08.key \ 61 | -out ${CERTSTORE}/csr/${COMPANY}_client_eccx08.csr \ 62 | -sha256 -config ${CERTSTORE}/openssl.cnf \ 63 | -subj /C=US/ST=CA/L=Sunnyvale/O=Homut\ LLC/CN=${COMPANY}_client_eccx08/ \ 64 | -verify 65 | 66 | fi 67 | 68 | ${CMD} ca -batch \ 69 | -config ${CERTSTORE}/openssl.cnf \ 70 | -extensions usr_cert -days 365 -in ${CERTSTORE}/csr/${COMPANY}_client_eccx08.csr \ 71 | -cert ${CERTSTORE}/trusted/${COMPANY}_intermediate.crt \ 72 | -keyfile ${CERTSTORE}/privkeys/${COMPANY}_intermediate.key \ 73 | -out ${CERTSTORE}/personal/${COMPANY}_client_eccx08.crt 74 | 75 | ${CMD} ec \ 76 | -in ${CERTSTORE}/privkeys/${COMPANY}_client_eccx08.key \ 77 | -out ${CERTSTORE}/privkeys/${COMPANY}_client_eccx08.key 78 | 79 | ${CMD} ec \ 80 | -in ${CERTSTORE}/privkeys/${COMPANY}_client_eccx08.key \ 81 | -outform DER -out ${CERTSTORE}/privkeys/${COMPANY}_client_eccx08.der 82 | 83 | hexdump -C ${CERTSTORE}/privkeys/${COMPANY}_client_eccx08.der 84 | 85 | exit $? 86 | 87 | -------------------------------------------------------------------------------- /scripts/run_client.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set -x 4 | cd $(dirname $0) 5 | source ./common.sh 6 | 7 | BUNDLE=bundle 8 | 9 | if [ $USE_ENGINE = "0" ]; then 10 | export TARGET="client" 11 | else 12 | export TARGET="client_eccx08" 13 | fi 14 | 15 | if [ $USE_RSA = "0" ]; then 16 | RSA= 17 | else 18 | RSA=rsa_ 19 | if [ $USE_ENGINE = "0" ]; then 20 | KEYFORM= 21 | else 22 | KEYFORM="-keyform ENG" 23 | fi 24 | fi 25 | 26 | if [ $USE_ATMEL_CA = "0" ]; then 27 | export DEVICE_CERT_PEM=${CERTSTORE}/personal/${COMPANY}_${RSA}${TARGET}.crt 28 | export DEVICE_KEY=${CERTSTORE}/privkeys/${COMPANY}_${RSA}${TARGET}.key 29 | export SIGNER_PATH=${CERTSTORE}/trusted 30 | export SIGNER_BUNDLE=${CERTSTORE}/trusted/${COMPANY}_${RSA}${BUNDLE}.crt 31 | else 32 | export DEVICE_CERT_PEM=${DEVICE_CERT}.pem 33 | fi 34 | 35 | # Note this env var can be considered in OpenSSL s_client.c (see getenv) 36 | 37 | if [ -z "$SSL_CIPHER" ]; then 38 | #export SSL_CIPHER=ECDHE-ECDSA-AES128-GCM-SHA256 # define RSA to nothing on both client and server 39 | export SSL_CIPHER=ECDH-ECDSA-AES128-GCM-SHA256 # define RSA to nothing on both client and server 40 | #export SSL_CIPHER=ECDHE-RSA-AES128-SHA # define RSA=rsa_ on both client and server 41 | #export SSL_CIPHER=ECDHE-RSA-AES128-SHA256 # define RSA=rsa_ on both client and server 42 | fi 43 | 44 | #export SSL_CIPHER=ECDH-RSA-AES128-SHA256 # - dropped from SOW 45 | #export SSL_CIPHER=DH-RSA-AES256-SHA256 # requires TARGET="dh"on server side - dropped from SOW 46 | 47 | # Call TLS client 48 | 49 | set +e 50 | if [ $USE_EXAMPLE = "0" ]; then 51 | ${CMD} s_client ${ENGINE} -connect ${IP_ADDRESS}:${PORT_NUMBER} \ 52 | -verify 2 \ 53 | -cert ${DEVICE_CERT_PEM} ${KEYFORM} \ 54 | -key ${DEVICE_KEY} \ 55 | -CApath ${SIGNER_PATH} \ 56 | -CAfile ${SIGNER_BUNDLE} \ 57 | -cipher ${SSL_CIPHER} \ 58 | -no_ssl2 -no_ssl3 -no_tls1 -no_tls1_1 \ 59 | # -showcerts 60 | else 61 | ${CMD_EX} ${ENGINE_EX} \ 62 | -d 2 \ 63 | -c ${SSL_CIPHER} \ 64 | -p ${SIGNER_PATH} \ 65 | -b ${SIGNER_BUNDLE} \ 66 | -f ${DEVICE_CERT_PEM} \ 67 | -k ${DEVICE_KEY} \ 68 | -I ${IP_ADDRESS} \ 69 | -P ${PORT_NUMBER} 70 | fi 71 | STATUS=$? 72 | echo "EXIT STATUS: ${STATUS}" 73 | exit ${STATUS} 74 | -------------------------------------------------------------------------------- /scripts/run_eng_cmds: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd $(dirname $0) 3 | cd .. 4 | TREE_TOP=${PWD} 5 | CERTSTORE=$TREE_TOP/certstore 6 | SCRIPTS=$TREE_TOP/scripts 7 | BIN_DIR=$TREE_TOP/install_dir/bin 8 | EX_DIR=$TREE_TOP/client-server 9 | 10 | export LD_LIBRARY_PATH=$TREE_TOP/install_dir/lib 11 | export LD_PRELOAD=/lib/x86_64-linux-gnu/libpthread.so.0 12 | 13 | CMD_EX="${EX_DIR}/exchange-tls12" 14 | 15 | ${CMD_EX} -C $1 -e ateccx08 16 | #gdb --args ${CMD_EX} -C $1 -e ateccx08 17 | 18 | -------------------------------------------------------------------------------- /scripts/run_extract_certs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # If Atmel delievers the openssl key file then it is safer to use NEW_KEY=0 3 | # If the openssl key file is not delievered then this script may be called 4 | # with the NEW_KEY=1. If the device key in ATECC08 hardware wasn't locked 5 | # during provisioning then it may be destroyed. Verify that it is locked 6 | # before using NEW_KEY=1. 7 | # Type the same password 3 times once prompted. Any 4 characters are sufficient. 8 | 9 | set -e 10 | set -x 11 | cd $(dirname $0) 12 | source ./common.sh 13 | 14 | set +e 15 | ${CMD_EX} -E -e ateccx08 16 | #gdb --args ${CMD_EX} -E -e ateccx08 17 | 18 | # Convert certificates from DER to PEM format and bundle the CA 19 | ${CMD} x509 -inform DER -outform PEM -in ${SIGNER_CERT}.der -out ${SIGNER_CERT}.pem 20 | ${CMD} x509 -inform DER -outform PEM -in ${ROOT_CERT}.der -out ${ROOT_CERT}.pem 21 | cat ${SIGNER_CERT}.pem ${ROOT_CERT}.pem > ${SIGNER_BUNDLE} 22 | ${CMD} x509 -inform DER -outform PEM -in ${DEVICE_CERT}.der -out ${DEVICE_CERT}.pem 23 | 24 | if [ $NEW_KEY = "1" ]; then 25 | ${CMD} req ${KEYGEN_ENGINE} \ 26 | -new -newkey ec:${CERTSTORE}/prime256v1.pem \ 27 | -keyout ${DEVICE_KEY} \ 28 | -out ${DEVICE_CSR} \ 29 | -sha256 -config ${CERTSTORE}/openssl.cnf \ 30 | -subj '/C=US/ST=CA/CN=dummy_eccx08/' \ 31 | -verify 32 | 33 | ${CMD} ec \ 34 | -in ${DEVICE_KEY} \ 35 | -out ${DEVICE_KEY} 36 | 37 | fi 38 | 39 | STATUS=$? 40 | echo "EXIT STATUS: ${STATUS}" 41 | exit ${STATUS} 42 | 43 | -------------------------------------------------------------------------------- /scripts/run_server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set -x 4 | cd $(dirname $0) 5 | source ./common.sh 6 | 7 | BUNDLE=bundle 8 | 9 | if [ $USE_WWW = "0" ]; then 10 | WWW= 11 | else 12 | WWW=-www 13 | fi 14 | 15 | #TARGET="dh" 16 | if [ -z "$TARGET" ]; then 17 | if [ $USE_ENGINE = "0" ]; then 18 | TARGET="server" 19 | else 20 | TARGET="server_eccx08" 21 | fi 22 | fi 23 | 24 | if [ $USE_RSA = "0" ]; then 25 | RSA= 26 | else 27 | RSA=rsa_ 28 | if [ $USE_ENGINE = "0" ]; then 29 | KEYFORM= 30 | else 31 | KEYFORM="-keyform ENG" 32 | fi 33 | fi 34 | 35 | if [ $USE_ATMEL_CA = "0" ]; then 36 | export DEVICE_CERT_PEM=${CERTSTORE}/personal/${COMPANY}_${RSA}${TARGET}.crt 37 | export DEVICE_KEY=${CERTSTORE}/privkeys/${COMPANY}_${RSA}${TARGET}.key 38 | export SIGNER_PATH=${CERTSTORE}/trusted 39 | export SIGNER_BUNDLE=${CERTSTORE}/trusted/${COMPANY}_${RSA}${BUNDLE}.crt 40 | else 41 | export DEVICE_CERT_PEM=${DEVICE_CERT}.pem 42 | fi 43 | 44 | 45 | #No need to specify cipher on server - it will pick correct one 46 | #export SSL_CIPHER=ECDHE-ECDSA-AES128-GCM-SHA256 # define RSA to nothing on both client and server 47 | #export SSL_CIPHER=ECDH-ECDSA-AES128-GCM-SHA256 # define RSA to nothing on both client and server 48 | #export SSL_CIPHER=ECDHE-RSA-AES128-SHA # define RSA=rsa_ on both client and server 49 | #export SSL_CIPHER=ECDHE-RSA-AES128-SHA256 # define RSA=rsa_ on both client and server 50 | 51 | #export SSL_CIPHER=ECDH-RSA-AES128-SHA256 # - dropped from SOW 52 | #export SSL_CIPHER=DH-RSA-AES256-SHA256 # requires TARGET="dh" - not required by SOW 53 | 54 | # Call TLS server 55 | 56 | set +e 57 | if [ $USE_EXAMPLE = "0" ]; then 58 | ${CMD} s_server ${ENGINE} -accept ${PORT_NUMBER} -verify 2 \ 59 | -cert ${DEVICE_CERT_PEM} ${KEYFORM} \ 60 | -key ${DEVICE_KEY} \ 61 | -CApath ${SIGNER_PATH} \ 62 | -CAfile ${SIGNER_BUNDLE} \ 63 | -no_ssl2 -no_ssl3 -no_tls1 -no_tls1_1 ${WWW} 64 | else 65 | ${CMD_EX} -s ${ENGINE_EX} \ 66 | -d 2 \ 67 | -p ${SIGNER_PATH} \ 68 | -b ${SIGNER_BUNDLE} \ 69 | -f ${DEVICE_CERT_PEM} \ 70 | -k ${DEVICE_KEY} \ 71 | -I ${IP_ADDRESS} \ 72 | -P ${PORT_NUMBER} 73 | fi 74 | STATUS=$? 75 | echo "EXIT STATUS: ${STATUS}" 76 | exit ${STATUS} 77 | 78 | -------------------------------------------------------------------------------- /scripts/test_engine_post.py: -------------------------------------------------------------------------------- 1 | (client_status,server_status) = test_expect(client_cmd_lst,cmd_server,env_server,fname_log_server) 2 | --------------------------------------------------------------------------------