├── docs ├── static │ ├── custom.css │ ├── file.png │ ├── plus.png │ ├── minus.png │ ├── documentation_options.js │ ├── pygments.css │ ├── doctools.js │ ├── language_data.js │ └── alabaster.css ├── objects.inv ├── .buildinfo ├── sources │ ├── index.rst.txt │ ├── contributors.rst.txt │ ├── readme.rst.txt │ ├── usage_normal.rst.txt │ └── usage_arduino.rst.txt ├── Makefile ├── genindex.html ├── search.html ├── searchindex.js ├── contributors.html ├── index.html ├── readme.html └── usage_normal.html ├── sha ├── keywords.txt ├── library.properties ├── Makefile ├── examples │ ├── sha1 │ │ └── sha1.ino │ ├── sha1HMAC │ │ └── sha1HMAC.ino │ ├── sha256 │ │ └── sha256.ino │ └── sha256HMAC │ │ ├── sha256HMAC.ino │ │ └── platformio.ini ├── test │ ├── Makefile │ ├── test_sha1.c │ └── test_sha256.c ├── sha1 │ ├── basic.h │ ├── sha1.h │ ├── default.h │ ├── sha1.c │ ├── constants.c │ ├── types.c │ ├── types.h │ ├── hash.h │ ├── constants.h │ └── hash.c ├── config.h ├── backend.cpp ├── sha256 │ ├── sha256.h │ ├── default.h │ ├── sha256.c │ ├── types.c │ ├── constants.h │ ├── basic.h │ ├── types.h │ ├── hash.h │ ├── constants.c │ └── hash.c ├── sha1.h ├── sha256.h ├── sha1.cpp └── sha256.cpp ├── Makefile ├── doc ├── source │ ├── index.rst │ ├── contributors.rst │ ├── readme.rst │ ├── usage_normal.rst │ ├── conf.py │ └── usage_arduino.rst ├── Makefile └── github-make ├── .gitignore ├── library.json ├── contributors.yml ├── tools └── contributors.py └── README.rst /docs/static/custom.css: -------------------------------------------------------------------------------- 1 | /* This file intentionally left blank. */ 2 | -------------------------------------------------------------------------------- /docs/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daknuett/cryptosuite2/HEAD/docs/objects.inv -------------------------------------------------------------------------------- /docs/static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daknuett/cryptosuite2/HEAD/docs/static/file.png -------------------------------------------------------------------------------- /docs/static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daknuett/cryptosuite2/HEAD/docs/static/plus.png -------------------------------------------------------------------------------- /docs/static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daknuett/cryptosuite2/HEAD/docs/static/minus.png -------------------------------------------------------------------------------- /sha/keywords.txt: -------------------------------------------------------------------------------- 1 | Sha256 KEYWORD1 DATA_TYPE 2 | Sha1 KEYWORD1 DATA_TYPE 3 | 4 | init KEYWORD2 5 | result KEYWORD2 6 | initHmac KEYWORD2 7 | resultHmac KEYWORD2 8 | write KEYWORD2 9 | -------------------------------------------------------------------------------- /docs/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: f791f132dd10f7af8a5cbc2d23dac5f5 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /sha/library.properties: -------------------------------------------------------------------------------- 1 | name=cryptosuite2 2 | version=0.2.7 3 | author=Daniel Knuettel 4 | maintainer=Daniel Knuettel 5 | sentence=SHA256,SHA1 hashing and SHA256-HMAC,SHA1-HMAC 6 | paragraph= 7 | category=Data Processing 8 | url=https://github.com/daknuett/cryptosuite2 9 | architectures=* 10 | includes=sha256.h,sha1.h 11 | -------------------------------------------------------------------------------- /docs/static/documentation_options.js: -------------------------------------------------------------------------------- 1 | var DOCUMENTATION_OPTIONS = { 2 | URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), 3 | VERSION: '0.2.6', 4 | LANGUAGE: 'None', 5 | COLLAPSE_INDEX: false, 6 | BUILDER: 'html', 7 | FILE_SUFFIX: '.html', 8 | LINK_SUFFIX: '.html', 9 | HAS_SOURCE: true, 10 | SOURCELINK_SUFFIX: '.txt', 11 | NAVIGATION_WITH_KEYS: false 12 | }; -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: doc 3 | 4 | 5 | print-contributors: 6 | python3 tools/contributors.py print contributors.yml 7 | 8 | create-contributors: 9 | python3 tools/contributors.py create contributors.yml doc/source/contributors.rst 10 | 11 | doc: create-contributors 12 | cd doc && make html 13 | 14 | tests: 15 | cd sha/test && make -s 16 | cd sha/test && make clean 17 | 18 | zip: 19 | - rm sha.zip 20 | - cd sha && make clean 21 | zip sha.zip sha/* 22 | zip sha.zip sha/*/* 23 | zip sha.zip sha/*/*/* 24 | -------------------------------------------------------------------------------- /doc/source/index.rst: -------------------------------------------------------------------------------- 1 | .. cryptosuite2 documentation master file, created by 2 | sphinx-quickstart on Sun Feb 25 22:30:55 2018. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to cryptosuite2's documentation! 7 | ======================================== 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | :caption: Contents: 12 | 13 | readme 14 | usage_arduino 15 | usage_normal 16 | contributors 17 | 18 | 19 | 20 | Indices and tables 21 | ================== 22 | 23 | * :ref:`genindex` 24 | * :ref:`search` 25 | -------------------------------------------------------------------------------- /docs/sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | .. cryptosuite2 documentation master file, created by 2 | sphinx-quickstart on Sun Feb 25 22:30:55 2018. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to cryptosuite2's documentation! 7 | ======================================== 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | :caption: Contents: 12 | 13 | readme 14 | usage_arduino 15 | usage_normal 16 | contributors 17 | 18 | 19 | 20 | Indices and tables 21 | ================== 22 | 23 | * :ref:`genindex` 24 | * :ref:`search` 25 | -------------------------------------------------------------------------------- /sha/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAG= -O 3 | sha256_objects= sha256/types.o sha256/hash.o sha256/constants.o sha256/sha256.o 4 | sha1_objects= sha1/types.o sha1/hash.o sha1/constants.o sha1/sha1.o 5 | 6 | all: $(sha256_objects) $(sha1_objects) 7 | 8 | %.o: %.c 9 | $(CC) $< $(CFLAG) -c -o $@ 10 | 11 | test/test_sha256: $(sha256_objects) test/test_sha256.c 12 | $(CC) test/test_sha256.c $(CFLAG) -I. $(sha256_objects) -o test/test_sha256 13 | 14 | test/test_sha1: $(sha1_objects) test/test_sha1.c 15 | $(CC) test/test_sha1.c $(CFLAG) -I. $(sha1_objects) -o test/test_sha1 16 | 17 | clean: 18 | -rm $(sha256_objects) 19 | -rm $(sha1_objects) 20 | -rm test/test_sha256 21 | -rm test/test_sha1 22 | 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | # PlatformIO 55 | .pio 56 | /platformio.ini 57 | 58 | # VSCode 59 | .vscode 60 | .clang_complete 61 | .gcc-flags.json 62 | -------------------------------------------------------------------------------- /sha/examples/sha1/sha1.ino: -------------------------------------------------------------------------------- 1 | #include "sha1.h" 2 | 3 | // read data from the serial interface and print the 4 | // hash to the serial 5 | 6 | const char hexMap[] PROGMEM = "0123456789abcdef"; 7 | void setup(void) 8 | { 9 | Serial.begin(9600); 10 | } 11 | 12 | void loop(void) 13 | { 14 | if(!Serial.available()) 15 | { 16 | return; 17 | } 18 | Sha1.init(); 19 | 20 | Sha1.print(Serial.read()); 21 | 22 | uint8_t * result = Sha1.result(); 23 | 24 | Serial.print("Hash:\n"); 25 | 26 | for (int i = 0; i < 20; i++) { 27 | Serial.print((char)pgm_read_byte(hexMap + (result[i] >> 4))); 28 | Serial.print((char)pgm_read_byte(hexMap + (result[i] & 0xf))); 29 | } 30 | Serial.print("\n"); 31 | } 32 | -------------------------------------------------------------------------------- /sha/examples/sha1HMAC/sha1HMAC.ino: -------------------------------------------------------------------------------- 1 | #include "sha1.h" 2 | 3 | const char hexMap[] PROGMEM = "0123456789abcdef"; 4 | void setup(void) 5 | { 6 | Serial.begin(9600); 7 | 8 | // this is actually the RFC4231 4.3 test 9 | 10 | Sha1.initHmac((uint8_t * ) "Jefe", 4); 11 | Sha1.print("what do ya want for nothing?"); 12 | uint8_t * result = Sha1.resultHmac(); 13 | 14 | Serial.println("Expect: effcdf6ae5eb2fa2d27416d5f184df9c259a7c79"); 15 | Serial.print( "Got : "); 16 | for (int i = 0; i < 20; i++) { 17 | Serial.print((char)pgm_read_byte(hexMap + (result[i] >> 4))); 18 | Serial.print((char)pgm_read_byte(hexMap + (result[i] & 0xf))); 19 | } 20 | Serial.print("\n"); 21 | } 22 | 23 | 24 | void loop(void) 25 | {} 26 | -------------------------------------------------------------------------------- /sha/examples/sha256/sha256.ino: -------------------------------------------------------------------------------- 1 | #include "sha256.h" 2 | 3 | // read data from the serial interface and print the 4 | // hash to the serial 5 | 6 | const char hexMap[] PROGMEM = "0123456789abcdef"; 7 | void setup(void) 8 | { 9 | Serial.begin(9600); 10 | } 11 | 12 | void loop(void) 13 | { 14 | if(!Serial.available()) 15 | { 16 | return; 17 | } 18 | Sha256.init(); 19 | 20 | Sha256.print(Serial.read()); 21 | 22 | uint8_t * result = Sha256.result(); 23 | 24 | Serial.print("Hash:\n"); 25 | 26 | for (int i = 0; i < 32; i++) { 27 | Serial.print((char)pgm_read_byte(hexMap + (result[i] >> 4))); 28 | Serial.print((char)pgm_read_byte(hexMap + (result[i] & 0xf))); 29 | } 30 | Serial.print("\n"); 31 | } 32 | -------------------------------------------------------------------------------- /sha/examples/sha256HMAC/sha256HMAC.ino: -------------------------------------------------------------------------------- 1 | #include "sha256.h" 2 | 3 | const char hexMap[] PROGMEM = "0123456789abcdef"; 4 | void setup(void) 5 | { 6 | Serial.begin(115200); 7 | 8 | // this is actually the RFC4231 4.3 test 9 | 10 | Sha256.initHmac((uint8_t * ) "Jefe", 4); 11 | Sha256.print("what do ya want for nothing?"); 12 | uint8_t * result = Sha256.resultHmac(); 13 | 14 | Serial.println("Expect: 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843"); 15 | Serial.print( "Got : "); 16 | for (int i = 0; i < 32; i++) { 17 | Serial.print((char)pgm_read_byte(hexMap + (result[i] >> 4))); 18 | Serial.print((char)pgm_read_byte(hexMap + (result[i] & 0xf))); 19 | } 20 | Serial.print("\n"); 21 | } 22 | 23 | 24 | void loop(void) 25 | {} 26 | -------------------------------------------------------------------------------- /sha/test/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | clflag= -g -c 3 | 4 | lib_objects=../sha1/constants.o \ 5 | ../sha1/hash.o \ 6 | ../sha1/sha1.o \ 7 | ../sha1/types.o \ 8 | ../sha256/constants.o \ 9 | ../sha256/hash.o \ 10 | ../sha256/sha256.o \ 11 | ../sha256/types.o 12 | 13 | test_objects= test_sha1.o test_sha256.o 14 | tests=test_sha1 test_sha256 15 | 16 | all: clean $(tests) 17 | echo "############# ALL TESTS PASSED ##############" 18 | 19 | %.o:%.c 20 | $(CC) $(clflag) -o $@ $< 21 | 22 | test_sha1: $(test_objects) $(lib_objects) 23 | $(CC) $(cflag) $(lib_objects) test_sha1.o -o test_sha1 24 | ./test_sha1 25 | rm test_sha1 26 | 27 | test_sha256: $(test_objects) $(lib_objects) 28 | $(CC) $(cflag) $(lib_objects) test_sha256.o -o test_sha256 29 | ./test_sha256 30 | rm test_sha256 31 | 32 | clean: 33 | -rm $(lib_objects) 34 | -rm $(test_objects) 35 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cryptosuite2", 3 | "version": "0.2.7", 4 | "description": "Arduino/Generic C library for SHA256, SHA1 hashing and SHA256-HMAC, SHA1-HMAC", 5 | "keywords": "crypto, sha256, sha265-hmac, hash, sha1, sha1-hmac", 6 | "platforms": "*", 7 | "frameworks": "arduino", 8 | "authors": [ 9 | ], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/daknuett/cryptosuite2.git", 13 | "branch": "master" 14 | }, 15 | "export": { 16 | "include": [ 17 | "LICENSE", 18 | "library.json", 19 | "README.md", 20 | "sha/*", 21 | "sha/examples/*" 22 | ] 23 | }, 24 | "examples": [ "sha/examples/*/*.ino" ], 25 | "build": { 26 | "srcDir": "sha/", 27 | "srcFilter": [ 28 | "+<*.c>", 29 | "+<*.cpp>", 30 | "+<*.h>" 31 | ], 32 | "libLDFMode": "deep+" 33 | }, 34 | "dependencies": [ 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = cryptosuite2 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | @echo "Copying files to /docs..." 22 | if [ -e ../docs ] ;then rm -rf ../docs;fi 23 | cp -r $(BUILDDIR)/html ../docs 24 | @echo "done" 25 | @echo "calling postbuild..." 26 | cp github-make ../docs/Makefile 27 | cd ../docs && make github 28 | @echo "done" 29 | -------------------------------------------------------------------------------- /doc/source/contributors.rst: -------------------------------------------------------------------------------- 1 | Contributors 2 | ************ 3 | 4 | 5 | 6 | **Daniel Knüttel** 7 | 8 | `daniel.knuettel@daknuett.eu `_ 9 | 10 | - *2018* Initial version of the library 11 | - *2018* Initial version of the C++ Wrapper 12 | - *2018* SHA1 implementation and C++ Wrapper for SHA1 13 | - *2019* Some bug fixes & some usability enhancments 14 | **per1234** 15 | 16 | `None `_ 17 | 18 | - *2018* Add keywords.txt 19 | - *2018* Add library.properties 20 | - *2019* Move example sketches to appropriately named folders 21 | **JoshHeaney** 22 | 23 | `None `_ 24 | 25 | - *2019* SHA256 and SHA1 HMAC example digest fix. 26 | **nagimov** 27 | 28 | `None `_ 29 | 30 | - *2020* fix expected hmac256 test output 31 | - *2020* Moved some data from RAM to flash in the examples 32 | **Christoph Honal** 33 | 34 | `None `_ 35 | 36 | - *2021* Remove test sketches from the regular build on PlatformIO 37 | - *2021* Fix out-of-bounds memory access in SHA1 hashing 38 | -------------------------------------------------------------------------------- /docs/sources/contributors.rst.txt: -------------------------------------------------------------------------------- 1 | Contributors 2 | ************ 3 | 4 | 5 | 6 | **Daniel Knüttel** 7 | 8 | `daniel.knuettel@daknuett.eu `_ 9 | 10 | - *2018* Initial version of the library 11 | - *2018* Initial version of the C++ Wrapper 12 | - *2018* SHA1 implementation and C++ Wrapper for SHA1 13 | - *2019* Some bug fixes & some usability enhancments 14 | **per1234** 15 | 16 | `None `_ 17 | 18 | - *2018* Add keywords.txt 19 | - *2018* Add library.properties 20 | - *2019* Move example sketches to appropriately named folders 21 | **JoshHeaney** 22 | 23 | `None `_ 24 | 25 | - *2019* SHA256 and SHA1 HMAC example digest fix. 26 | **nagimov** 27 | 28 | `None `_ 29 | 30 | - *2020* fix expected hmac256 test output 31 | - *2020* Moved some data from RAM to flash in the examples 32 | **Christoph Honal** 33 | 34 | `None `_ 35 | 36 | - *2021* Remove test sketches from the regular build on PlatformIO 37 | - *2021* Fix out-of-bounds memory access in SHA1 hashing 38 | -------------------------------------------------------------------------------- /doc/github-make: -------------------------------------------------------------------------------- 1 | 2 | # Using github-pages with sphinx-build documentation 3 | # is a pain in the ass. 4 | # This makefile solves the problems quickly. 5 | # just add these lines to the "html" rule that sphinx-quickstart 6 | # generated and save this file with the name github-make in 7 | # the folder that contains your sphinx-Makefile: 8 | # 9 | # @echo "Copying files to /docs..." 10 | # if [ -e ../docs ] ;then rm -rf ../docs;fi 11 | # cp -r $(BUILDDIR)/html ../docs 12 | # @echo "done" 13 | # @echo "calling postbuild..." 14 | # cp github-make ../docs/Makefile 15 | # cd ../docs && make github 16 | # @echo "done" 17 | # 18 | # then the command "make html" will build a 19 | # site suiting github-pages in ../docs 20 | 21 | 22 | # ~Makefile~ 23 | github: 24 | find . -name \*.html -exec sed -i -- 's/_static/static/g' {} \; 25 | find . -name \*.html -exec sed -i -- 's/_sources/sources/g' {} \; 26 | find . -name \*.html -exec sed -i -- 's/_images/images/g' {} \; 27 | find . -name \*.html -exec sed -i -- 's/_modules/modules/g' {} \; 28 | if [ -e _static/ ] ; then mv _static/ ./static/; fi 29 | if [ -e _sources/ ] ; then mv _sources/ ./sources/; fi 30 | if [ -e _images/ ] ; then mv _images/ ./images/; fi 31 | if [ -e _modules/ ] ; then mv _modules/ ./modules/; fi 32 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | 2 | # Using github-pages with sphinx-build documentation 3 | # is a pain in the ass. 4 | # This makefile solves the problems quickly. 5 | # just add these lines to the "html" rule that sphinx-quickstart 6 | # generated and save this file with the name github-make in 7 | # the folder that contains your sphinx-Makefile: 8 | # 9 | # @echo "Copying files to /docs..." 10 | # if [ -e ../docs ] ;then rm -rf ../docs;fi 11 | # cp -r $(BUILDDIR)/html ../docs 12 | # @echo "done" 13 | # @echo "calling postbuild..." 14 | # cp github-make ../docs/Makefile 15 | # cd ../docs && make github 16 | # @echo "done" 17 | # 18 | # then the command "make html" will build a 19 | # site suiting github-pages in ../docs 20 | 21 | 22 | # ~Makefile~ 23 | github: 24 | find . -name \*.html -exec sed -i -- 's/_static/static/g' {} \; 25 | find . -name \*.html -exec sed -i -- 's/_sources/sources/g' {} \; 26 | find . -name \*.html -exec sed -i -- 's/_images/images/g' {} \; 27 | find . -name \*.html -exec sed -i -- 's/_modules/modules/g' {} \; 28 | if [ -e _static/ ] ; then mv _static/ ./static/; fi 29 | if [ -e _sources/ ] ; then mv _sources/ ./sources/; fi 30 | if [ -e _images/ ] ; then mv _images/ ./images/; fi 31 | if [ -e _modules/ ] ; then mv _modules/ ./modules/; fi 32 | -------------------------------------------------------------------------------- /sha/sha1/basic.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #ifndef SHA1_BASIC_H_ 18 | #define SHA1_BASIC_H_ 19 | 20 | #include "default.h" 21 | #include 22 | 23 | #define sha1_rotl(bits,word) (((word) << (bits)) | ((word) >> (32 - (bits)))) 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /sha/config.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | 18 | 19 | // include the module config first, 20 | // overwrite it in the arduino interface config. 21 | #include "sha256/default.h" 22 | #include "sha1/default.h" 23 | 24 | #ifndef SHA_CONFIG_H_ 25 | #define SHA_CONFIG_H_ 26 | 27 | // No changes yet. 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /sha/backend.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "config.h" 18 | 19 | #ifndef SHA256_DISABLED 20 | #include "sha256/constants.c" 21 | #include "sha256/hash.c" 22 | #include "sha256/types.c" 23 | #include "sha256/sha256.c" 24 | #endif 25 | 26 | #ifndef SHA1_DISABLED 27 | #include "sha1/constants.c" 28 | #include "sha1/hash.c" 29 | #include "sha1/types.c" 30 | #include "sha1/sha1.c" 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /sha/sha1/sha1.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #ifndef SHA1_SHA1_H_ 18 | #define SHA1_SHA1_H_ 19 | 20 | #include "default.h" 21 | #include "types.h" 22 | #include "hash.h" 23 | #include 24 | #include 25 | 26 | #ifdef __AVR__ 27 | #define ssize_t long int 28 | #endif 29 | 30 | ssize_t sha1_hasher_write(sha1_hasher_t hasher, const void * buf, size_t count); 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /sha/sha256/sha256.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #ifndef SHA256_SHA256_H_ 18 | #define SHA256_SHA256_H_ 19 | 20 | #include "default.h" 21 | #include "types.h" 22 | #include "hash.h" 23 | #include 24 | #include 25 | 26 | #ifdef __AVR__ 27 | #define ssize_t long int 28 | #endif 29 | 30 | ssize_t sha256_hasher_write(sha256_hasher_t hasher, const void * buf, size_t count); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /contributors.yml: -------------------------------------------------------------------------------- 1 | - name: Daniel Knüttel 2 | email: daniel.knuettel@daknuett.eu 3 | contributions: 4 | - year: 2018 5 | descr: Initial version of the library 6 | - year: 2018 7 | descr: Initial version of the C++ Wrapper 8 | - year: 2018 9 | descr: SHA1 implementation and C++ Wrapper for SHA1 10 | - year: 2019 11 | descr: Some bug fixes & some usability enhancments 12 | - name: per1234 13 | email: 14 | contributions: 15 | - year: 2018 16 | descr: Add keywords.txt 17 | - year: 2018 18 | descr: Add library.properties 19 | - year: 2019 20 | descr: Move example sketches to appropriately named folders 21 | - name: JoshHeaney 22 | email: 23 | contributions: 24 | - year: 2019 25 | descr: SHA256 and SHA1 HMAC example digest fix. 26 | - name: nagimov 27 | email: 28 | contributions: 29 | - year: 2020 30 | descr: fix expected hmac256 test output 31 | - year: 2020 32 | descr: Moved some data from RAM to flash in the examples 33 | - name: Christoph Honal 34 | email: 35 | contributions: 36 | - year: 2021 37 | descr: Remove test sketches from the regular build on PlatformIO 38 | - year: 2021 39 | descr: Fix out-of-bounds memory access in SHA1 hashing 40 | - name: Anthony Aufdenkampe 41 | email: aaufdenkampe@limno.com 42 | contributions: 43 | - year: 2022 44 | descr: Improve use with PlatformIO via `library.json` tweaks and example `plaformio.ini` files 45 | -------------------------------------------------------------------------------- /sha/sha1/default.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | // This file is the module config header 18 | // when the arduino interface is NOT used. 19 | // 20 | // If you want to use the library with Arduino, 21 | // edit sha/config.h. If you use a proper build system, 22 | // use this config file for sha1 and sha/sha256/default.h 23 | // for sha256. 24 | #ifndef SHA1_DEFAULT_H_ 25 | #define SHA1_DEFAULT_H_ 26 | 27 | #define SHA1_ENABLE_HMAC 28 | 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /sha/sha1/sha1.c: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "sha1.h" 18 | 19 | ssize_t sha1_hasher_write(sha1_hasher_t hasher, const void * buf, size_t count) 20 | { 21 | size_t written = 0; 22 | int chk_result; 23 | char c; 24 | while(written < count) 25 | { 26 | c = ((char *) buf)[written]; 27 | chk_result = sha1_hasher_putc(hasher, c); 28 | if(chk_result != c) 29 | { 30 | return -1; 31 | } 32 | written++; 33 | } 34 | return written; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /sha/sha256/default.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | 18 | // This file is the module config header 19 | // when the arduino interface is NOT used. 20 | // 21 | // If you want to use the library with Arduino, 22 | // edit sha/config.h. If you use a proper build system, 23 | // use this config file for sha256 and sha/sha1/default.h 24 | // for sha1. 25 | #ifndef SHA256_DEFAULT_H_ 26 | #define SHA256_DEFAULT_H_ 27 | 28 | #define SHA256_ENABLE_HMAC 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /sha/sha256/sha256.c: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "sha256.h" 18 | 19 | ssize_t sha256_hasher_write(sha256_hasher_t hasher, const void * buf, size_t count) 20 | { 21 | size_t written = 0; 22 | int chk_result; 23 | char c; 24 | while(written < count) 25 | { 26 | c = ((char *) buf)[written]; 27 | chk_result = sha256_hasher_putc(hasher, c); 28 | if(chk_result != c) 29 | { 30 | return -1; 31 | } 32 | written++; 33 | } 34 | return written; 35 | } 36 | -------------------------------------------------------------------------------- /sha/sha1/constants.c: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "constants.h" 18 | 19 | #ifndef __AVR__ 20 | const uint32_t sha1_init_state[SHA1_HASH_LEN / 4] = 21 | #else 22 | const uint32_t sha1_init_state[SHA1_HASH_LEN / 4] PROGMEM = 23 | #endif 24 | { 25 | 0x67452301, 0xefcdab89, 0x98badcfe, 26 | 0x10325476, 0xc3d2e1f0 27 | }; 28 | 29 | #ifndef __AVR__ 30 | const uint32_t sha1_constants[4] = 31 | #else 32 | const uint32_t sha1_constants[4] PROGMEM = 33 | #endif 34 | { 35 | 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6 36 | }; 37 | 38 | 39 | -------------------------------------------------------------------------------- /sha/sha1.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "config.h" 18 | 19 | #ifndef Sha1_h 20 | #define Sha1_h 21 | 22 | #include 23 | #include "Print.h" 24 | #include "sha1/sha1.h" 25 | 26 | #ifndef SHA1_DISABLE_WRAPPER 27 | class Sha1Wrapper : public Print 28 | { 29 | public: 30 | void init(void); 31 | uint8_t * result(void); 32 | #ifdef SHA1_ENABLE_HMAC 33 | void initHmac(const uint8_t * secret, unsigned int secretLength); 34 | uint8_t * resultHmac(void); 35 | #endif 36 | virtual size_t write(uint8_t); 37 | using Print::write; 38 | private: 39 | struct sha1_hasher_s _hasher; 40 | 41 | }; 42 | 43 | extern Sha1Wrapper Sha1; 44 | #endif 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /sha/sha256.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "config.h" 18 | 19 | #ifndef Sha256_h 20 | #define Sha256_h 21 | 22 | #include 23 | #include "Print.h" 24 | #include "sha256/sha256.h" 25 | 26 | #ifndef SHA256_DISABLE_WRAPPER 27 | class Sha256Wrapper : public Print 28 | { 29 | public: 30 | void init(void); 31 | uint8_t * result(void); 32 | #ifdef SHA256_ENABLE_HMAC 33 | void initHmac(const uint8_t * secret, unsigned int secretLength); 34 | uint8_t * resultHmac(void); 35 | #endif 36 | virtual size_t write(uint8_t); 37 | using Print::write; 38 | private: 39 | struct sha256_hasher_s _hasher; 40 | 41 | }; 42 | 43 | extern Sha256Wrapper Sha256; 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /sha/examples/sha256HMAC/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Please visit documentation for options and examples 4 | ; http://docs.platformio.org/page/projectconf.html 5 | ; 6 | ; COPY THIS TO THE PROJECT ROOT DIRECTORY 7 | 8 | [platformio] 9 | description = cryptosuite2 ini for library development 10 | default_envs = mayfly 11 | include_dir = sha ; path to this project's header files. See http://docs.platformio.org/en/latest/projectconf/section_platformio.html#include-dir 12 | src_dir = sha/examples/sha256HMAC 13 | 14 | [env] 15 | monitor_speed = 115200 16 | framework = arduino 17 | lib_ldf_mode = deep+ 18 | ; To your `lib_extra_dirs` directory, you need to add "." (meaning the current project folder) , not "src". 19 | ; Without a "." it's searching for the library files in a src subdirectory of the lib_extra_dirs directory, so it doesn't find the library files because they're in ./src not ./src/src. 20 | ; https://community.platformio.org/t/finding-libraries-in-subfolders-submodules-on-git/1508/12 21 | lib_extra_dirs = . 22 | ; Then you need to explicitly ignore all of the other library containing folders so they don't get compiled twice (which would also cause issues): 23 | lib_ignore = 24 | .git 25 | .pio 26 | .vscode 27 | doc 28 | docs 29 | sha/examples 30 | tools 31 | ; lib_deps = 32 | ; All these src_filter flags aren’t necessary this way because it’s actually 33 | ; finding the library.json in the main directory and that is already telling the compiler it needs those subdirectories. They don’t hurt, though. 34 | src_filter = 35 | +<*> 36 | +<../../sha> 37 | ; +<../../sha/sha1> 38 | ; +<../../sha/sha256> 39 | ; build_flags = 40 | 41 | [env:mayfly] 42 | ; upload_port = COM4 43 | ; monitor_port = COM4 44 | board = mayfly 45 | platform = atmelavr 46 | lib_ignore = 47 | ${env.lib_ignore} 48 | RTCZero 49 | build_flags = 50 | ${env.build_flags} 51 | ; upload_flags = 52 | ; -V 53 | lib_deps = 54 | ${env.lib_deps} 55 | -------------------------------------------------------------------------------- /sha/sha1.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "sha1.h" 18 | 19 | #ifndef SHA1_DISABLED 20 | #ifndef SHA1_DISABLE_WRAPPER 21 | void Sha1Wrapper::init(void) 22 | { 23 | sha1_hasher_init(&_hasher); 24 | } 25 | 26 | #ifdef SHA1_ENABLE_HMAC 27 | void Sha1Wrapper::initHmac(const uint8_t * secret, unsigned int secretLength) 28 | { 29 | sha1_hasher_init_hmac(&_hasher, secret, secretLength); 30 | } 31 | 32 | uint8_t * Sha1Wrapper::resultHmac(void) 33 | { 34 | return sha1_hasher_gethmac(&_hasher); 35 | } 36 | #endif 37 | 38 | 39 | size_t Sha1Wrapper::write(uint8_t byte) 40 | { 41 | if(sha1_hasher_putc(&_hasher, byte) == byte) 42 | { 43 | return 1; 44 | } 45 | return 0; 46 | } 47 | 48 | uint8_t * Sha1Wrapper::result(void) 49 | { 50 | return sha1_hasher_gethash(&_hasher); 51 | } 52 | 53 | Sha1Wrapper Sha1; 54 | 55 | #endif 56 | #endif 57 | -------------------------------------------------------------------------------- /sha/sha256.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "sha256.h" 18 | 19 | #ifndef SHA256_DISABLED 20 | #ifndef SHA256_DISABLE_WRAPPER 21 | void Sha256Wrapper::init(void) 22 | { 23 | sha256_hasher_init(&_hasher); 24 | } 25 | 26 | #ifdef SHA256_ENABLE_HMAC 27 | void Sha256Wrapper::initHmac(const uint8_t * secret, unsigned int secretLength) 28 | { 29 | sha256_hasher_init_hmac(&_hasher, secret, secretLength); 30 | } 31 | 32 | uint8_t * Sha256Wrapper::resultHmac(void) 33 | { 34 | return sha256_hasher_gethmac(&_hasher); 35 | } 36 | #endif 37 | 38 | 39 | size_t Sha256Wrapper::write(uint8_t byte) 40 | { 41 | if(sha256_hasher_putc(&_hasher, byte) == byte) 42 | { 43 | return 1; 44 | } 45 | return 0; 46 | } 47 | 48 | uint8_t * Sha256Wrapper::result(void) 49 | { 50 | return sha256_hasher_gethash(&_hasher); 51 | } 52 | 53 | Sha256Wrapper Sha256; 54 | 55 | #endif 56 | #endif 57 | -------------------------------------------------------------------------------- /sha/sha1/types.c: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "types.h" 18 | #include 19 | #include 20 | #include "constants.h" 21 | 22 | sha1_hasher_t sha1_hasher_new(void) 23 | { 24 | sha1_hasher_t hasher = (sha1_hasher_t) malloc(sizeof(struct sha1_hasher_s)); 25 | if(!hasher) 26 | { 27 | return NULL; 28 | } 29 | sha1_hasher_init(hasher); 30 | return hasher; 31 | } 32 | 33 | void sha1_hasher_init(sha1_hasher_t hasher) 34 | { 35 | #ifdef __AVR__ 36 | int i; 37 | for(i = 0; i < SHA1_HASH_LEN / 4; i++) 38 | { 39 | hasher->state.words[i] = pgm_read_dword(sha1_init_state + i); 40 | } 41 | #else 42 | memcpy(hasher->state.words, sha1_init_state, SHA1_HASH_LEN); 43 | #endif 44 | hasher->block_offset = 0; 45 | hasher->total_bytes = 0; 46 | hasher->_lock = 0; 47 | 48 | } 49 | 50 | 51 | void sha1_hasher_del(sha1_hasher_t hasher) 52 | { 53 | free(hasher); 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /tools/contributors.py: -------------------------------------------------------------------------------- 1 | import docopt, yaml, sys 2 | from yaml import Loader 3 | 4 | usage = \ 5 | ''' 6 | Usage: 7 | contributors.py print FILE [--quiet] 8 | contributors.py create FILE RST 9 | 10 | Options: 11 | --quiet do not print to stdout 12 | 13 | ''' 14 | 15 | if( __name__ == "__main__"): 16 | args = docopt.docopt(usage) 17 | 18 | if(args["print"]): 19 | try: 20 | f = open(args["FILE"]) 21 | except Exception as e: 22 | print(e, file = sys.stdout) 23 | sys.exit(1) 24 | 25 | try: 26 | data = yaml.load(f, Loader) 27 | except Exception as e: 28 | print(e, file = sys.stdout) 29 | sys.exit(1) 30 | 31 | for contributor in data: 32 | try: 33 | string = "{name} (mailto:{email})".format(**contributor) 34 | contributions = "".join(["\t[{year}] {descr}\n".format(**c) for c in contributor["contributions"]]) 35 | except Exception as e: 36 | print(e, file = sys.stdout) 37 | print("Dataset was:", file = sys.stdout) 38 | print(contributor, file = sys.stdout) 39 | sys.exit(1) 40 | if(not args["--quiet"]): 41 | print(string) 42 | print(contributions) 43 | 44 | sys.exit(0) 45 | 46 | if(args["create"]): 47 | try: 48 | f = open(args["FILE"]) 49 | except Exception as e: 50 | print(e, file = sys.stdout) 51 | sys.exit(1) 52 | 53 | try: 54 | data = yaml.load(f, Loader) 55 | except Exception as e: 56 | print(e, file = sys.stdout) 57 | sys.exit(1) 58 | 59 | 60 | try: 61 | fout = open(args["RST"], "w") 62 | except Exception as e: 63 | print(e, file = sys.stdout) 64 | sys.exit(1) 65 | 66 | heading = "Contributors" 67 | print(heading, file = fout) 68 | print("*" * len(heading), file = fout) 69 | print("\n\n", file = fout) 70 | 71 | for contributor in data: 72 | print("**{name}** \n\n\t `{email} `_".format(**contributor), file = fout) 73 | print(file = fout) 74 | for contribution in contributor["contributions"]: 75 | print("\t- *{year}* {descr}".format(**contribution), file = fout) 76 | 77 | 78 | -------------------------------------------------------------------------------- /sha/sha256/types.c: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "types.h" 18 | #include 19 | #include 20 | #include "constants.h" 21 | 22 | sha256_hasher_t sha256_hasher_new(void) 23 | { 24 | sha256_hasher_t hasher = (sha256_hasher_t) malloc(sizeof(struct sha256_hasher_s)); 25 | if(!hasher) 26 | { 27 | return NULL; 28 | } 29 | sha256_hasher_init(hasher); 30 | return hasher; 31 | } 32 | 33 | void sha256_hasher_init(sha256_hasher_t hasher) 34 | { 35 | #ifdef __AVR__ 36 | int i; 37 | for(i = 0; i < SHA256_HASH_LEN / 4; i++) 38 | { 39 | hasher->state.words[i] = pgm_read_dword(sha256_init_state + i); 40 | } 41 | #else 42 | memcpy(hasher->state.words, sha256_init_state, SHA256_HASH_LEN); 43 | #endif 44 | hasher->block_offset = 0; 45 | hasher->total_bytes = 0; 46 | hasher->_lock = 0; 47 | 48 | } 49 | 50 | 51 | void sha256_hasher_del(sha256_hasher_t hasher) 52 | { 53 | free(hasher); 54 | } 55 | 56 | -------------------------------------------------------------------------------- /sha/sha256/constants.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #ifndef SHA256_CONSTANTS_H_ 18 | #define SHA256_CONSTANTS_H_ 19 | 20 | #include "default.h" 21 | #include 22 | 23 | #define SHA256_BLOCK_LEN 64 24 | #define SHA256_HASH_LEN 32 25 | 26 | #ifdef __AVR__ 27 | #include 28 | #endif 29 | 30 | #ifndef __AVR__ 31 | extern const uint32_t sha256_init_state[SHA256_HASH_LEN / 4]; 32 | #else 33 | extern const uint32_t sha256_init_state[SHA256_HASH_LEN / 4] PROGMEM; 34 | #endif 35 | 36 | #ifndef __AVR__ 37 | extern const uint32_t sha256_constants[64]; 38 | #else 39 | extern const uint32_t sha256_constants[64] PROGMEM; 40 | #endif 41 | 42 | #ifdef __AVR__ 43 | #define sha256_k(i) pgm_read_dword(sha256_constants + i) 44 | #else 45 | #define sha256_k(i) sha256_constants[i] 46 | #endif 47 | 48 | 49 | #ifdef SHA256_ENABLE_HMAC 50 | #define SHA256_HMAC_IPAD 0x36 51 | #define SHA256_HMAC_OPAD 0x5c 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Cryptosuite2 2 | ************ 3 | 4 | .. contents:: 5 | 6 | Links 7 | ===== 8 | 9 | - The `code is here `_. 10 | - The `docs are here `_. 11 | 12 | 13 | 14 | What Is Cryptosuite2? 15 | ===================== 16 | 17 | Cryptosuite2 is a (more or less) drop in replacement for 18 | https://github.com/Cathedrow/Cryptosuite. It currently 19 | provides SHA256 and HMAC-SHA256. 20 | 21 | Install 22 | ======= 23 | 24 | Using the ZIP for Arduino 25 | ------------------------- 26 | 27 | Download the latest ZIP release from `the release page `_ 28 | and install it using the Arduino IDE. 29 | 30 | Manually 31 | -------- 32 | 33 | - Download the library. 34 | - Copy ``cryptosuite2/sha`` to ``~/sketchbook/libraries`` 35 | (``cp -rv cryptosuite2/sha ~/sketchbook/libraries``) 36 | or ``~/Arduino/libraries`` (``cp -rv cryptosuite2/sha ~/Arduino/libraries``) 37 | 38 | Usage 39 | ===== 40 | 41 | Take a look at the `docs 42 | `_. 43 | 44 | 45 | Gotchas 46 | ------- 47 | 48 | - Once ``Sha256.result()`` or ``Sha256.resultHmac()`` 49 | (or ``sha256_hasher_gethash()``, 50 | ``sha256_hasher_gethmac()``, ``sha256_hasher_pad()``) 51 | have been invoked ``Sha256.init()`` (or 52 | ``sha256_hasher_init()``) must be invoked! 53 | - The same thing applies for ``Sha1`` and ``sha1_*``. 54 | 55 | Todos 56 | ===== 57 | 58 | You can ask for further features, but right now it seems 59 | like all the required stuff is running. 60 | 61 | Contributing 62 | ============ 63 | 64 | Contributions are welcome! 65 | 66 | Just add yourself in the ``contributors.yml`` file and send 67 | a pull request. 68 | 69 | All contributions must be licensed under the GNU GPLv3. This 70 | is just because keeping track of various licenses is a pain 71 | in the ass. 72 | 73 | Support 74 | ======= 75 | 76 | I can give you some assistance in general, but do not expect 77 | too much. I have a lot to do. 78 | Also I will fix bugs, but it might take a while. 79 | -------------------------------------------------------------------------------- /doc/source/readme.rst: -------------------------------------------------------------------------------- 1 | Cryptosuite2 2 | ************ 3 | 4 | .. contents:: 5 | 6 | Links 7 | ===== 8 | 9 | - The `code is here `_. 10 | - The `docs are here `_. 11 | 12 | 13 | 14 | What Is Cryptosuite2? 15 | ===================== 16 | 17 | Cryptosuite2 is a (more or less) drop in replacement for 18 | https://github.com/Cathedrow/Cryptosuite. It currently 19 | provides SHA256 and HMAC-SHA256. 20 | 21 | Install 22 | ======= 23 | 24 | Using the ZIP for Arduino 25 | ------------------------- 26 | 27 | Download the latest ZIP release from `the release page `_ 28 | and install it using the Arduino IDE. 29 | 30 | Manually 31 | -------- 32 | 33 | - Download the library. 34 | - Copy ``cryptosuite2/sha`` to ``~/sketchbook/libraries`` 35 | (``cp -rv cryptosuite2/sha ~/sketchbook/libraries``) 36 | or ``~/Arduino/libraries`` (``cp -rv cryptosuite2/sha ~/Arduino/libraries``) 37 | 38 | Usage 39 | ===== 40 | 41 | Take a look at the `docs 42 | `_. 43 | 44 | 45 | Gotchas 46 | ------- 47 | 48 | - Once ``Sha256.result()`` or ``Sha256.resultHmac()`` 49 | (or ``sha256_hasher_gethash()``, 50 | ``sha256_hasher_gethmac()``, ``sha256_hasher_pad()``) 51 | have been invoked ``Sha256.init()`` (or 52 | ``sha256_hasher_init()``) must be invoked! 53 | - The same thing applies for ``Sha1`` and ``sha1_*``. 54 | 55 | Todos 56 | ===== 57 | 58 | You can ask for further features, but right now it seems 59 | like all the required stuff is running. 60 | 61 | Contributing 62 | ============ 63 | 64 | Contributions are welcome! 65 | 66 | Just add yourself in the ``contributors.yml`` file and send 67 | a pull request. 68 | 69 | All contributions must be licensed under the GNU GPLv3. This 70 | is just because keeping track of various licenses is a pain 71 | in the ass. 72 | 73 | Support 74 | ======= 75 | 76 | I can give you some assistance in general, but do not expect 77 | too much. I have a lot to do. 78 | Also I will fix bugs, but it might take a while. 79 | -------------------------------------------------------------------------------- /docs/sources/readme.rst.txt: -------------------------------------------------------------------------------- 1 | Cryptosuite2 2 | ************ 3 | 4 | .. contents:: 5 | 6 | Links 7 | ===== 8 | 9 | - The `code is here `_. 10 | - The `docs are here `_. 11 | 12 | 13 | 14 | What Is Cryptosuite2? 15 | ===================== 16 | 17 | Cryptosuite2 is a (more or less) drop in replacement for 18 | https://github.com/Cathedrow/Cryptosuite. It currently 19 | provides SHA256 and HMAC-SHA256. 20 | 21 | Install 22 | ======= 23 | 24 | Using the ZIP for Arduino 25 | ------------------------- 26 | 27 | Download the latest ZIP release from `the release page `_ 28 | and install it using the Arduino IDE. 29 | 30 | Manually 31 | -------- 32 | 33 | - Download the library. 34 | - Copy ``cryptosuite2/sha`` to ``~/sketchbook/libraries`` 35 | (``cp -rv cryptosuite2/sha ~/sketchbook/libraries``) 36 | or ``~/Arduino/libraries`` (``cp -rv cryptosuite2/sha ~/Arduino/libraries``) 37 | 38 | Usage 39 | ===== 40 | 41 | Take a look at the `docs 42 | `_. 43 | 44 | 45 | Gotchas 46 | ------- 47 | 48 | - Once ``Sha256.result()`` or ``Sha256.resultHmac()`` 49 | (or ``sha256_hasher_gethash()``, 50 | ``sha256_hasher_gethmac()``, ``sha256_hasher_pad()``) 51 | have been invoked ``Sha256.init()`` (or 52 | ``sha256_hasher_init()``) must be invoked! 53 | - The same thing applies for ``Sha1`` and ``sha1_*``. 54 | 55 | Todos 56 | ===== 57 | 58 | You can ask for further features, but right now it seems 59 | like all the required stuff is running. 60 | 61 | Contributing 62 | ============ 63 | 64 | Contributions are welcome! 65 | 66 | Just add yourself in the ``contributors.yml`` file and send 67 | a pull request. 68 | 69 | All contributions must be licensed under the GNU GPLv3. This 70 | is just because keeping track of various licenses is a pain 71 | in the ass. 72 | 73 | Support 74 | ======= 75 | 76 | I can give you some assistance in general, but do not expect 77 | too much. I have a lot to do. 78 | Also I will fix bugs, but it might take a while. 79 | -------------------------------------------------------------------------------- /sha/sha1/types.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #ifndef SHA1_TYPES_H_ 18 | #define SHA1_TYPES_H_ 19 | 20 | #include "default.h" 21 | #include 22 | #include 23 | #include "constants.h" 24 | 25 | 26 | typedef union 27 | { 28 | uint8_t bytes[SHA1_HASH_LEN]; 29 | uint32_t words[SHA1_HASH_LEN / 4]; 30 | 31 | } sha1_state_t; 32 | 33 | typedef union 34 | { 35 | uint8_t bytes[SHA1_BLOCK_LEN]; 36 | uint32_t words[SHA1_BLOCK_LEN / 4]; 37 | 38 | } sha1_block_t; 39 | 40 | typedef struct __attribute__((__packed__)) sha1_hasher_s 41 | { 42 | sha1_state_t state; 43 | sha1_block_t buffer; 44 | 45 | uint8_t block_offset; 46 | uint64_t total_bytes; 47 | uint8_t _lock; 48 | #ifdef SHA1_ENABLE_HMAC 49 | uint8_t hmac_key_buffer[SHA1_BLOCK_LEN]; 50 | uint8_t hmac_inner_hash[SHA1_HASH_LEN]; 51 | #endif 52 | } * sha1_hasher_t; 53 | 54 | sha1_hasher_t sha1_hasher_new(void); 55 | void sha1_hasher_del(sha1_hasher_t hasher); 56 | void sha1_hasher_init(sha1_hasher_t hasher); 57 | 58 | 59 | #endif 60 | 61 | -------------------------------------------------------------------------------- /sha/sha256/basic.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #ifndef SHA256_BASIC_H_ 18 | #define SHA256_BASIC_H_ 19 | 20 | #include "default.h" 21 | #include 22 | 23 | #define sha_ch(x, y, z) (((x) & ((y) ^ (z))) ^ (z)) 24 | #define sha_maj(x, y, z) (((x) & ((y) | (z))) | ((y) & (z))) 25 | #define sha_parity(x, y, z) ((x) ^ (y) ^ (z)) 26 | 27 | #define sha256_shr(bits,word) ((word) >> (bits)) 28 | #define sha256_rotl(bits,word) (((word) << (bits)) | ((word) >> (32 - (bits)))) 29 | #define sha256_rotr(bits,word) (((word) >> (bits)) | ((word) << (32 - (bits)))) 30 | 31 | #define sha256_SIGMA0(word) (sha256_rotr(2, word) ^ sha256_rotr(13, word) ^ sha256_rotr(22, word)) 32 | #define sha256_SIGMA1(word) (sha256_rotr(6, word) ^ sha256_rotr(11, word) ^ sha256_rotr(25, word)) 33 | #define sha256_sigma0(word) (sha256_rotr(7, word) ^ sha256_rotr(18, word) ^ sha256_shr(3, word)) 34 | #define sha256_sigma1(word) (sha256_rotr(17, word) ^ sha256_rotr(19, word) ^ sha256_shr(10, word)) 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /sha/sha256/types.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #ifndef SHA256_TYPES_H_ 18 | #define SHA256_TYPES_H_ 19 | 20 | #include "default.h" 21 | #include 22 | #include 23 | #include "constants.h" 24 | 25 | 26 | typedef union 27 | { 28 | uint8_t bytes[SHA256_HASH_LEN]; 29 | uint32_t words[SHA256_HASH_LEN / 4]; 30 | 31 | } sha256_state_t; 32 | 33 | typedef union 34 | { 35 | uint8_t bytes[SHA256_BLOCK_LEN]; 36 | uint32_t words[SHA256_BLOCK_LEN / 4]; 37 | 38 | } sha256_block_t; 39 | 40 | typedef struct __attribute__((__packed__)) sha256_hasher_s 41 | { 42 | sha256_state_t state; 43 | sha256_block_t buffer; 44 | 45 | uint8_t block_offset; 46 | uint64_t total_bytes; 47 | uint8_t _lock; 48 | #ifdef SHA256_ENABLE_HMAC 49 | uint8_t hmac_key_buffer[SHA256_BLOCK_LEN]; 50 | uint8_t hmac_inner_hash[SHA256_HASH_LEN]; 51 | #endif 52 | } * sha256_hasher_t; 53 | 54 | sha256_hasher_t sha256_hasher_new(void); 55 | void sha256_hasher_del(sha256_hasher_t hasher); 56 | void sha256_hasher_init(sha256_hasher_t hasher); 57 | 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /sha/sha1/hash.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #ifndef SHA1_HASH_H_ 18 | #define SHA1_HASH_H_ 19 | 20 | 21 | #include "default.h" 22 | #include "constants.h" 23 | #include "types.h" 24 | #include "basic.h" 25 | 26 | void sha1_hash_block(sha1_hasher_t hasher); 27 | 28 | void sha1_hasher_add_byte(sha1_hasher_t hasher, uint8_t byte); 29 | 30 | /** 31 | * NOTE: once the block has been pad'ed the hasher will 32 | * produce nonsense data. Therefore putc will return EOF 33 | * once the hasher has been pad'ed (this happens, when 34 | * sha1_hasher_gethash or sha1_hasher_gethmac are invoced). 35 | * */ 36 | int sha1_hasher_putc(sha1_hasher_t hasher, uint8_t byte); 37 | 38 | void sha1_hasher_pad(sha1_hasher_t hasher); 39 | 40 | /** 41 | * NOTE: this will NOT return a copy of the data but 42 | * a REFERENCE! One MUST NOT free the result. 43 | * 44 | * Also this modifies the state of the hasher. The 45 | * hasher has an internal lock ensuring that writing 46 | * to the hasher fails after this operation. 47 | * */ 48 | uint8_t * sha1_hasher_gethash(sha1_hasher_t hasher); 49 | 50 | #ifdef SHA1_ENABLE_HMAC 51 | void sha1_hasher_init_hmac(sha1_hasher_t hasher, const uint8_t * key, size_t key_len); 52 | uint8_t * sha1_hasher_gethmac(sha1_hasher_t hasher); 53 | #endif 54 | 55 | #endif 56 | 57 | -------------------------------------------------------------------------------- /sha/sha256/hash.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #ifndef SHA256_HASH_H_ 18 | #define SHA256_HASH_H_ 19 | 20 | 21 | #include "default.h" 22 | #include "constants.h" 23 | #include "types.h" 24 | #include "basic.h" 25 | 26 | void sha256_hash_block(sha256_hasher_t hasher); 27 | 28 | void sha256_hasher_add_byte(sha256_hasher_t hasher, uint8_t byte); 29 | 30 | /** 31 | * NOTE: once the block has been pad'ed the hasher will 32 | * produce nonsense data. Therefore putc will return EOF 33 | * once the hasher has been pad'ed (this happens, when 34 | * sha256_hasher_gethash or sha256_hasher_gethmac are invoced). 35 | * */ 36 | int sha256_hasher_putc(sha256_hasher_t hasher, uint8_t byte); 37 | 38 | void sha256_hasher_pad(sha256_hasher_t hasher); 39 | 40 | /** 41 | * NOTE: this will NOT return a copy of the data but 42 | * a REFERENCE! One MUST NOT free the result. 43 | * 44 | * Also this modifies the state of the hasher. The 45 | * hasher has an internal lock ensuring that writing 46 | * to the hasher fails after this operation. 47 | * */ 48 | uint8_t * sha256_hasher_gethash(sha256_hasher_t hasher); 49 | 50 | #ifdef SHA256_ENABLE_HMAC 51 | void sha256_hasher_init_hmac(sha256_hasher_t hasher, const uint8_t * key, size_t key_len); 52 | uint8_t * sha256_hasher_gethmac(sha256_hasher_t hasher); 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /sha/sha256/constants.c: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "constants.h" 18 | 19 | #ifndef __AVR__ 20 | const uint32_t sha256_init_state[SHA256_HASH_LEN / 4] = 21 | #else 22 | const uint32_t sha256_init_state[SHA256_HASH_LEN / 4] PROGMEM = 23 | #endif 24 | { 25 | 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 26 | 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 27 | }; 28 | 29 | #ifndef __AVR__ 30 | const uint32_t sha256_constants[64] = 31 | #else 32 | const uint32_t sha256_constants[64] PROGMEM = 33 | #endif 34 | { 35 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 36 | 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 37 | 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 38 | 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 39 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 40 | 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 41 | 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 42 | 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 43 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 44 | 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 45 | 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 46 | 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 47 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /sha/sha1/constants.h: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #ifndef SHA1_CONSTANTS_H_ 18 | #define SHA1_CONSTANTS_H_ 19 | 20 | #include "default.h" 21 | #include 22 | 23 | #define SHA1_BLOCK_LEN 64 24 | #define SHA1_HASH_LEN 20 25 | 26 | #ifdef __AVR__ 27 | #include 28 | #endif 29 | 30 | #ifndef __AVR__ 31 | extern const uint32_t sha1_init_state[SHA1_HASH_LEN / 4]; 32 | #else 33 | extern const uint32_t sha1_init_state[SHA1_HASH_LEN / 4] PROGMEM; 34 | #endif 35 | 36 | #ifndef __AVR__ 37 | extern const uint32_t sha1_constants[4]; 38 | #else 39 | extern const uint32_t sha1_constants[4] PROGMEM; 40 | #endif 41 | 42 | 43 | // From RFC3174 (http://www.faqs.org/rfcs/rfc3174.html) 44 | // (Section 5): 45 | // 46 | // A sequence of constant words K(0), K(1), ... , K(79) is used in the 47 | // SHA-1. In hex these are given by 48 | // 49 | // K(t) = 5A827999 ( 0 <= t <= 19) 50 | // 51 | // K(t) = 6ED9EBA1 (20 <= t <= 39) 52 | // 53 | // K(t) = 8F1BBCDC (40 <= t <= 59) 54 | // 55 | // K(t) = CA62C1D6 (60 <= t <= 79). 56 | // 57 | // This can be achieved using an integer division by 20 and only 4 constants. 58 | 59 | #ifdef __AVR__ 60 | #define sha1_k(i) pgm_read_dword(sha1_constants + (i / 20)) 61 | #else 62 | #define sha1_k(i) sha1_constants[i / 20] 63 | #endif 64 | 65 | 66 | #ifdef SHA1_ENABLE_HMAC 67 | #define SHA1_HMAC_IPAD 0x36 68 | #define SHA1_HMAC_OPAD 0x5c 69 | #endif 70 | 71 | #endif 72 | 73 | -------------------------------------------------------------------------------- /sha/test/test_sha1.c: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "../sha1/sha1.h" 18 | #include 19 | #include 20 | #include 21 | 22 | void print_hash(uint8_t * result) 23 | { 24 | int i; 25 | for(i = 0; i < SHA1_HASH_LEN; i++) 26 | { 27 | printf("%02x", result[i]); 28 | } 29 | printf("\n"); 30 | } 31 | 32 | int main(void) 33 | { 34 | sha1_hasher_t hasher = sha1_hasher_new(); 35 | uint8_t * result; 36 | int i; 37 | 38 | 39 | 40 | uint8_t expect_test1[SHA1_HASH_LEN] = {0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a, 0xba, 41 | 0x3e, 0x25, 0x71, 0x78, 0x50, 0xc2, 0x6c, 0x9c, 0xd0, 42 | 0xd8, 0x9d} ; 43 | 44 | sha1_hasher_init(hasher); 45 | sha1_hasher_write(hasher, "abc", 3); 46 | result = sha1_hasher_gethash(hasher); 47 | printf("EXPECT: a9993e364706816aba3e25717850c26c9cd0d89d\n"); 48 | printf("GOT: "); 49 | print_hash(result); 50 | 51 | for(i=0; i < SHA1_HASH_LEN; i++) 52 | { 53 | assert(result[i] == expect_test1[i]); 54 | } 55 | 56 | 57 | 58 | uint8_t expect_test2[SHA1_HASH_LEN] = {0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 59 | 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 60 | 0xaf, 0xd8, 0x07, 0x09}; 61 | sha1_hasher_init(hasher); 62 | result = sha1_hasher_gethash(hasher); 63 | printf("EXPECT: da39a3ee5e6b4b0d3255bfef95601890afd80709\n"); 64 | printf("GOT: "); 65 | print_hash(result); 66 | 67 | for(i=0; i < SHA1_HASH_LEN; i++) 68 | { 69 | assert(result[i] == expect_test2[i]); 70 | } 71 | 72 | 73 | sha1_hasher_del(hasher); 74 | return 0; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /doc/source/usage_normal.rst: -------------------------------------------------------------------------------- 1 | Usage as a C Library 2 | ******************** 3 | 4 | .. contents:: 5 | 6 | SHA256 7 | :::::: 8 | 9 | API Doc 10 | ------- 11 | 12 | ``sha256_hasher_new(void): sha256_hasher_t`` 13 | Allocate and initialize a new hasher. 14 | ``sha256_hasher_del(sha256_hasher_t hasher): void`` 15 | Free the hasher. 16 | ``sha256_hasher_init(sha256_hasher_t hasher)`` 17 | (Re-) Initialize the hasher for hashing. 18 | ``sha256_hasher_putc(sha256_hasher_t hasher, uint8_t byte): int`` 19 | Put ``byte`` to the hasher. Follows the standard 20 | ``putc`` conventions. 21 | ``sha256_hasher_gethash(sha256_hasher_t hasher): uint8_t *`` 22 | Returns **a reference** of the hash. One **must 23 | not** free the result. This modifies the state of 24 | the hasher. Once this function has been called, 25 | ``sha256_hasher_init`` must be invoked or 26 | ``sha256_hasher_putc`` will fail. 27 | ``sha256_hasher_write(sha256_hasher_t hasher, const void * buf, size_t count): ssize_t`` 28 | Writes to the hasher. Follows the standard ``write`` 29 | conventions and uses ``sha256_hasher_putc``. 30 | 31 | If ``SHA256_ENABLE_HMAC`` is defined in ``sha256/default.h`` 32 | also the following functions are available: 33 | 34 | ``sha256_hasher_init_hmac(sha256_hasher_t hasher, const uint8_t * key, size_t key_len): void`` 35 | Initialize the hasher for *HMAC*. Invokes 36 | ``sha256_hasher_init``. 37 | ``sha256_hasher_gethmac(sha256_hasher_t hasher): uint8_t *`` 38 | Returns **a reference** of the hash. One **must 39 | not** free the result. This modifies the state of 40 | the hasher. Once this function has been called, 41 | ``sha256_hasher_init`` must be invoked or 42 | ``sha256_hasher_putc`` will fail. 43 | 44 | SHA1 45 | :::: 46 | API Doc 47 | ------- 48 | 49 | ``sha1_hasher_new(void): sha1_hasher_t`` 50 | Allocate and initialize a new hasher. 51 | ``sha1_hasher_del(sha1_hasher_t hasher): void`` 52 | Free the hasher. 53 | ``sha1_hasher_init(sha1_hasher_t hasher)`` 54 | (Re-) Initialize the hasher for hashing. 55 | ``sha1_hasher_putc(sha1_hasher_t hasher, uint8_t byte): int`` 56 | Put ``byte`` to the hasher. Follows the standard 57 | ``putc`` conventions. 58 | ``sha1_hasher_gethash(sha1_hasher_t hasher): uint8_t *`` 59 | Returns **a reference** of the hash. One **must 60 | not** free the result. This modifies the state of 61 | the hasher. Once this function has been called, 62 | ``sha1_hasher_init`` must be invoked or 63 | ``sha1_hasher_putc`` will fail. 64 | ``sha1_hasher_write(sha1_hasher_t hasher, const void * buf, size_t count): ssize_t`` 65 | Writes to the hasher. Follows the standard ``write`` 66 | conventions and uses ``sha1_hasher_putc``. 67 | 68 | If ``SHA1_ENABLE_HMAC`` is defined in ``sha1/default.h`` 69 | also the following functions are available: 70 | 71 | ``sha1_hasher_init_hmac(sha1_hasher_t hasher, const uint8_t * key, size_t key_len): void`` 72 | Initialize the hasher for *HMAC*. Invokes 73 | ``sha1_hasher_init``. 74 | ``sha1_hasher_gethmac(sha1_hasher_t hasher): uint8_t *`` 75 | Returns **a reference** of the hash. One **must 76 | not** free the result. This modifies the state of 77 | the hasher. Once this function has been called, 78 | ``sha1_hasher_init`` must be invoked or 79 | ``sha1_hasher_putc`` will fail. 80 | -------------------------------------------------------------------------------- /sha/test/test_sha256.c: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "../sha256/sha256.h" 18 | #include 19 | #include 20 | #include 21 | 22 | void print_hash(uint8_t * result) 23 | { 24 | int i; 25 | for(i = 0; i < SHA256_HASH_LEN; i++) 26 | { 27 | printf("%02x", result[i]); 28 | } 29 | printf("\n"); 30 | } 31 | 32 | int main(void) 33 | { 34 | sha256_hasher_t hasher = sha256_hasher_new(); 35 | uint8_t * result; 36 | int i; 37 | 38 | 39 | 40 | uint8_t expected_test1[SHA256_HASH_LEN] = {0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 41 | 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, 42 | 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 43 | 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}; 44 | 45 | sha256_hasher_init(hasher); 46 | sha256_hasher_write(hasher, "abc", 3); 47 | result = sha256_hasher_gethash(hasher); 48 | printf("EXPECT: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad\n"); 49 | printf("GOT: "); 50 | print_hash(result); 51 | 52 | for(i = 0; i < SHA256_HASH_LEN; i++) 53 | { 54 | assert(result[i] == expected_test1[i]); 55 | } 56 | 57 | 58 | uint8_t expected_test2[SHA256_HASH_LEN] = {0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 59 | 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 60 | 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 61 | 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}; 62 | 63 | sha256_hasher_init(hasher); 64 | result = sha256_hasher_gethash(hasher); 65 | printf("EXPECT: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n"); 66 | printf("GOT: "); 67 | print_hash(result); 68 | 69 | for(i = 0; i < SHA256_HASH_LEN; i++) 70 | { 71 | assert(result[i] == expected_test2[i]); 72 | } 73 | 74 | 75 | sha256_hasher_del(hasher); 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /docs/sources/usage_normal.rst.txt: -------------------------------------------------------------------------------- 1 | Usage as a C Library 2 | ******************** 3 | 4 | .. contents:: 5 | 6 | SHA256 7 | :::::: 8 | 9 | API Doc 10 | ------- 11 | 12 | ``sha256_hasher_new(void): sha256_hasher_t`` 13 | Allocate and initialize a new hasher. 14 | ``sha256_hasher_del(sha256_hasher_t hasher): void`` 15 | Free the hasher. 16 | ``sha256_hasher_init(sha256_hasher_t hasher)`` 17 | (Re-) Initialize the hasher for hashing. 18 | ``sha256_hasher_putc(sha256_hasher_t hasher, uint8_t byte): int`` 19 | Put ``byte`` to the hasher. Follows the standard 20 | ``putc`` conventions. 21 | ``sha256_hasher_gethash(sha256_hasher_t hasher): uint8_t *`` 22 | Returns **a reference** of the hash. One **must 23 | not** free the result. This modifies the state of 24 | the hasher. Once this function has been called, 25 | ``sha256_hasher_init`` must be invoked or 26 | ``sha256_hasher_putc`` will fail. 27 | ``sha256_hasher_write(sha256_hasher_t hasher, const void * buf, size_t count): ssize_t`` 28 | Writes to the hasher. Follows the standard ``write`` 29 | conventions and uses ``sha256_hasher_putc``. 30 | 31 | If ``SHA256_ENABLE_HMAC`` is defined in ``sha256/default.h`` 32 | also the following functions are available: 33 | 34 | ``sha256_hasher_init_hmac(sha256_hasher_t hasher, const uint8_t * key, size_t key_len): void`` 35 | Initialize the hasher for *HMAC*. Invokes 36 | ``sha256_hasher_init``. 37 | ``sha256_hasher_gethmac(sha256_hasher_t hasher): uint8_t *`` 38 | Returns **a reference** of the hash. One **must 39 | not** free the result. This modifies the state of 40 | the hasher. Once this function has been called, 41 | ``sha256_hasher_init`` must be invoked or 42 | ``sha256_hasher_putc`` will fail. 43 | 44 | SHA1 45 | :::: 46 | API Doc 47 | ------- 48 | 49 | ``sha1_hasher_new(void): sha1_hasher_t`` 50 | Allocate and initialize a new hasher. 51 | ``sha1_hasher_del(sha1_hasher_t hasher): void`` 52 | Free the hasher. 53 | ``sha1_hasher_init(sha1_hasher_t hasher)`` 54 | (Re-) Initialize the hasher for hashing. 55 | ``sha1_hasher_putc(sha1_hasher_t hasher, uint8_t byte): int`` 56 | Put ``byte`` to the hasher. Follows the standard 57 | ``putc`` conventions. 58 | ``sha1_hasher_gethash(sha1_hasher_t hasher): uint8_t *`` 59 | Returns **a reference** of the hash. One **must 60 | not** free the result. This modifies the state of 61 | the hasher. Once this function has been called, 62 | ``sha1_hasher_init`` must be invoked or 63 | ``sha1_hasher_putc`` will fail. 64 | ``sha1_hasher_write(sha1_hasher_t hasher, const void * buf, size_t count): ssize_t`` 65 | Writes to the hasher. Follows the standard ``write`` 66 | conventions and uses ``sha1_hasher_putc``. 67 | 68 | If ``SHA1_ENABLE_HMAC`` is defined in ``sha1/default.h`` 69 | also the following functions are available: 70 | 71 | ``sha1_hasher_init_hmac(sha1_hasher_t hasher, const uint8_t * key, size_t key_len): void`` 72 | Initialize the hasher for *HMAC*. Invokes 73 | ``sha1_hasher_init``. 74 | ``sha1_hasher_gethmac(sha1_hasher_t hasher): uint8_t *`` 75 | Returns **a reference** of the hash. One **must 76 | not** free the result. This modifies the state of 77 | the hasher. Once this function has been called, 78 | ``sha1_hasher_init`` must be invoked or 79 | ``sha1_hasher_putc`` will fail. 80 | -------------------------------------------------------------------------------- /docs/genindex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Index — cryptosuite2 0.2.6 documentation 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 |
28 |
29 | 30 | 31 |
32 | 33 | 34 |

Index

35 | 36 |
37 | 38 |
39 | 40 | 41 |
42 | 43 |
44 |
45 | 92 |
93 |
94 | 102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /docs/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Search — cryptosuite2 0.2.6 documentation 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
33 |
34 |
35 | 36 | 37 |
38 | 39 |

Search

40 | 41 | 49 | 50 | 51 |

52 | Searching for multiple words only shows matches that contain 53 | all words. 54 |

55 | 56 | 57 |
58 | 59 | 60 | 61 |
62 | 63 | 64 | 65 |
66 | 67 |
68 | 69 | 70 |
71 | 72 |
73 |
74 | 111 |
112 |
113 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /docs/searchindex.js: -------------------------------------------------------------------------------- 1 | Search.setIndex({docnames:["contributors","index","readme","usage_arduino","usage_normal"],envversion:{"sphinx.domains.c":2,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":4,"sphinx.domains.index":1,"sphinx.domains.javascript":2,"sphinx.domains.math":2,"sphinx.domains.python":3,"sphinx.domains.rst":2,"sphinx.domains.std":2,sphinx:56},filenames:["contributors.rst","index.rst","readme.rst","usage_arduino.rst","usage_normal.rst"],objects:{},objnames:{},objtypes:{},terms:{"0":3,"0123456789abcdef":3,"0xf":3,"1":3,"10":3,"2018":0,"2019":0,"2020":0,"2021":0,"3":3,"32":3,"4":3,"5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843":3,"9600":3,"byte":[3,4],"class":3,"const":[3,4],"default":[3,4],"do":[2,3],"function":[3,4],"import":3,"int":[3,4],"kn\u00fcttel":0,"new":4,"return":[3,4],"void":[3,4],"while":2,A:3,If:[3,4],Is:1,It:[2,3],One:[3,4],The:[2,3],Then:3,abc:3,about:3,access:0,actual:3,add:[0,2],after:3,again:3,all:[2,3],alloc:[3,4],also:[2,3,4],although:3,appli:2,appropri:0,ar:[2,3,4],arduino:1,ask:2,ass:2,assist:2,avail:[3,4],b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7:3,ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad:3,becaus:2,been:[2,3,4],befor:3,begin:3,below:3,both:3,bound:0,bring:3,buf:[3,4],bug:[0,2],build:0,c:[0,1],call:[3,4],can:[2,3],cathedrow:2,christoph:0,code:2,com:2,config:3,configur:3,contribut:1,contributor:[1,2],convent:[3,4],copi:2,count:[3,4],cp:2,creat:3,cryptosuit:2,cryptosuite2:3,current:2,daknuett:0,daniel:0,data:[0,3],defin:[3,4],delet:3,digest:0,doc:2,done:3,download:2,drop:2,easili:3,eat:3,edit:3,enhanc:0,eu:0,exampl:[0,3],exclud:3,expect:[0,2,3],fail:[3,4],featur:2,file:[2,3],first:3,fix:[0,2],flash:[0,3],folder:[0,3],follow:[3,4],free:4,from:[0,2,3],further:2,gener:[1,2],github:2,give:2,global:3,gnu:2,got:3,gplv3:2,h:[3,4],ha:[3,4],hash:[0,3,4],hasher:4,have:2,he:3,header:3,here:[2,3],hmac256:0,hmac:[0,2,3,4],honal:0,how:3,http:2,i:[2,3],id:2,implement:0,includ:3,increas:3,index:1,init:[2,3],inithmac:3,initi:[0,3,4],insid:3,instal:1,interfac:3,invok:[2,3,4],jefe:3,joshheanei:0,just:2,keep:2,kei:[3,4],key_len:[3,4],keyword:0,knuettel:0,last:3,latest:2,less:2,librari:[0,1,2,3],licens:2,like:2,link:1,look:2,loop:3,lot:2,macro:3,memori:[0,3],method:3,might:2,modifi:[3,4],modul:3,more:2,move:0,much:2,must:[2,3,4],n:3,nagimov:0,name:0,need:3,none:0,noth:3,now:2,onc:[2,3,4],one:3,onli:3,out:0,output:0,overhead:3,overwrit:3,page:[1,2],pain:2,per1234:0,platformio:0,preciou:3,preprocessor:3,print:3,println:3,properti:0,provid:2,pull:2,put:[3,4],putc:[3,4],ram:[0,3],re:[3,4],read:3,refer:[3,4],regular:0,releas:2,remov:0,replac:2,request:2,requir:2,result:[2,4],resulthmac:[2,3],rfc4231:3,right:2,run:2,rv:2,safe:3,same:[2,3],save:3,search:1,secret:3,secretlength:3,section:3,see:3,seem:2,send:2,serial:3,set:3,setup:3,sha1:[0,1,2],sha1_:2,sha1_dis:3,sha1_disable_wrapp:3,sha1_enable_hmac:[3,4],sha1_hasher_del:[3,4],sha1_hasher_gethash:[3,4],sha1_hasher_gethmac:[3,4],sha1_hasher_init:[3,4],sha1_hasher_init_hmac:[3,4],sha1_hasher_new:[3,4],sha1_hasher_putc:[3,4],sha1_hasher_t:[3,4],sha1_hasher_writ:[3,4],sha1wrapp:3,sha256:[0,1,2],sha256_dis:3,sha256_disable_wrapp:3,sha256_enable_hmac:[3,4],sha256_hasher_del:[3,4],sha256_hasher_gethash:[2,3,4],sha256_hasher_gethmac:[2,3,4],sha256_hasher_init:[2,3,4],sha256_hasher_init_hmac:[3,4],sha256_hasher_new:[3,4],sha256_hasher_pad:2,sha256_hasher_putc:[3,4],sha256_hasher_t:[3,4],sha256_hasher_writ:[3,4],sha256wrapp:3,sha:2,shax:3,should:3,size_t:[3,4],sketch:0,sketchbook:2,so:3,some:[0,2,3],ssize_t:[3,4],standard:[3,4],state:[3,4],stuff:2,support:1,take:2,test:[0,3],therefor:3,thi:[2,3,4],thing:[2,3],todo:1,too:2,track:2,txt:0,type:3,uint8_t:[3,4],undef:3,under:2,unsign:3,up:3,us:[3,4],usabl:0,usag:1,user:3,variou:[2,3],version:0,wai:3,want:3,we:3,welcom:2,what:[1,3],when:3,which:3,wrapper:0,write:4,ya:3,yml:2,you:[2,3],your:3,yourself:2},titles:["Contributors","Welcome to cryptosuite2\u2019s documentation!","Cryptosuite2","Usage with Arduino","Usage as a C Library"],titleterms:{"new":3,Is:2,api:[3,4],arduino:[2,3],c:[3,4],code:3,content:[1,2,3,4],contribut:2,contributor:0,cryptosuite2:[1,2],disabl:3,doc:[3,4],document:1,extend:3,free:3,gener:3,gotcha:2,hasher:3,indic:1,ing:3,instal:2,instanti:3,librari:4,link:2,manual:2,object:3,obtain:3,optim:3,result:3,s:1,sha1:[3,4],sha256:[3,4],simpl:3,support:2,tabl:1,todo:2,us:2,usag:[2,3,4],welcom:1,what:2,wrapper:3,write:3,zip:2}}) -------------------------------------------------------------------------------- /docs/static/pygments.css: -------------------------------------------------------------------------------- 1 | pre { line-height: 125%; } 2 | td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } 3 | span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } 4 | td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } 5 | span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } 6 | .highlight .hll { background-color: #ffffcc } 7 | .highlight { background: #eeffcc; } 8 | .highlight .c { color: #408090; font-style: italic } /* Comment */ 9 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 10 | .highlight .k { color: #007020; font-weight: bold } /* Keyword */ 11 | .highlight .o { color: #666666 } /* Operator */ 12 | .highlight .ch { color: #408090; font-style: italic } /* Comment.Hashbang */ 13 | .highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */ 14 | .highlight .cp { color: #007020 } /* Comment.Preproc */ 15 | .highlight .cpf { color: #408090; font-style: italic } /* Comment.PreprocFile */ 16 | .highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */ 17 | .highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ 18 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 19 | .highlight .ge { font-style: italic } /* Generic.Emph */ 20 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 21 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 22 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 23 | .highlight .go { color: #333333 } /* Generic.Output */ 24 | .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ 25 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 26 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 27 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 28 | .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */ 29 | .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ 30 | .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ 31 | .highlight .kp { color: #007020 } /* Keyword.Pseudo */ 32 | .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ 33 | .highlight .kt { color: #902000 } /* Keyword.Type */ 34 | .highlight .m { color: #208050 } /* Literal.Number */ 35 | .highlight .s { color: #4070a0 } /* Literal.String */ 36 | .highlight .na { color: #4070a0 } /* Name.Attribute */ 37 | .highlight .nb { color: #007020 } /* Name.Builtin */ 38 | .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */ 39 | .highlight .no { color: #60add5 } /* Name.Constant */ 40 | .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */ 41 | .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */ 42 | .highlight .ne { color: #007020 } /* Name.Exception */ 43 | .highlight .nf { color: #06287e } /* Name.Function */ 44 | .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */ 45 | .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ 46 | .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */ 47 | .highlight .nv { color: #bb60d5 } /* Name.Variable */ 48 | .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */ 49 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 50 | .highlight .mb { color: #208050 } /* Literal.Number.Bin */ 51 | .highlight .mf { color: #208050 } /* Literal.Number.Float */ 52 | .highlight .mh { color: #208050 } /* Literal.Number.Hex */ 53 | .highlight .mi { color: #208050 } /* Literal.Number.Integer */ 54 | .highlight .mo { color: #208050 } /* Literal.Number.Oct */ 55 | .highlight .sa { color: #4070a0 } /* Literal.String.Affix */ 56 | .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */ 57 | .highlight .sc { color: #4070a0 } /* Literal.String.Char */ 58 | .highlight .dl { color: #4070a0 } /* Literal.String.Delimiter */ 59 | .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ 60 | .highlight .s2 { color: #4070a0 } /* Literal.String.Double */ 61 | .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ 62 | .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */ 63 | .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ 64 | .highlight .sx { color: #c65d09 } /* Literal.String.Other */ 65 | .highlight .sr { color: #235388 } /* Literal.String.Regex */ 66 | .highlight .s1 { color: #4070a0 } /* Literal.String.Single */ 67 | .highlight .ss { color: #517918 } /* Literal.String.Symbol */ 68 | .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */ 69 | .highlight .fm { color: #06287e } /* Name.Function.Magic */ 70 | .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */ 71 | .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */ 72 | .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */ 73 | .highlight .vm { color: #bb60d5 } /* Name.Variable.Magic */ 74 | .highlight .il { color: #208050 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /doc/source/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # cryptosuite2 documentation build configuration file, created by 4 | # sphinx-quickstart on Sun Feb 25 22:30:55 2018. 5 | # 6 | # This file is execfile()d with the current directory set to its 7 | # containing dir. 8 | # 9 | # Note that not all possible configuration values are present in this 10 | # autogenerated file. 11 | # 12 | # All configuration values have a default; values that are commented out 13 | # serve to show the default. 14 | 15 | # If extensions (or modules to document with autodoc) are in another directory, 16 | # add these directories to sys.path here. If the directory is relative to the 17 | # documentation root, use os.path.abspath to make it absolute, like shown here. 18 | # 19 | # import os 20 | # import sys 21 | # sys.path.insert(0, os.path.abspath('.')) 22 | 23 | 24 | # -- General configuration ------------------------------------------------ 25 | 26 | # If your documentation needs a minimal Sphinx version, state it here. 27 | # 28 | # needs_sphinx = '1.0' 29 | 30 | # Add any Sphinx extension module names here, as strings. They can be 31 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 32 | # ones. 33 | extensions = [] 34 | 35 | # Add any paths that contain templates here, relative to this directory. 36 | templates_path = ['_templates'] 37 | 38 | # The suffix(es) of source filenames. 39 | # You can specify multiple suffix as a list of string: 40 | # 41 | # source_suffix = ['.rst', '.md'] 42 | source_suffix = '.rst' 43 | 44 | # The master toctree document. 45 | master_doc = 'index' 46 | 47 | # General information about the project. 48 | project = u'cryptosuite2' 49 | copyright = u'2018, Daniel Knüttel' 50 | author = u'Daniel Knüttel' 51 | 52 | # The version info for the project you're documenting, acts as replacement for 53 | # |version| and |release|, also used in various other places throughout the 54 | # built documents. 55 | # 56 | # The short X.Y version. 57 | version = u'0.2.6' 58 | # The full version, including alpha/beta/rc tags. 59 | release = u'0.2.6' 60 | 61 | # The language for content autogenerated by Sphinx. Refer to documentation 62 | # for a list of supported languages. 63 | # 64 | # This is also used if you do content translation via gettext catalogs. 65 | # Usually you set "language" from the command line for these cases. 66 | language = None 67 | 68 | # List of patterns, relative to source directory, that match files and 69 | # directories to ignore when looking for source files. 70 | # This patterns also effect to html_static_path and html_extra_path 71 | exclude_patterns = [] 72 | 73 | # The name of the Pygments (syntax highlighting) style to use. 74 | pygments_style = 'sphinx' 75 | 76 | # If true, `todo` and `todoList` produce output, else they produce nothing. 77 | todo_include_todos = False 78 | 79 | 80 | # -- Options for HTML output ---------------------------------------------- 81 | 82 | # The theme to use for HTML and HTML Help pages. See the documentation for 83 | # a list of builtin themes. 84 | # 85 | html_theme = 'alabaster' 86 | 87 | # Theme options are theme-specific and customize the look and feel of a theme 88 | # further. For a list of options available for each theme, see the 89 | # documentation. 90 | # 91 | # html_theme_options = {} 92 | 93 | # Add any paths that contain custom static files (such as style sheets) here, 94 | # relative to this directory. They are copied after the builtin static files, 95 | # so a file named "default.css" will overwrite the builtin "default.css". 96 | html_static_path = ['_static'] 97 | 98 | 99 | # -- Options for HTMLHelp output ------------------------------------------ 100 | 101 | # Output file base name for HTML help builder. 102 | htmlhelp_basename = 'cryptosuite2doc' 103 | 104 | 105 | # -- Options for LaTeX output --------------------------------------------- 106 | 107 | latex_elements = { 108 | # The paper size ('letterpaper' or 'a4paper'). 109 | # 110 | # 'papersize': 'letterpaper', 111 | 112 | # The font size ('10pt', '11pt' or '12pt'). 113 | # 114 | # 'pointsize': '10pt', 115 | 116 | # Additional stuff for the LaTeX preamble. 117 | # 118 | # 'preamble': '', 119 | 120 | # Latex figure (float) alignment 121 | # 122 | # 'figure_align': 'htbp', 123 | } 124 | 125 | # Grouping the document tree into LaTeX files. List of tuples 126 | # (source start file, target name, title, 127 | # author, documentclass [howto, manual, or own class]). 128 | latex_documents = [ 129 | (master_doc, 'cryptosuite2.tex', u'cryptosuite2 Documentation', 130 | u'Daniel Knüttel', 'manual'), 131 | ] 132 | 133 | 134 | # -- Options for manual page output --------------------------------------- 135 | 136 | # One entry per manual page. List of tuples 137 | # (source start file, name, description, authors, manual section). 138 | man_pages = [ 139 | (master_doc, 'cryptosuite2', u'cryptosuite2 Documentation', 140 | [author], 1) 141 | ] 142 | 143 | 144 | # -- Options for Texinfo output ------------------------------------------- 145 | 146 | # Grouping the document tree into Texinfo files. List of tuples 147 | # (source start file, target name, title, author, 148 | # dir menu entry, description, category) 149 | texinfo_documents = [ 150 | (master_doc, 'cryptosuite2', u'cryptosuite2 Documentation', 151 | author, 'cryptosuite2', 'One line description of project.', 152 | 'Miscellaneous'), 153 | ] 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /docs/contributors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Contributors — cryptosuite2 0.2.6 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 |
30 |
31 | 32 | 33 |
34 | 35 |
36 |

Contributors

37 |

Daniel Knüttel

38 |
39 |
40 |
42 |
    43 |
  • 2018 Initial version of the library

  • 44 |
  • 2018 Initial version of the C++ Wrapper

  • 45 |
  • 2018 SHA1 implementation and C++ Wrapper for SHA1

  • 46 |
  • 2019 Some bug fixes & some usability enhancments

  • 47 |
48 |
49 |

per1234

50 |
51 |
52 |

None

53 |
54 |
    55 |
  • 2018 Add keywords.txt

  • 56 |
  • 2018 Add library.properties

  • 57 |
  • 2019 Move example sketches to appropriately named folders

  • 58 |
59 |
60 |

JoshHeaney

61 |
62 |
63 |

None

64 |
65 |
    66 |
  • 2019 SHA256 and SHA1 HMAC example digest fix.

  • 67 |
68 |
69 |

nagimov

70 |
71 |
72 |

None

73 |
74 |
    75 |
  • 2020 fix expected hmac256 test output

  • 76 |
  • 2020 Moved some data from RAM to flash in the examples

  • 77 |
78 |
79 |

Christoph Honal

80 |
81 |
82 |

None

83 |
84 |
    85 |
  • 2021 Remove test sketches from the regular build on PlatformIO

  • 86 |
  • 2021 Fix out-of-bounds memory access in SHA1 hashing

  • 87 |
88 |
89 |
90 | 91 | 92 |
93 | 94 |
95 |
96 | 144 |
145 |
146 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Welcome to cryptosuite2’s documentation! — cryptosuite2 0.2.6 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 |
30 |
31 | 32 | 33 |
34 | 35 |
36 |

Welcome to cryptosuite2’s documentation!

37 |
38 |

Contents:

39 | 63 |
64 |
65 |
66 |

Indices and tables

67 | 71 |
72 | 73 | 74 |
75 | 76 |
77 |
78 | 126 |
127 |
128 | 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /sha/sha1/hash.c: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "hash.h" 18 | #include 19 | #include 20 | 21 | 22 | void sha1_hash_block(sha1_hasher_t hasher) 23 | { 24 | int i; 25 | uint32_t a, b, c, d, e, temp; 26 | 27 | // XXX: Omit initializing the message schedule. 28 | // See how I did this below. 29 | // Allocating the message schedule would eat 2k RAM 30 | // which is a no-go on an AVR. 31 | int i4; 32 | // On x86 we have to change the byte order, because... 33 | // I actually do not know. 34 | for(i = i4 = 0; i < 16; i++, i4 += 4) 35 | { 36 | hasher->buffer.words[i] = (((uint32_t)hasher->buffer.bytes[i4]) << 24) | 37 | (((uint32_t)hasher->buffer.bytes[i4 + 1]) << 16) | 38 | (((uint32_t)hasher->buffer.bytes[i4 + 2]) << 8) | 39 | (((uint32_t)hasher->buffer.bytes[i4 + 3])); 40 | } 41 | 42 | a = hasher->state.words[0]; 43 | b = hasher->state.words[1]; 44 | c = hasher->state.words[2]; 45 | d = hasher->state.words[3]; 46 | e = hasher->state.words[4]; 47 | 48 | for(i = 0; i < 80; i++) 49 | { 50 | // XXX: 51 | // This part of the computation omits the message schedule 52 | // W as described in https://tools.ietf.org/html/rfc4634 53 | // The first 16 words of the message schedule is just the block 54 | // anyways and the computation of the message schedule uses only 55 | // the last 16 words, so we can do that. 56 | if( i >= 16 ) 57 | { 58 | hasher->buffer.words[i & 15] = sha1_rotl(1 59 | , hasher->buffer.words[(i - 3)& 15] 60 | ^ hasher->buffer.words[(i - 8)& 15] 61 | ^ hasher->buffer.words[(i - 14)& 15] 62 | ^ hasher->buffer.words[(i - 16)& 15]); 63 | } 64 | 65 | temp = sha1_rotl(5, a) + e + hasher->buffer.words[i & 15] + sha1_k(i); 66 | if(i < 20) 67 | { 68 | temp += (b & c) | ((~b) & d); 69 | } 70 | else if(i < 40) 71 | { 72 | temp += b ^ c ^ d; 73 | } 74 | else if(i < 60) 75 | { 76 | temp += (b & c) | (b & d) | (c & d); 77 | } 78 | else 79 | { 80 | temp += b ^ c ^ d; 81 | } 82 | 83 | 84 | 85 | 86 | 87 | e = d; 88 | d = c; 89 | c = sha1_rotl(30, b); 90 | b = a; 91 | a = temp; 92 | } 93 | hasher->state.words[0] += a; 94 | hasher->state.words[1] += b; 95 | hasher->state.words[2] += c; 96 | hasher->state.words[3] += d; 97 | hasher->state.words[4] += e; 98 | 99 | } 100 | 101 | 102 | 103 | void sha1_hasher_add_byte(sha1_hasher_t hasher, uint8_t byte) 104 | { 105 | hasher->buffer.bytes[hasher->block_offset] = byte; 106 | hasher->block_offset++; 107 | if(hasher->block_offset == SHA1_BLOCK_LEN) 108 | { 109 | sha1_hash_block(hasher); 110 | hasher->block_offset = 0; 111 | } 112 | } 113 | 114 | /** 115 | * NOTE: once the block has been pad'ed the hasher will 116 | * produce nonsense data. Therefore putc will return EOF 117 | * once the hasher has been pad'ed (this happens, when 118 | * sha1_hasher_gethash or sha1_hasher_gethmac are invoced). 119 | * */ 120 | int sha1_hasher_putc(sha1_hasher_t hasher, uint8_t byte) 121 | { 122 | if(hasher->_lock) 123 | { 124 | return EOF; 125 | } 126 | hasher->total_bytes++; 127 | sha1_hasher_add_byte(hasher, byte); 128 | return byte; 129 | 130 | } 131 | 132 | 133 | 134 | void sha1_hasher_pad(sha1_hasher_t hasher) 135 | { 136 | hasher->_lock = 1; 137 | sha1_hasher_add_byte(hasher, 0x80); 138 | while(hasher->block_offset != 56) 139 | { 140 | sha1_hasher_add_byte(hasher, 0); 141 | } 142 | 143 | // FIXME: 144 | // Use a loop for this. 145 | sha1_hasher_add_byte(hasher, hasher->total_bytes * 8 >> 56); 146 | sha1_hasher_add_byte(hasher, hasher->total_bytes * 8 >> 48); 147 | sha1_hasher_add_byte(hasher, hasher->total_bytes * 8 >> 40); 148 | sha1_hasher_add_byte(hasher, hasher->total_bytes * 8 >> 32); 149 | sha1_hasher_add_byte(hasher, hasher->total_bytes * 8 >> 24); 150 | sha1_hasher_add_byte(hasher, hasher->total_bytes * 8 >> 16); 151 | sha1_hasher_add_byte(hasher, hasher->total_bytes * 8 >> 8); 152 | sha1_hasher_add_byte(hasher, hasher->total_bytes * 8); 153 | 154 | } 155 | 156 | uint8_t * sha1_hasher_gethash(sha1_hasher_t hasher) 157 | { 158 | sha1_hasher_pad(hasher); 159 | int i; 160 | 161 | // switch byte order. 162 | for(i = 0; i < (SHA1_HASH_LEN / 4); i++) 163 | { 164 | uint32_t a, b; 165 | a = hasher->state.words[i]; 166 | b = a << 24; 167 | b |= ( a << 8) & 0x00ff0000; 168 | b |= ( a >> 8) & 0x0000ff00; 169 | b |= a >> 24; 170 | hasher->state.words[i] = b; 171 | } 172 | return hasher->state.bytes; 173 | } 174 | 175 | 176 | #ifdef SHA1_ENABLE_HMAC 177 | void sha1_hasher_init_hmac(sha1_hasher_t hasher, const uint8_t * key, size_t key_len) 178 | { 179 | int i; 180 | memset(hasher->hmac_key_buffer, 0, SHA1_BLOCK_LEN); 181 | 182 | if(key_len > SHA1_BLOCK_LEN) 183 | { 184 | sha1_hasher_init(hasher); 185 | while(key_len--) 186 | { 187 | sha1_hasher_putc(hasher, *key++); 188 | } 189 | memcpy(hasher->hmac_key_buffer, 190 | sha1_hasher_gethash(hasher), 191 | SHA1_HASH_LEN); 192 | } 193 | else 194 | { 195 | memcpy(hasher->hmac_key_buffer, key, key_len); 196 | } 197 | sha1_hasher_init(hasher); 198 | for(i = 0; i < SHA1_BLOCK_LEN; i++) 199 | { 200 | sha1_hasher_putc(hasher, hasher->hmac_key_buffer[i] ^ SHA1_HMAC_IPAD); 201 | } 202 | 203 | } 204 | uint8_t * sha1_hasher_gethmac(sha1_hasher_t hasher) 205 | { 206 | int i; 207 | memcpy(hasher->hmac_inner_hash, sha1_hasher_gethash(hasher), 208 | SHA1_HASH_LEN); 209 | sha1_hasher_init(hasher); 210 | 211 | for(i = 0; i < SHA1_BLOCK_LEN; i++) 212 | { 213 | sha1_hasher_putc(hasher, hasher->hmac_key_buffer[i] ^ SHA1_HMAC_OPAD); 214 | } 215 | for(i = 0; i < SHA1_HASH_LEN; i++) 216 | { 217 | sha1_hasher_putc(hasher, hasher->hmac_inner_hash[i]); 218 | } 219 | return sha1_hasher_gethash(hasher); 220 | } 221 | #endif 222 | 223 | -------------------------------------------------------------------------------- /sha/sha256/hash.c: -------------------------------------------------------------------------------- 1 | // This file is part of cryptosuite2. // 2 | // // 3 | // cryptosuite2 is free software: you can redistribute it and/or modify // 4 | // it under the terms of the GNU General Public License as published by // 5 | // the Free Software Foundation, either version 3 of the License, or // 6 | // (at your option) any later version. // 7 | // // 8 | // cryptosuite2 is distributed in the hope that it will be useful, // 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 11 | // GNU General Public License for more details. // 12 | // // 13 | // You should have received a copy of the GNU General Public License // 14 | // along with cryptosuite2. If not, see . // 15 | // // 16 | 17 | #include "hash.h" 18 | #include 19 | #include 20 | 21 | 22 | void sha256_hash_block(sha256_hasher_t hasher) 23 | { 24 | int i; 25 | uint32_t a, b, c, d, e, f, g, h, t1, t2; 26 | 27 | // XXX: Omit initializing the message schedule. 28 | // See how I did this below. 29 | // Allocating the message schedule would eat 2k RAM 30 | // which is a no-go on an AVR. 31 | int i4; 32 | // On x86 we have to change the byte order, because... 33 | // I actually do not know. 34 | for(i = i4 = 0; i < 16; i++, i4 += 4) 35 | { 36 | hasher->buffer.words[i] = (((uint32_t)hasher->buffer.bytes[i4]) << 24) | 37 | (((uint32_t)hasher->buffer.bytes[i4 + 1]) << 16) | 38 | (((uint32_t)hasher->buffer.bytes[i4 + 2]) << 8) | 39 | (((uint32_t)hasher->buffer.bytes[i4 + 3])); 40 | } 41 | 42 | a = hasher->state.words[0]; 43 | b = hasher->state.words[1]; 44 | c = hasher->state.words[2]; 45 | d = hasher->state.words[3]; 46 | e = hasher->state.words[4]; 47 | f = hasher->state.words[5]; 48 | g = hasher->state.words[6]; 49 | h = hasher->state.words[7]; 50 | 51 | for(i = 0; i < 64; i++) 52 | { 53 | // XXX: 54 | // This part of the computation omits the message schedule 55 | // W as described in https://tools.ietf.org/html/rfc4634 56 | // The first 16 words of the message schedule is just the block 57 | // anyways and the computation of the message schedule uses only 58 | // the last 16 words, so we can do that. 59 | if( i >= 16 ) 60 | { 61 | hasher->buffer.words[i & 15] = sha256_sigma1(hasher->buffer.words[(i - 2) & 15]) + 62 | hasher->buffer.words[(i - 7) & 15] + 63 | sha256_sigma0(hasher->buffer.words[(i - 15) & 15]) + 64 | hasher->buffer.words[(i - 16) & 15]; 65 | } 66 | t1 = h + sha256_SIGMA1(e) + sha_ch(e, f, g) + sha256_k(i) + hasher->buffer.words[i & 15]; 67 | t2 = sha256_SIGMA0(a) + sha_maj(a, b, c); 68 | h = g; 69 | g = f; 70 | f = e; 71 | e = d + t1; 72 | d = c; 73 | c = b; 74 | b = a; 75 | a = t1 + t2; 76 | } 77 | hasher->state.words[0] += a; 78 | hasher->state.words[1] += b; 79 | hasher->state.words[2] += c; 80 | hasher->state.words[3] += d; 81 | hasher->state.words[4] += e; 82 | hasher->state.words[5] += f; 83 | hasher->state.words[6] += g; 84 | hasher->state.words[7] += h; 85 | 86 | } 87 | 88 | 89 | 90 | void sha256_hasher_add_byte(sha256_hasher_t hasher, uint8_t byte) 91 | { 92 | hasher->buffer.bytes[hasher->block_offset] = byte; 93 | hasher->block_offset++; 94 | if(hasher->block_offset == SHA256_BLOCK_LEN) 95 | { 96 | sha256_hash_block(hasher); 97 | hasher->block_offset = 0; 98 | } 99 | } 100 | 101 | /** 102 | * NOTE: once the block has been pad'ed the hasher will 103 | * produce nonsense data. Therefore putc will return EOF 104 | * once the hasher has been pad'ed (this happens, when 105 | * sha256_hasher_gethash or sha256_hasher_gethmac are invoced). 106 | * */ 107 | int sha256_hasher_putc(sha256_hasher_t hasher, uint8_t byte) 108 | { 109 | if(hasher->_lock) 110 | { 111 | return EOF; 112 | } 113 | hasher->total_bytes++; 114 | sha256_hasher_add_byte(hasher, byte); 115 | return byte; 116 | 117 | } 118 | 119 | 120 | 121 | void sha256_hasher_pad(sha256_hasher_t hasher) 122 | { 123 | hasher->_lock = 1; 124 | sha256_hasher_add_byte(hasher, 0x80); 125 | while(hasher->block_offset != 56) 126 | { 127 | sha256_hasher_add_byte(hasher, 0); 128 | } 129 | 130 | // FIXME: 131 | // Use a loop for this. 132 | sha256_hasher_add_byte(hasher, hasher->total_bytes * 8 >> 56); 133 | sha256_hasher_add_byte(hasher, hasher->total_bytes * 8 >> 48); 134 | sha256_hasher_add_byte(hasher, hasher->total_bytes * 8 >> 40); 135 | sha256_hasher_add_byte(hasher, hasher->total_bytes * 8 >> 32); 136 | sha256_hasher_add_byte(hasher, hasher->total_bytes * 8 >> 24); 137 | sha256_hasher_add_byte(hasher, hasher->total_bytes * 8 >> 16); 138 | sha256_hasher_add_byte(hasher, hasher->total_bytes * 8 >> 8); 139 | sha256_hasher_add_byte(hasher, hasher->total_bytes * 8); 140 | 141 | } 142 | 143 | uint8_t * sha256_hasher_gethash(sha256_hasher_t hasher) 144 | { 145 | sha256_hasher_pad(hasher); 146 | int i; 147 | 148 | // switch byte order. 149 | for(i = 0; i < 8; i++) 150 | { 151 | uint32_t a, b; 152 | a = hasher->state.words[i]; 153 | b = a << 24; 154 | b |= ( a << 8) & 0x00ff0000; 155 | b |= ( a >> 8) & 0x0000ff00; 156 | b |= a >> 24; 157 | hasher->state.words[i] = b; 158 | } 159 | return hasher->state.bytes; 160 | } 161 | 162 | 163 | #ifdef SHA256_ENABLE_HMAC 164 | void sha256_hasher_init_hmac(sha256_hasher_t hasher, const uint8_t * key, size_t key_len) 165 | { 166 | int i; 167 | memset(hasher->hmac_key_buffer, 0, SHA256_BLOCK_LEN); 168 | 169 | if(key_len > SHA256_BLOCK_LEN) 170 | { 171 | sha256_hasher_init(hasher); 172 | while(key_len--) 173 | { 174 | sha256_hasher_putc(hasher, *key++); 175 | } 176 | memcpy(hasher->hmac_key_buffer, 177 | sha256_hasher_gethash(hasher), 178 | SHA256_HASH_LEN); 179 | } 180 | else 181 | { 182 | memcpy(hasher->hmac_key_buffer, key, key_len); 183 | } 184 | sha256_hasher_init(hasher); 185 | for(i = 0; i < SHA256_BLOCK_LEN; i++) 186 | { 187 | sha256_hasher_putc(hasher, hasher->hmac_key_buffer[i] ^ SHA256_HMAC_IPAD); 188 | } 189 | 190 | } 191 | uint8_t * sha256_hasher_gethmac(sha256_hasher_t hasher) 192 | { 193 | int i; 194 | memcpy(hasher->hmac_inner_hash, sha256_hasher_gethash(hasher), 195 | SHA256_HASH_LEN); 196 | sha256_hasher_init(hasher); 197 | 198 | for(i = 0; i < SHA256_BLOCK_LEN; i++) 199 | { 200 | sha256_hasher_putc(hasher, hasher->hmac_key_buffer[i] ^ SHA256_HMAC_OPAD); 201 | } 202 | for(i = 0; i < SHA256_HASH_LEN; i++) 203 | { 204 | sha256_hasher_putc(hasher, hasher->hmac_inner_hash[i]); 205 | } 206 | return sha256_hasher_gethash(hasher); 207 | } 208 | #endif 209 | -------------------------------------------------------------------------------- /docs/readme.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Cryptosuite2 — cryptosuite2 0.2.6 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 |
35 | 36 |
37 |

Cryptosuite2

38 |
39 |

Contents

40 | 62 |
63 | 70 |
71 |

What Is Cryptosuite2?

72 |

Cryptosuite2 is a (more or less) drop in replacement for 73 | https://github.com/Cathedrow/Cryptosuite. It currently 74 | provides SHA256 and HMAC-SHA256.

75 |
76 |
77 |

Install

78 |
79 |

Using the ZIP for Arduino

80 |

Download the latest ZIP release from the release page 81 | and install it using the Arduino IDE.

82 |
83 |
84 |

Manually

85 |
    86 |
  • Download the library.

  • 87 |
  • Copy cryptosuite2/sha to ~/sketchbook/libraries 88 | (cp -rv cryptosuite2/sha ~/sketchbook/libraries) 89 | or ~/Arduino/libraries (cp -rv cryptosuite2/sha ~/Arduino/libraries)

  • 90 |
91 |
92 |
93 |
94 |

Usage

95 |

Take a look at the docs.

96 |
97 |

Gotchas

98 |
    99 |
  • Once Sha256.result() or Sha256.resultHmac() 100 | (or sha256_hasher_gethash(), 101 | sha256_hasher_gethmac(), sha256_hasher_pad()) 102 | have been invoked Sha256.init() (or 103 | sha256_hasher_init()) must be invoked!

  • 104 |
  • The same thing applies for Sha1 and sha1_*.

  • 105 |
106 |
107 |
108 |
109 |

Todos

110 |

You can ask for further features, but right now it seems 111 | like all the required stuff is running.

112 |
113 |
114 |

Contributing

115 |

Contributions are welcome!

116 |

Just add yourself in the contributors.yml file and send 117 | a pull request.

118 |

All contributions must be licensed under the GNU GPLv3. This 119 | is just because keeping track of various licenses is a pain 120 | in the ass.

121 |
122 |
123 |

Support

124 |

I can give you some assistance in general, but do not expect 125 | too much. I have a lot to do. 126 | Also I will fix bugs, but it might take a while.

127 |
128 |
129 | 130 | 131 |
132 | 133 |
134 |
135 | 193 |
194 |
195 | 206 | 207 | 208 | 209 | 210 | 211 | -------------------------------------------------------------------------------- /docs/static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Sphinx JavaScript utilities for all documentation. 6 | * 7 | * :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /** 13 | * select a different prefix for underscore 14 | */ 15 | $u = _.noConflict(); 16 | 17 | /** 18 | * make the code below compatible with browsers without 19 | * an installed firebug like debugger 20 | if (!window.console || !console.firebug) { 21 | var names = ["log", "debug", "info", "warn", "error", "assert", "dir", 22 | "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", 23 | "profile", "profileEnd"]; 24 | window.console = {}; 25 | for (var i = 0; i < names.length; ++i) 26 | window.console[names[i]] = function() {}; 27 | } 28 | */ 29 | 30 | /** 31 | * small helper function to urldecode strings 32 | * 33 | * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent#Decoding_query_parameters_from_a_URL 34 | */ 35 | jQuery.urldecode = function(x) { 36 | if (!x) { 37 | return x 38 | } 39 | return decodeURIComponent(x.replace(/\+/g, ' ')); 40 | }; 41 | 42 | /** 43 | * small helper function to urlencode strings 44 | */ 45 | jQuery.urlencode = encodeURIComponent; 46 | 47 | /** 48 | * This function returns the parsed url parameters of the 49 | * current request. Multiple values per key are supported, 50 | * it will always return arrays of strings for the value parts. 51 | */ 52 | jQuery.getQueryParameters = function(s) { 53 | if (typeof s === 'undefined') 54 | s = document.location.search; 55 | var parts = s.substr(s.indexOf('?') + 1).split('&'); 56 | var result = {}; 57 | for (var i = 0; i < parts.length; i++) { 58 | var tmp = parts[i].split('=', 2); 59 | var key = jQuery.urldecode(tmp[0]); 60 | var value = jQuery.urldecode(tmp[1]); 61 | if (key in result) 62 | result[key].push(value); 63 | else 64 | result[key] = [value]; 65 | } 66 | return result; 67 | }; 68 | 69 | /** 70 | * highlight a given string on a jquery object by wrapping it in 71 | * span elements with the given class name. 72 | */ 73 | jQuery.fn.highlightText = function(text, className) { 74 | function highlight(node, addItems) { 75 | if (node.nodeType === 3) { 76 | var val = node.nodeValue; 77 | var pos = val.toLowerCase().indexOf(text); 78 | if (pos >= 0 && 79 | !jQuery(node.parentNode).hasClass(className) && 80 | !jQuery(node.parentNode).hasClass("nohighlight")) { 81 | var span; 82 | var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg"); 83 | if (isInSVG) { 84 | span = document.createElementNS("http://www.w3.org/2000/svg", "tspan"); 85 | } else { 86 | span = document.createElement("span"); 87 | span.className = className; 88 | } 89 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 90 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 91 | document.createTextNode(val.substr(pos + text.length)), 92 | node.nextSibling)); 93 | node.nodeValue = val.substr(0, pos); 94 | if (isInSVG) { 95 | var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect"); 96 | var bbox = node.parentElement.getBBox(); 97 | rect.x.baseVal.value = bbox.x; 98 | rect.y.baseVal.value = bbox.y; 99 | rect.width.baseVal.value = bbox.width; 100 | rect.height.baseVal.value = bbox.height; 101 | rect.setAttribute('class', className); 102 | addItems.push({ 103 | "parent": node.parentNode, 104 | "target": rect}); 105 | } 106 | } 107 | } 108 | else if (!jQuery(node).is("button, select, textarea")) { 109 | jQuery.each(node.childNodes, function() { 110 | highlight(this, addItems); 111 | }); 112 | } 113 | } 114 | var addItems = []; 115 | var result = this.each(function() { 116 | highlight(this, addItems); 117 | }); 118 | for (var i = 0; i < addItems.length; ++i) { 119 | jQuery(addItems[i].parent).before(addItems[i].target); 120 | } 121 | return result; 122 | }; 123 | 124 | /* 125 | * backward compatibility for jQuery.browser 126 | * This will be supported until firefox bug is fixed. 127 | */ 128 | if (!jQuery.browser) { 129 | jQuery.uaMatch = function(ua) { 130 | ua = ua.toLowerCase(); 131 | 132 | var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || 133 | /(webkit)[ \/]([\w.]+)/.exec(ua) || 134 | /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || 135 | /(msie) ([\w.]+)/.exec(ua) || 136 | ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || 137 | []; 138 | 139 | return { 140 | browser: match[ 1 ] || "", 141 | version: match[ 2 ] || "0" 142 | }; 143 | }; 144 | jQuery.browser = {}; 145 | jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true; 146 | } 147 | 148 | /** 149 | * Small JavaScript module for the documentation. 150 | */ 151 | var Documentation = { 152 | 153 | init : function() { 154 | this.fixFirefoxAnchorBug(); 155 | this.highlightSearchWords(); 156 | this.initIndexTable(); 157 | if (DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) { 158 | this.initOnKeyListeners(); 159 | } 160 | }, 161 | 162 | /** 163 | * i18n support 164 | */ 165 | TRANSLATIONS : {}, 166 | PLURAL_EXPR : function(n) { return n === 1 ? 0 : 1; }, 167 | LOCALE : 'unknown', 168 | 169 | // gettext and ngettext don't access this so that the functions 170 | // can safely bound to a different name (_ = Documentation.gettext) 171 | gettext : function(string) { 172 | var translated = Documentation.TRANSLATIONS[string]; 173 | if (typeof translated === 'undefined') 174 | return string; 175 | return (typeof translated === 'string') ? translated : translated[0]; 176 | }, 177 | 178 | ngettext : function(singular, plural, n) { 179 | var translated = Documentation.TRANSLATIONS[singular]; 180 | if (typeof translated === 'undefined') 181 | return (n == 1) ? singular : plural; 182 | return translated[Documentation.PLURALEXPR(n)]; 183 | }, 184 | 185 | addTranslations : function(catalog) { 186 | for (var key in catalog.messages) 187 | this.TRANSLATIONS[key] = catalog.messages[key]; 188 | this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')'); 189 | this.LOCALE = catalog.locale; 190 | }, 191 | 192 | /** 193 | * add context elements like header anchor links 194 | */ 195 | addContextElements : function() { 196 | $('div[id] > :header:first').each(function() { 197 | $('\u00B6'). 198 | attr('href', '#' + this.id). 199 | attr('title', _('Permalink to this headline')). 200 | appendTo(this); 201 | }); 202 | $('dt[id]').each(function() { 203 | $('\u00B6'). 204 | attr('href', '#' + this.id). 205 | attr('title', _('Permalink to this definition')). 206 | appendTo(this); 207 | }); 208 | }, 209 | 210 | /** 211 | * workaround a firefox stupidity 212 | * see: https://bugzilla.mozilla.org/show_bug.cgi?id=645075 213 | */ 214 | fixFirefoxAnchorBug : function() { 215 | if (document.location.hash && $.browser.mozilla) 216 | window.setTimeout(function() { 217 | document.location.href += ''; 218 | }, 10); 219 | }, 220 | 221 | /** 222 | * highlight the search words provided in the url in the text 223 | */ 224 | highlightSearchWords : function() { 225 | var params = $.getQueryParameters(); 226 | var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : []; 227 | if (terms.length) { 228 | var body = $('div.body'); 229 | if (!body.length) { 230 | body = $('body'); 231 | } 232 | window.setTimeout(function() { 233 | $.each(terms, function() { 234 | body.highlightText(this.toLowerCase(), 'highlighted'); 235 | }); 236 | }, 10); 237 | $('') 239 | .appendTo($('#searchbox')); 240 | } 241 | }, 242 | 243 | /** 244 | * init the domain index toggle buttons 245 | */ 246 | initIndexTable : function() { 247 | var togglers = $('img.toggler').click(function() { 248 | var src = $(this).attr('src'); 249 | var idnum = $(this).attr('id').substr(7); 250 | $('tr.cg-' + idnum).toggle(); 251 | if (src.substr(-9) === 'minus.png') 252 | $(this).attr('src', src.substr(0, src.length-9) + 'plus.png'); 253 | else 254 | $(this).attr('src', src.substr(0, src.length-8) + 'minus.png'); 255 | }).css('display', ''); 256 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) { 257 | togglers.click(); 258 | } 259 | }, 260 | 261 | /** 262 | * helper function to hide the search marks again 263 | */ 264 | hideSearchWords : function() { 265 | $('#searchbox .highlight-link').fadeOut(300); 266 | $('span.highlighted').removeClass('highlighted'); 267 | }, 268 | 269 | /** 270 | * make the url absolute 271 | */ 272 | makeURL : function(relativeURL) { 273 | return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL; 274 | }, 275 | 276 | /** 277 | * get the current relative url 278 | */ 279 | getCurrentURL : function() { 280 | var path = document.location.pathname; 281 | var parts = path.split(/\//); 282 | $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() { 283 | if (this === '..') 284 | parts.pop(); 285 | }); 286 | var url = parts.join('/'); 287 | return path.substring(url.lastIndexOf('/') + 1, path.length - 1); 288 | }, 289 | 290 | initOnKeyListeners: function() { 291 | $(document).keydown(function(event) { 292 | var activeElementType = document.activeElement.tagName; 293 | // don't navigate when in search box, textarea, dropdown or button 294 | if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT' 295 | && activeElementType !== 'BUTTON' && !event.altKey && !event.ctrlKey && !event.metaKey 296 | && !event.shiftKey) { 297 | switch (event.keyCode) { 298 | case 37: // left 299 | var prevHref = $('link[rel="prev"]').prop('href'); 300 | if (prevHref) { 301 | window.location.href = prevHref; 302 | return false; 303 | } 304 | break; 305 | case 39: // right 306 | var nextHref = $('link[rel="next"]').prop('href'); 307 | if (nextHref) { 308 | window.location.href = nextHref; 309 | return false; 310 | } 311 | break; 312 | } 313 | } 314 | }); 315 | } 316 | }; 317 | 318 | // quick alias for translations 319 | _ = Documentation.gettext; 320 | 321 | $(document).ready(function() { 322 | Documentation.init(); 323 | }); 324 | -------------------------------------------------------------------------------- /docs/static/language_data.js: -------------------------------------------------------------------------------- 1 | /* 2 | * language_data.js 3 | * ~~~~~~~~~~~~~~~~ 4 | * 5 | * This script contains the language-specific data used by searchtools.js, 6 | * namely the list of stopwords, stemmer, scorer and splitter. 7 | * 8 | * :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. 9 | * :license: BSD, see LICENSE for details. 10 | * 11 | */ 12 | 13 | var stopwords = ["a","and","are","as","at","be","but","by","for","if","in","into","is","it","near","no","not","of","on","or","such","that","the","their","then","there","these","they","this","to","was","will","with"]; 14 | 15 | 16 | /* Non-minified version is copied as a separate JS file, is available */ 17 | 18 | /** 19 | * Porter Stemmer 20 | */ 21 | var Stemmer = function() { 22 | 23 | var step2list = { 24 | ational: 'ate', 25 | tional: 'tion', 26 | enci: 'ence', 27 | anci: 'ance', 28 | izer: 'ize', 29 | bli: 'ble', 30 | alli: 'al', 31 | entli: 'ent', 32 | eli: 'e', 33 | ousli: 'ous', 34 | ization: 'ize', 35 | ation: 'ate', 36 | ator: 'ate', 37 | alism: 'al', 38 | iveness: 'ive', 39 | fulness: 'ful', 40 | ousness: 'ous', 41 | aliti: 'al', 42 | iviti: 'ive', 43 | biliti: 'ble', 44 | logi: 'log' 45 | }; 46 | 47 | var step3list = { 48 | icate: 'ic', 49 | ative: '', 50 | alize: 'al', 51 | iciti: 'ic', 52 | ical: 'ic', 53 | ful: '', 54 | ness: '' 55 | }; 56 | 57 | var c = "[^aeiou]"; // consonant 58 | var v = "[aeiouy]"; // vowel 59 | var C = c + "[^aeiouy]*"; // consonant sequence 60 | var V = v + "[aeiou]*"; // vowel sequence 61 | 62 | var mgr0 = "^(" + C + ")?" + V + C; // [C]VC... is m>0 63 | var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1 64 | var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1 65 | var s_v = "^(" + C + ")?" + v; // vowel in stem 66 | 67 | this.stemWord = function (w) { 68 | var stem; 69 | var suffix; 70 | var firstch; 71 | var origword = w; 72 | 73 | if (w.length < 3) 74 | return w; 75 | 76 | var re; 77 | var re2; 78 | var re3; 79 | var re4; 80 | 81 | firstch = w.substr(0,1); 82 | if (firstch == "y") 83 | w = firstch.toUpperCase() + w.substr(1); 84 | 85 | // Step 1a 86 | re = /^(.+?)(ss|i)es$/; 87 | re2 = /^(.+?)([^s])s$/; 88 | 89 | if (re.test(w)) 90 | w = w.replace(re,"$1$2"); 91 | else if (re2.test(w)) 92 | w = w.replace(re2,"$1$2"); 93 | 94 | // Step 1b 95 | re = /^(.+?)eed$/; 96 | re2 = /^(.+?)(ed|ing)$/; 97 | if (re.test(w)) { 98 | var fp = re.exec(w); 99 | re = new RegExp(mgr0); 100 | if (re.test(fp[1])) { 101 | re = /.$/; 102 | w = w.replace(re,""); 103 | } 104 | } 105 | else if (re2.test(w)) { 106 | var fp = re2.exec(w); 107 | stem = fp[1]; 108 | re2 = new RegExp(s_v); 109 | if (re2.test(stem)) { 110 | w = stem; 111 | re2 = /(at|bl|iz)$/; 112 | re3 = new RegExp("([^aeiouylsz])\\1$"); 113 | re4 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 114 | if (re2.test(w)) 115 | w = w + "e"; 116 | else if (re3.test(w)) { 117 | re = /.$/; 118 | w = w.replace(re,""); 119 | } 120 | else if (re4.test(w)) 121 | w = w + "e"; 122 | } 123 | } 124 | 125 | // Step 1c 126 | re = /^(.+?)y$/; 127 | if (re.test(w)) { 128 | var fp = re.exec(w); 129 | stem = fp[1]; 130 | re = new RegExp(s_v); 131 | if (re.test(stem)) 132 | w = stem + "i"; 133 | } 134 | 135 | // Step 2 136 | re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/; 137 | if (re.test(w)) { 138 | var fp = re.exec(w); 139 | stem = fp[1]; 140 | suffix = fp[2]; 141 | re = new RegExp(mgr0); 142 | if (re.test(stem)) 143 | w = stem + step2list[suffix]; 144 | } 145 | 146 | // Step 3 147 | re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/; 148 | if (re.test(w)) { 149 | var fp = re.exec(w); 150 | stem = fp[1]; 151 | suffix = fp[2]; 152 | re = new RegExp(mgr0); 153 | if (re.test(stem)) 154 | w = stem + step3list[suffix]; 155 | } 156 | 157 | // Step 4 158 | re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/; 159 | re2 = /^(.+?)(s|t)(ion)$/; 160 | if (re.test(w)) { 161 | var fp = re.exec(w); 162 | stem = fp[1]; 163 | re = new RegExp(mgr1); 164 | if (re.test(stem)) 165 | w = stem; 166 | } 167 | else if (re2.test(w)) { 168 | var fp = re2.exec(w); 169 | stem = fp[1] + fp[2]; 170 | re2 = new RegExp(mgr1); 171 | if (re2.test(stem)) 172 | w = stem; 173 | } 174 | 175 | // Step 5 176 | re = /^(.+?)e$/; 177 | if (re.test(w)) { 178 | var fp = re.exec(w); 179 | stem = fp[1]; 180 | re = new RegExp(mgr1); 181 | re2 = new RegExp(meq1); 182 | re3 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 183 | if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) 184 | w = stem; 185 | } 186 | re = /ll$/; 187 | re2 = new RegExp(mgr1); 188 | if (re.test(w) && re2.test(w)) { 189 | re = /.$/; 190 | w = w.replace(re,""); 191 | } 192 | 193 | // and turn initial Y back to y 194 | if (firstch == "y") 195 | w = firstch.toLowerCase() + w.substr(1); 196 | return w; 197 | } 198 | } 199 | 200 | 201 | 202 | 203 | var splitChars = (function() { 204 | var result = {}; 205 | var singles = [96, 180, 187, 191, 215, 247, 749, 885, 903, 907, 909, 930, 1014, 1648, 206 | 1748, 1809, 2416, 2473, 2481, 2526, 2601, 2609, 2612, 2615, 2653, 2702, 207 | 2706, 2729, 2737, 2740, 2857, 2865, 2868, 2910, 2928, 2948, 2961, 2971, 208 | 2973, 3085, 3089, 3113, 3124, 3213, 3217, 3241, 3252, 3295, 3341, 3345, 209 | 3369, 3506, 3516, 3633, 3715, 3721, 3736, 3744, 3748, 3750, 3756, 3761, 210 | 3781, 3912, 4239, 4347, 4681, 4695, 4697, 4745, 4785, 4799, 4801, 4823, 211 | 4881, 5760, 5901, 5997, 6313, 7405, 8024, 8026, 8028, 8030, 8117, 8125, 212 | 8133, 8181, 8468, 8485, 8487, 8489, 8494, 8527, 11311, 11359, 11687, 11695, 213 | 11703, 11711, 11719, 11727, 11735, 12448, 12539, 43010, 43014, 43019, 43587, 214 | 43696, 43713, 64286, 64297, 64311, 64317, 64319, 64322, 64325, 65141]; 215 | var i, j, start, end; 216 | for (i = 0; i < singles.length; i++) { 217 | result[singles[i]] = true; 218 | } 219 | var ranges = [[0, 47], [58, 64], [91, 94], [123, 169], [171, 177], [182, 184], [706, 709], 220 | [722, 735], [741, 747], [751, 879], [888, 889], [894, 901], [1154, 1161], 221 | [1318, 1328], [1367, 1368], [1370, 1376], [1416, 1487], [1515, 1519], [1523, 1568], 222 | [1611, 1631], [1642, 1645], [1750, 1764], [1767, 1773], [1789, 1790], [1792, 1807], 223 | [1840, 1868], [1958, 1968], [1970, 1983], [2027, 2035], [2038, 2041], [2043, 2047], 224 | [2070, 2073], [2075, 2083], [2085, 2087], [2089, 2307], [2362, 2364], [2366, 2383], 225 | [2385, 2391], [2402, 2405], [2419, 2424], [2432, 2436], [2445, 2446], [2449, 2450], 226 | [2483, 2485], [2490, 2492], [2494, 2509], [2511, 2523], [2530, 2533], [2546, 2547], 227 | [2554, 2564], [2571, 2574], [2577, 2578], [2618, 2648], [2655, 2661], [2672, 2673], 228 | [2677, 2692], [2746, 2748], [2750, 2767], [2769, 2783], [2786, 2789], [2800, 2820], 229 | [2829, 2830], [2833, 2834], [2874, 2876], [2878, 2907], [2914, 2917], [2930, 2946], 230 | [2955, 2957], [2966, 2968], [2976, 2978], [2981, 2983], [2987, 2989], [3002, 3023], 231 | [3025, 3045], [3059, 3076], [3130, 3132], [3134, 3159], [3162, 3167], [3170, 3173], 232 | [3184, 3191], [3199, 3204], [3258, 3260], [3262, 3293], [3298, 3301], [3312, 3332], 233 | [3386, 3388], [3390, 3423], [3426, 3429], [3446, 3449], [3456, 3460], [3479, 3481], 234 | [3518, 3519], [3527, 3584], [3636, 3647], [3655, 3663], [3674, 3712], [3717, 3718], 235 | [3723, 3724], [3726, 3731], [3752, 3753], [3764, 3772], [3774, 3775], [3783, 3791], 236 | [3802, 3803], [3806, 3839], [3841, 3871], [3892, 3903], [3949, 3975], [3980, 4095], 237 | [4139, 4158], [4170, 4175], [4182, 4185], [4190, 4192], [4194, 4196], [4199, 4205], 238 | [4209, 4212], [4226, 4237], [4250, 4255], [4294, 4303], [4349, 4351], [4686, 4687], 239 | [4702, 4703], [4750, 4751], [4790, 4791], [4806, 4807], [4886, 4887], [4955, 4968], 240 | [4989, 4991], [5008, 5023], [5109, 5120], [5741, 5742], [5787, 5791], [5867, 5869], 241 | [5873, 5887], [5906, 5919], [5938, 5951], [5970, 5983], [6001, 6015], [6068, 6102], 242 | [6104, 6107], [6109, 6111], [6122, 6127], [6138, 6159], [6170, 6175], [6264, 6271], 243 | [6315, 6319], [6390, 6399], [6429, 6469], [6510, 6511], [6517, 6527], [6572, 6592], 244 | [6600, 6607], [6619, 6655], [6679, 6687], [6741, 6783], [6794, 6799], [6810, 6822], 245 | [6824, 6916], [6964, 6980], [6988, 6991], [7002, 7042], [7073, 7085], [7098, 7167], 246 | [7204, 7231], [7242, 7244], [7294, 7400], [7410, 7423], [7616, 7679], [7958, 7959], 247 | [7966, 7967], [8006, 8007], [8014, 8015], [8062, 8063], [8127, 8129], [8141, 8143], 248 | [8148, 8149], [8156, 8159], [8173, 8177], [8189, 8303], [8306, 8307], [8314, 8318], 249 | [8330, 8335], [8341, 8449], [8451, 8454], [8456, 8457], [8470, 8472], [8478, 8483], 250 | [8506, 8507], [8512, 8516], [8522, 8525], [8586, 9311], [9372, 9449], [9472, 10101], 251 | [10132, 11263], [11493, 11498], [11503, 11516], [11518, 11519], [11558, 11567], 252 | [11622, 11630], [11632, 11647], [11671, 11679], [11743, 11822], [11824, 12292], 253 | [12296, 12320], [12330, 12336], [12342, 12343], [12349, 12352], [12439, 12444], 254 | [12544, 12548], [12590, 12592], [12687, 12689], [12694, 12703], [12728, 12783], 255 | [12800, 12831], [12842, 12880], [12896, 12927], [12938, 12976], [12992, 13311], 256 | [19894, 19967], [40908, 40959], [42125, 42191], [42238, 42239], [42509, 42511], 257 | [42540, 42559], [42592, 42593], [42607, 42622], [42648, 42655], [42736, 42774], 258 | [42784, 42785], [42889, 42890], [42893, 43002], [43043, 43055], [43062, 43071], 259 | [43124, 43137], [43188, 43215], [43226, 43249], [43256, 43258], [43260, 43263], 260 | [43302, 43311], [43335, 43359], [43389, 43395], [43443, 43470], [43482, 43519], 261 | [43561, 43583], [43596, 43599], [43610, 43615], [43639, 43641], [43643, 43647], 262 | [43698, 43700], [43703, 43704], [43710, 43711], [43715, 43738], [43742, 43967], 263 | [44003, 44015], [44026, 44031], [55204, 55215], [55239, 55242], [55292, 55295], 264 | [57344, 63743], [64046, 64047], [64110, 64111], [64218, 64255], [64263, 64274], 265 | [64280, 64284], [64434, 64466], [64830, 64847], [64912, 64913], [64968, 65007], 266 | [65020, 65135], [65277, 65295], [65306, 65312], [65339, 65344], [65371, 65381], 267 | [65471, 65473], [65480, 65481], [65488, 65489], [65496, 65497]]; 268 | for (i = 0; i < ranges.length; i++) { 269 | start = ranges[i][0]; 270 | end = ranges[i][1]; 271 | for (j = start; j <= end; j++) { 272 | result[j] = true; 273 | } 274 | } 275 | return result; 276 | })(); 277 | 278 | function splitQuery(query) { 279 | var result = []; 280 | var start = -1; 281 | for (var i = 0; i < query.length; i++) { 282 | if (splitChars[query.charCodeAt(i)]) { 283 | if (start !== -1) { 284 | result.push(query.slice(start, i)); 285 | start = -1; 286 | } 287 | } else if (start === -1) { 288 | start = i; 289 | } 290 | } 291 | if (start !== -1) { 292 | result.push(query.slice(start)); 293 | } 294 | return result; 295 | } 296 | 297 | 298 | -------------------------------------------------------------------------------- /docs/usage_normal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Usage as a C Library — cryptosuite2 0.2.6 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 |
35 | 36 |
37 |

Usage as a C Library

38 |
39 |

Contents

40 | 56 |
57 |
58 |

SHA256

59 |
60 |

API Doc

61 |
62 |
sha256_hasher_new(void): sha256_hasher_t

Allocate and initialize a new hasher.

63 |
64 |
sha256_hasher_del(sha256_hasher_t hasher): void

Free the hasher.

65 |
66 |
sha256_hasher_init(sha256_hasher_t hasher)

(Re-) Initialize the hasher for hashing.

67 |
68 |
sha256_hasher_putc(sha256_hasher_t hasher, uint8_t byte): int

Put byte to the hasher. Follows the standard 69 | putc conventions.

70 |
71 |
sha256_hasher_gethash(sha256_hasher_t hasher): uint8_t *

Returns a reference of the hash. One must 72 | not free the result. This modifies the state of 73 | the hasher. Once this function has been called, 74 | sha256_hasher_init must be invoked or 75 | sha256_hasher_putc will fail.

76 |
77 |
sha256_hasher_write(sha256_hasher_t hasher, const void * buf, size_t count): ssize_t

Writes to the hasher. Follows the standard write 78 | conventions and uses sha256_hasher_putc.

79 |
80 |
81 |

If SHA256_ENABLE_HMAC is defined in sha256/default.h 82 | also the following functions are available:

83 |
84 |
sha256_hasher_init_hmac(sha256_hasher_t hasher, const uint8_t * key, size_t key_len): void

Initialize the hasher for HMAC. Invokes 85 | sha256_hasher_init.

86 |
87 |
sha256_hasher_gethmac(sha256_hasher_t hasher): uint8_t *

Returns a reference of the hash. One must 88 | not free the result. This modifies the state of 89 | the hasher. Once this function has been called, 90 | sha256_hasher_init must be invoked or 91 | sha256_hasher_putc will fail.

92 |
93 |
94 |
95 |
96 |
97 |

SHA1

98 |
99 |

API Doc

100 |
101 |
sha1_hasher_new(void): sha1_hasher_t

Allocate and initialize a new hasher.

102 |
103 |
sha1_hasher_del(sha1_hasher_t hasher): void

Free the hasher.

104 |
105 |
sha1_hasher_init(sha1_hasher_t hasher)

(Re-) Initialize the hasher for hashing.

106 |
107 |
sha1_hasher_putc(sha1_hasher_t hasher, uint8_t byte): int

Put byte to the hasher. Follows the standard 108 | putc conventions.

109 |
110 |
sha1_hasher_gethash(sha1_hasher_t hasher): uint8_t *

Returns a reference of the hash. One must 111 | not free the result. This modifies the state of 112 | the hasher. Once this function has been called, 113 | sha1_hasher_init must be invoked or 114 | sha1_hasher_putc will fail.

115 |
116 |
sha1_hasher_write(sha1_hasher_t hasher, const void * buf, size_t count): ssize_t

Writes to the hasher. Follows the standard write 117 | conventions and uses sha1_hasher_putc.

118 |
119 |
120 |

If SHA1_ENABLE_HMAC is defined in sha1/default.h 121 | also the following functions are available:

122 |
123 |
sha1_hasher_init_hmac(sha1_hasher_t hasher, const uint8_t * key, size_t key_len): void

Initialize the hasher for HMAC. Invokes 124 | sha1_hasher_init.

125 |
126 |
sha1_hasher_gethmac(sha1_hasher_t hasher): uint8_t *

Returns a reference of the hash. One must 127 | not free the result. This modifies the state of 128 | the hasher. Once this function has been called, 129 | sha1_hasher_init must be invoked or 130 | sha1_hasher_putc will fail.

131 |
132 |
133 |
134 |
135 |
136 | 137 | 138 |
139 | 140 |
141 |
142 | 195 |
196 |
197 | 208 | 209 | 210 | 211 | 212 | 213 | -------------------------------------------------------------------------------- /doc/source/usage_arduino.rst: -------------------------------------------------------------------------------- 1 | Usage with Arduino 2 | ****************** 3 | 4 | .. contents:: 5 | 6 | 7 | General 8 | ::::::: 9 | 10 | Optimization and Disabling Code Objects 11 | ======================================= 12 | 13 | Code objects eat up your precious flash memory. It is 14 | therefore important to disable all the code you do not need. 15 | 16 | This can be done using the file ``config.h`` in the library 17 | folder of cryptosuite2. This file includes the module 18 | configuration first so you can overwrite the module 19 | configuration. 20 | 21 | The first thing one should do is to disable modules you do 22 | not need. This is done by defining ``SHA256_DISABLED`` or 23 | ``SHA1_DISABLED``. All code for these modules will then be 24 | excluded. 25 | 26 | Also you can disable *HMAC* to save both flash memory and 27 | RAM using ``#undef SHA256_ENABLE_HMAC`` and 28 | ``#undef SHA1_ENABLE_HMAC``. 29 | 30 | The last thing one can do is to disable the ``C++`` 31 | interface (see the sections below about how to use the ``C`` 32 | interface) by defining ``SHA256_DISABLE_WRAPPER`` and 33 | ``SHA1_DISABLE_WRAPPER``. 34 | 35 | 36 | Sha256 37 | :::::: 38 | 39 | Simple Usage 40 | ============ 41 | 42 | cryptosuite2 brings a C++ interface that can be used by 43 | Arduino users easily. 44 | 45 | 46 | After including the header one can use the class 47 | ``Sha256Wrapper`` with the methods 48 | 49 | ``init(void): void`` 50 | Initializes the ``Sha256Wrapper`` for hashing. 51 | Must be invoked before hashing. 52 | ``result(void): uint8_t *`` 53 | Returns **a reference** to the hash. Once this 54 | method has been called ``init`` must be invoked 55 | again. 56 | ``write(various types): size_t`` 57 | Write data into the hasher. 58 | 59 | If the preprocessor macro ``SHA256_ENABLE_HMAC`` in 60 | ``config.h`` is set (which it is by default) [1]_ the 61 | following methods are available: 62 | 63 | ``initHmac(const uint8_t * secret, unsigned int secretLength): void`` 64 | Initializes the ``Sha256Wrapper`` for HMAC. 65 | ``resultHmac(void): uint8_t *`` 66 | Returns **a reference** to the hash. Once this 67 | method has been called ``init`` must be invoked 68 | again. 69 | 70 | ``sha256.h`` also brings a global hasher: ``Sha256``. 71 | 72 | Example: 73 | 74 | .. code-block:: c++ 75 | 76 | #include "sha256.h" 77 | 78 | // read data from the serial interface and print the 79 | // hash to the serial 80 | 81 | void setup(void) 82 | { 83 | Serial.begin(9600); 84 | } 85 | 86 | void loop(void) 87 | { 88 | if(!Serial.available()) 89 | { 90 | return; 91 | } 92 | Sha256.init(); 93 | 94 | Sha256.print(Serial.read()); 95 | 96 | uint8_t * result = Sha256.result(); 97 | 98 | Serial.print("Hash:\n"); 99 | 100 | for (int i = 0; i < 32; i++) { 101 | Serial.print("0123456789abcdef"[result[i] >> 4]); 102 | Serial.print("0123456789abcdef"[result[i] & 0xf]); 103 | } 104 | Serial.print("\n"); 105 | } 106 | 107 | 108 | The same way *HMAC* can be used: 109 | 110 | .. code-block:: c++ 111 | 112 | #include "sha256.h" 113 | 114 | void setup(void) 115 | { 116 | Serial.begin(9600); 117 | 118 | // this is actually the RFC4231 4.3 test 119 | 120 | Sha256.initHmac((uint8_t * ) "Jefe", 4); 121 | Sha256.print("what do ya want for nothing?"); 122 | uint8_t * result = Sha256.resultHmac(); 123 | 124 | Serial.println("Expect: 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843"); 125 | Serial.print( "Got : "); 126 | for (int i = 0; i < 32; i++) { 127 | Serial.print("0123456789abcdef"[result[i] >> 4]); 128 | Serial.print("0123456789abcdef"[result[i] & 0xf]); 129 | } 130 | Serial.print("\n"); 131 | } 132 | 133 | 134 | void loop(void) 135 | {} 136 | 137 | Extended 138 | ======== 139 | 140 | Disabling the ``C++`` Wrapper 141 | ----------------------------- 142 | 143 | The ``C++`` wrapper increases the overhead and eats up some 144 | RAM. So one can disable the wrapper by defining 145 | ``SHA256_DISABLE_WRAPPER`` in ``config.h`` 146 | 147 | .. code-block:: c++ 148 | 149 | #define SHA256_DISABLE_WRAPPER 150 | 151 | 152 | Instantiating a new Hasher 153 | -------------------------- 154 | 155 | A new hasher can be created by calling ``sha256_hasher_new``: 156 | 157 | .. code-block:: c++ 158 | 159 | 160 | #define SHA256_DISABLE_WRAPPER 161 | #include "sha256.h" 162 | 163 | 164 | sha256_hasher_t hasher; 165 | 166 | void setup(void) 167 | { 168 | hasher = sha256_hasher_new(); 169 | Serial.begin(9600); 170 | } 171 | 172 | 173 | Writing to the Hasher 174 | --------------------- 175 | 176 | Before one writes to the hasher he should invoke 177 | ``sha256_hasher_init``, although this function has been 178 | called by ``sha256_hasher_new``. Then he can write safely: 179 | 180 | .. code-block:: c++ 181 | 182 | void loop(void) 183 | { 184 | sha256_hasher_init(hasher); 185 | 186 | sha256_hasher_write(hasher, "abc", 3); 187 | } 188 | 189 | Obtaining the Result and free'ing the Hasher 190 | -------------------------------------------- 191 | 192 | .. code-block:: c++ 193 | 194 | void loop(void) 195 | { 196 | sha256_hasher_init(hasher); 197 | sha256_hasher_write(hasher, "abc", 3); 198 | 199 | uint8_t * result; 200 | result = sha256_hasher_gethash(hasher); 201 | 202 | Serial.print("EXPECT: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad\n"); 203 | Serial.print("GOT : "); 204 | for (int i = 0; i < 32; i++) { 205 | Serial.print("0123456789abcdef"[result[i] >> 4]); 206 | Serial.print("0123456789abcdef"[result[i] & 0xf]); 207 | } 208 | Serial.print("\n"); 209 | 210 | // do not actually delete the hasher 211 | // we are inside loop 212 | 213 | // sha256_hasher_del(hasher); 214 | 215 | } 216 | 217 | 218 | API Doc 219 | ------- 220 | 221 | ``sha256_hasher_new(void): sha256_hasher_t`` 222 | Allocate and initialize a new hasher. 223 | ``sha256_hasher_del(sha256_hasher_t hasher): void`` 224 | Free the hasher. 225 | ``sha256_hasher_init(sha256_hasher_t hasher)`` 226 | (Re-) Initialize the hasher for hashing. 227 | ``sha256_hasher_putc(sha256_hasher_t hasher, uint8_t byte): int`` 228 | Put ``byte`` to the hasher. Follows the standard 229 | ``putc`` conventions. 230 | ``sha256_hasher_gethash(sha256_hasher_t hasher): uint8_t *`` 231 | Returns **a reference** of the hash. One **must 232 | not** free the result. This modifies the state of 233 | the hasher. Once this function has been called, 234 | ``sha256_hasher_init`` must be invoked or 235 | ``sha256_hasher_putc`` will fail. 236 | ``sha256_hasher_write(sha256_hasher_t hasher, const void * buf, size_t count): ssize_t`` 237 | Writes to the hasher. Follows the standard ``write`` 238 | conventions and uses ``sha256_hasher_putc``. 239 | 240 | If ``SHA256_ENABLE_HMAC`` is defined in ``config.h`` 241 | also the following functions are available: 242 | 243 | ``sha256_hasher_init_hmac(sha256_hasher_t hasher, const uint8_t * key, size_t key_len): void`` 244 | Initialize the hasher for *HMAC*. Invokes 245 | ``sha256_hasher_init``. 246 | ``sha256_hasher_gethmac(sha256_hasher_t hasher): uint8_t *`` 247 | Returns **a reference** of the hash. One **must 248 | not** free the result. This modifies the state of 249 | the hasher. Once this function has been called, 250 | ``sha256_hasher_init`` must be invoked or 251 | ``sha256_hasher_putc`` will fail. 252 | 253 | 254 | Sha1 255 | :::: 256 | 257 | Simple Usage 258 | ============ 259 | 260 | cryptosuite2 brings a C++ interface that can be used by 261 | Arduino users easily. 262 | 263 | 264 | After including the header one can use the class 265 | ``Sha1Wrapper`` with the methods 266 | 267 | ``init(void): void`` 268 | Initializes the ``Sha1Wrapper`` for hashing. 269 | Must be invoked before hashing. 270 | ``result(void): uint8_t *`` 271 | Returns **a reference** to the hash. Once this 272 | method has been called ``init`` must be invoked 273 | again. 274 | ``write(various types): size_t`` 275 | Write data into the hasher. 276 | 277 | If the preprocessor macro ``SHA1_ENABLE_HMAC`` in 278 | ``config.h`` is set (which it is by default) [1]_ the 279 | following methods are available: 280 | 281 | ``initHmac(const uint8_t * secret, unsigned int secretLength): void`` 282 | Initializes the ``Sha1Wrapper`` for HMAC. 283 | ``resultHmac(void): uint8_t *`` 284 | Returns **a reference** to the hash. Once this 285 | method has been called ``init`` must be invoked 286 | again. 287 | 288 | ``sha1.h`` also brings a global hasher: ``Sha1``. 289 | 290 | Example: 291 | 292 | .. code-block:: c++ 293 | 294 | #include "sha1.h" 295 | 296 | // read data from the serial interface and print the 297 | // hash to the serial 298 | 299 | void setup(void) 300 | { 301 | Serial.begin(9600); 302 | } 303 | 304 | void loop(void) 305 | { 306 | if(!Serial.available()) 307 | { 308 | return; 309 | } 310 | Sha1.init(); 311 | 312 | Sha1.print(Serial.read()); 313 | 314 | uint8_t * result = Sha1.result(); 315 | 316 | Serial.print("Hash:\n"); 317 | 318 | for (int i = 0; i < 10; i++) { 319 | Serial.print("0123456789abcdef"[result[i] >> 4]); 320 | Serial.print("0123456789abcdef"[result[i] & 0xf]); 321 | } 322 | Serial.print("\n"); 323 | } 324 | 325 | 326 | The same way *HMAC* can be used: 327 | 328 | .. code-block:: c++ 329 | 330 | #include "sha1.h" 331 | 332 | void setup(void) 333 | { 334 | Serial.begin(9600); 335 | 336 | // this is actually the RFC4231 4.3 test 337 | 338 | Sha1.initHmac((uint8_t * ) "Jefe", 4); 339 | Sha1.print("what do ya want for nothing?"); 340 | uint8_t * result = Sha1.resultHmac(); 341 | 342 | Serial.println("Expect: b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7"); 343 | Serial.print( "Got : "); 344 | for (int i = 0; i < 10; i++) { 345 | Serial.print("0123456789abcdef"[result[i] >> 4]); 346 | Serial.print("0123456789abcdef"[result[i] & 0xf]); 347 | } 348 | Serial.print("\n"); 349 | } 350 | 351 | 352 | void loop(void) 353 | {} 354 | 355 | Extended 356 | ======== 357 | 358 | Disabling the ``C++`` Wrapper 359 | ----------------------------- 360 | 361 | The ``C++`` wrapper increases the overhead and eats up some 362 | RAM. So one can disable the wrapper by defining 363 | ``SHA1_DISABLE_WRAPPER`` in ``config.h``: 364 | 365 | .. code-block:: c++ 366 | 367 | #define SHA1_DISABLE_WRAPPER 368 | 369 | 370 | Instantiating a new Hasher 371 | -------------------------- 372 | 373 | A new hasher can be created by calling ``sha1_hasher_new``: 374 | 375 | .. code-block:: c++ 376 | 377 | 378 | #define SHA1_DISABLE_WRAPPER 379 | #include "sha1.h" 380 | 381 | 382 | sha1_hasher_t hasher; 383 | 384 | void setup(void) 385 | { 386 | hasher = sha1_hasher_new(); 387 | Serial.begin(9600); 388 | } 389 | 390 | 391 | Writing to the Hasher 392 | --------------------- 393 | 394 | Before one writes to the hasher he should invoke 395 | ``sha1_hasher_init``, although this function has been 396 | called by ``sha1_hasher_new``. Then he can write safely: 397 | 398 | .. code-block:: c++ 399 | 400 | void loop(void) 401 | { 402 | sha1_hasher_init(hasher); 403 | 404 | sha1_hasher_write(hasher, "abc", 3); 405 | } 406 | 407 | Obtaining the Result and free'ing the Hasher 408 | -------------------------------------------- 409 | 410 | .. code-block:: c++ 411 | 412 | void loop(void) 413 | { 414 | sha1_hasher_init(hasher); 415 | sha1_hasher_write(hasher, "abc", 3); 416 | 417 | uint8_t * result; 418 | result = sha1_hasher_gethash(hasher); 419 | 420 | Serial.print("EXPECT: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad\n"); 421 | Serial.print("GOT : "); 422 | for (int i = 0; i < 10; i++) { 423 | Serial.print("0123456789abcdef"[result[i] >> 4]); 424 | Serial.print("0123456789abcdef"[result[i] & 0xf]); 425 | } 426 | Serial.print("\n"); 427 | 428 | // do not actually delete the hasher 429 | // we are inside loop 430 | 431 | // sha1_hasher_del(hasher); 432 | 433 | } 434 | 435 | 436 | API Doc 437 | ------- 438 | 439 | ``sha1_hasher_new(void): sha1_hasher_t`` 440 | Allocate and initialize a new hasher. 441 | ``sha1_hasher_del(sha1_hasher_t hasher): void`` 442 | Free the hasher. 443 | ``sha1_hasher_init(sha1_hasher_t hasher)`` 444 | (Re-) Initialize the hasher for hashing. 445 | ``sha1_hasher_putc(sha1_hasher_t hasher, uint8_t byte): int`` 446 | Put ``byte`` to the hasher. Follows the standard 447 | ``putc`` conventions. 448 | ``sha1_hasher_gethash(sha1_hasher_t hasher): uint8_t *`` 449 | Returns **a reference** of the hash. One **must 450 | not** free the result. This modifies the state of 451 | the hasher. Once this function has been called, 452 | ``sha1_hasher_init`` must be invoked or 453 | ``sha1_hasher_putc`` will fail. 454 | ``sha1_hasher_write(sha1_hasher_t hasher, const void * buf, size_t count): ssize_t`` 455 | Writes to the hasher. Follows the standard ``write`` 456 | conventions and uses ``sha1_hasher_putc``. 457 | 458 | If ``SHA1_ENABLE_HMAC`` is defined in ``config.h`` 459 | also the following functions are available: 460 | 461 | ``sha1_hasher_init_hmac(sha1_hasher_t hasher, const uint8_t * key, size_t key_len): void`` 462 | Initialize the hasher for *HMAC*. Invokes 463 | ``sha1_hasher_init``. 464 | ``sha1_hasher_gethmac(sha1_hasher_t hasher): uint8_t *`` 465 | Returns **a reference** of the hash. One **must 466 | not** free the result. This modifies the state of 467 | the hasher. Once this function has been called, 468 | ``sha1_hasher_init`` must be invoked or 469 | ``sha1_hasher_putc`` will fail. 470 | 471 | 472 | 473 | 474 | 475 | .. [1] ``config.h`` includes ``shaX/default.h``. Some 476 | configuration is done here. When using the Arduino 477 | interface one should only edit ``config.h``. 478 | -------------------------------------------------------------------------------- /docs/sources/usage_arduino.rst.txt: -------------------------------------------------------------------------------- 1 | Usage with Arduino 2 | ****************** 3 | 4 | .. contents:: 5 | 6 | 7 | General 8 | ::::::: 9 | 10 | Optimization and Disabling Code Objects 11 | ======================================= 12 | 13 | Code objects eat up your precious flash memory. It is 14 | therefore important to disable all the code you do not need. 15 | 16 | This can be done using the file ``config.h`` in the library 17 | folder of cryptosuite2. This file includes the module 18 | configuration first so you can overwrite the module 19 | configuration. 20 | 21 | The first thing one should do is to disable modules you do 22 | not need. This is done by defining ``SHA256_DISABLED`` or 23 | ``SHA1_DISABLED``. All code for these modules will then be 24 | excluded. 25 | 26 | Also you can disable *HMAC* to save both flash memory and 27 | RAM using ``#undef SHA256_ENABLE_HMAC`` and 28 | ``#undef SHA1_ENABLE_HMAC``. 29 | 30 | The last thing one can do is to disable the ``C++`` 31 | interface (see the sections below about how to use the ``C`` 32 | interface) by defining ``SHA256_DISABLE_WRAPPER`` and 33 | ``SHA1_DISABLE_WRAPPER``. 34 | 35 | 36 | Sha256 37 | :::::: 38 | 39 | Simple Usage 40 | ============ 41 | 42 | cryptosuite2 brings a C++ interface that can be used by 43 | Arduino users easily. 44 | 45 | 46 | After including the header one can use the class 47 | ``Sha256Wrapper`` with the methods 48 | 49 | ``init(void): void`` 50 | Initializes the ``Sha256Wrapper`` for hashing. 51 | Must be invoked before hashing. 52 | ``result(void): uint8_t *`` 53 | Returns **a reference** to the hash. Once this 54 | method has been called ``init`` must be invoked 55 | again. 56 | ``write(various types): size_t`` 57 | Write data into the hasher. 58 | 59 | If the preprocessor macro ``SHA256_ENABLE_HMAC`` in 60 | ``config.h`` is set (which it is by default) [1]_ the 61 | following methods are available: 62 | 63 | ``initHmac(const uint8_t * secret, unsigned int secretLength): void`` 64 | Initializes the ``Sha256Wrapper`` for HMAC. 65 | ``resultHmac(void): uint8_t *`` 66 | Returns **a reference** to the hash. Once this 67 | method has been called ``init`` must be invoked 68 | again. 69 | 70 | ``sha256.h`` also brings a global hasher: ``Sha256``. 71 | 72 | Example: 73 | 74 | .. code-block:: c++ 75 | 76 | #include "sha256.h" 77 | 78 | // read data from the serial interface and print the 79 | // hash to the serial 80 | 81 | void setup(void) 82 | { 83 | Serial.begin(9600); 84 | } 85 | 86 | void loop(void) 87 | { 88 | if(!Serial.available()) 89 | { 90 | return; 91 | } 92 | Sha256.init(); 93 | 94 | Sha256.print(Serial.read()); 95 | 96 | uint8_t * result = Sha256.result(); 97 | 98 | Serial.print("Hash:\n"); 99 | 100 | for (int i = 0; i < 32; i++) { 101 | Serial.print("0123456789abcdef"[result[i] >> 4]); 102 | Serial.print("0123456789abcdef"[result[i] & 0xf]); 103 | } 104 | Serial.print("\n"); 105 | } 106 | 107 | 108 | The same way *HMAC* can be used: 109 | 110 | .. code-block:: c++ 111 | 112 | #include "sha256.h" 113 | 114 | void setup(void) 115 | { 116 | Serial.begin(9600); 117 | 118 | // this is actually the RFC4231 4.3 test 119 | 120 | Sha256.initHmac((uint8_t * ) "Jefe", 4); 121 | Sha256.print("what do ya want for nothing?"); 122 | uint8_t * result = Sha256.resultHmac(); 123 | 124 | Serial.println("Expect: 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843"); 125 | Serial.print( "Got : "); 126 | for (int i = 0; i < 32; i++) { 127 | Serial.print("0123456789abcdef"[result[i] >> 4]); 128 | Serial.print("0123456789abcdef"[result[i] & 0xf]); 129 | } 130 | Serial.print("\n"); 131 | } 132 | 133 | 134 | void loop(void) 135 | {} 136 | 137 | Extended 138 | ======== 139 | 140 | Disabling the ``C++`` Wrapper 141 | ----------------------------- 142 | 143 | The ``C++`` wrapper increases the overhead and eats up some 144 | RAM. So one can disable the wrapper by defining 145 | ``SHA256_DISABLE_WRAPPER`` in ``config.h`` 146 | 147 | .. code-block:: c++ 148 | 149 | #define SHA256_DISABLE_WRAPPER 150 | 151 | 152 | Instantiating a new Hasher 153 | -------------------------- 154 | 155 | A new hasher can be created by calling ``sha256_hasher_new``: 156 | 157 | .. code-block:: c++ 158 | 159 | 160 | #define SHA256_DISABLE_WRAPPER 161 | #include "sha256.h" 162 | 163 | 164 | sha256_hasher_t hasher; 165 | 166 | void setup(void) 167 | { 168 | hasher = sha256_hasher_new(); 169 | Serial.begin(9600); 170 | } 171 | 172 | 173 | Writing to the Hasher 174 | --------------------- 175 | 176 | Before one writes to the hasher he should invoke 177 | ``sha256_hasher_init``, although this function has been 178 | called by ``sha256_hasher_new``. Then he can write safely: 179 | 180 | .. code-block:: c++ 181 | 182 | void loop(void) 183 | { 184 | sha256_hasher_init(hasher); 185 | 186 | sha256_hasher_write(hasher, "abc", 3); 187 | } 188 | 189 | Obtaining the Result and free'ing the Hasher 190 | -------------------------------------------- 191 | 192 | .. code-block:: c++ 193 | 194 | void loop(void) 195 | { 196 | sha256_hasher_init(hasher); 197 | sha256_hasher_write(hasher, "abc", 3); 198 | 199 | uint8_t * result; 200 | result = sha256_hasher_gethash(hasher); 201 | 202 | Serial.print("EXPECT: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad\n"); 203 | Serial.print("GOT : "); 204 | for (int i = 0; i < 32; i++) { 205 | Serial.print("0123456789abcdef"[result[i] >> 4]); 206 | Serial.print("0123456789abcdef"[result[i] & 0xf]); 207 | } 208 | Serial.print("\n"); 209 | 210 | // do not actually delete the hasher 211 | // we are inside loop 212 | 213 | // sha256_hasher_del(hasher); 214 | 215 | } 216 | 217 | 218 | API Doc 219 | ------- 220 | 221 | ``sha256_hasher_new(void): sha256_hasher_t`` 222 | Allocate and initialize a new hasher. 223 | ``sha256_hasher_del(sha256_hasher_t hasher): void`` 224 | Free the hasher. 225 | ``sha256_hasher_init(sha256_hasher_t hasher)`` 226 | (Re-) Initialize the hasher for hashing. 227 | ``sha256_hasher_putc(sha256_hasher_t hasher, uint8_t byte): int`` 228 | Put ``byte`` to the hasher. Follows the standard 229 | ``putc`` conventions. 230 | ``sha256_hasher_gethash(sha256_hasher_t hasher): uint8_t *`` 231 | Returns **a reference** of the hash. One **must 232 | not** free the result. This modifies the state of 233 | the hasher. Once this function has been called, 234 | ``sha256_hasher_init`` must be invoked or 235 | ``sha256_hasher_putc`` will fail. 236 | ``sha256_hasher_write(sha256_hasher_t hasher, const void * buf, size_t count): ssize_t`` 237 | Writes to the hasher. Follows the standard ``write`` 238 | conventions and uses ``sha256_hasher_putc``. 239 | 240 | If ``SHA256_ENABLE_HMAC`` is defined in ``config.h`` 241 | also the following functions are available: 242 | 243 | ``sha256_hasher_init_hmac(sha256_hasher_t hasher, const uint8_t * key, size_t key_len): void`` 244 | Initialize the hasher for *HMAC*. Invokes 245 | ``sha256_hasher_init``. 246 | ``sha256_hasher_gethmac(sha256_hasher_t hasher): uint8_t *`` 247 | Returns **a reference** of the hash. One **must 248 | not** free the result. This modifies the state of 249 | the hasher. Once this function has been called, 250 | ``sha256_hasher_init`` must be invoked or 251 | ``sha256_hasher_putc`` will fail. 252 | 253 | 254 | Sha1 255 | :::: 256 | 257 | Simple Usage 258 | ============ 259 | 260 | cryptosuite2 brings a C++ interface that can be used by 261 | Arduino users easily. 262 | 263 | 264 | After including the header one can use the class 265 | ``Sha1Wrapper`` with the methods 266 | 267 | ``init(void): void`` 268 | Initializes the ``Sha1Wrapper`` for hashing. 269 | Must be invoked before hashing. 270 | ``result(void): uint8_t *`` 271 | Returns **a reference** to the hash. Once this 272 | method has been called ``init`` must be invoked 273 | again. 274 | ``write(various types): size_t`` 275 | Write data into the hasher. 276 | 277 | If the preprocessor macro ``SHA1_ENABLE_HMAC`` in 278 | ``config.h`` is set (which it is by default) [1]_ the 279 | following methods are available: 280 | 281 | ``initHmac(const uint8_t * secret, unsigned int secretLength): void`` 282 | Initializes the ``Sha1Wrapper`` for HMAC. 283 | ``resultHmac(void): uint8_t *`` 284 | Returns **a reference** to the hash. Once this 285 | method has been called ``init`` must be invoked 286 | again. 287 | 288 | ``sha1.h`` also brings a global hasher: ``Sha1``. 289 | 290 | Example: 291 | 292 | .. code-block:: c++ 293 | 294 | #include "sha1.h" 295 | 296 | // read data from the serial interface and print the 297 | // hash to the serial 298 | 299 | void setup(void) 300 | { 301 | Serial.begin(9600); 302 | } 303 | 304 | void loop(void) 305 | { 306 | if(!Serial.available()) 307 | { 308 | return; 309 | } 310 | Sha1.init(); 311 | 312 | Sha1.print(Serial.read()); 313 | 314 | uint8_t * result = Sha1.result(); 315 | 316 | Serial.print("Hash:\n"); 317 | 318 | for (int i = 0; i < 10; i++) { 319 | Serial.print("0123456789abcdef"[result[i] >> 4]); 320 | Serial.print("0123456789abcdef"[result[i] & 0xf]); 321 | } 322 | Serial.print("\n"); 323 | } 324 | 325 | 326 | The same way *HMAC* can be used: 327 | 328 | .. code-block:: c++ 329 | 330 | #include "sha1.h" 331 | 332 | void setup(void) 333 | { 334 | Serial.begin(9600); 335 | 336 | // this is actually the RFC4231 4.3 test 337 | 338 | Sha1.initHmac((uint8_t * ) "Jefe", 4); 339 | Sha1.print("what do ya want for nothing?"); 340 | uint8_t * result = Sha1.resultHmac(); 341 | 342 | Serial.println("Expect: b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7"); 343 | Serial.print( "Got : "); 344 | for (int i = 0; i < 10; i++) { 345 | Serial.print("0123456789abcdef"[result[i] >> 4]); 346 | Serial.print("0123456789abcdef"[result[i] & 0xf]); 347 | } 348 | Serial.print("\n"); 349 | } 350 | 351 | 352 | void loop(void) 353 | {} 354 | 355 | Extended 356 | ======== 357 | 358 | Disabling the ``C++`` Wrapper 359 | ----------------------------- 360 | 361 | The ``C++`` wrapper increases the overhead and eats up some 362 | RAM. So one can disable the wrapper by defining 363 | ``SHA1_DISABLE_WRAPPER`` in ``config.h``: 364 | 365 | .. code-block:: c++ 366 | 367 | #define SHA1_DISABLE_WRAPPER 368 | 369 | 370 | Instantiating a new Hasher 371 | -------------------------- 372 | 373 | A new hasher can be created by calling ``sha1_hasher_new``: 374 | 375 | .. code-block:: c++ 376 | 377 | 378 | #define SHA1_DISABLE_WRAPPER 379 | #include "sha1.h" 380 | 381 | 382 | sha1_hasher_t hasher; 383 | 384 | void setup(void) 385 | { 386 | hasher = sha1_hasher_new(); 387 | Serial.begin(9600); 388 | } 389 | 390 | 391 | Writing to the Hasher 392 | --------------------- 393 | 394 | Before one writes to the hasher he should invoke 395 | ``sha1_hasher_init``, although this function has been 396 | called by ``sha1_hasher_new``. Then he can write safely: 397 | 398 | .. code-block:: c++ 399 | 400 | void loop(void) 401 | { 402 | sha1_hasher_init(hasher); 403 | 404 | sha1_hasher_write(hasher, "abc", 3); 405 | } 406 | 407 | Obtaining the Result and free'ing the Hasher 408 | -------------------------------------------- 409 | 410 | .. code-block:: c++ 411 | 412 | void loop(void) 413 | { 414 | sha1_hasher_init(hasher); 415 | sha1_hasher_write(hasher, "abc", 3); 416 | 417 | uint8_t * result; 418 | result = sha1_hasher_gethash(hasher); 419 | 420 | Serial.print("EXPECT: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad\n"); 421 | Serial.print("GOT : "); 422 | for (int i = 0; i < 10; i++) { 423 | Serial.print("0123456789abcdef"[result[i] >> 4]); 424 | Serial.print("0123456789abcdef"[result[i] & 0xf]); 425 | } 426 | Serial.print("\n"); 427 | 428 | // do not actually delete the hasher 429 | // we are inside loop 430 | 431 | // sha1_hasher_del(hasher); 432 | 433 | } 434 | 435 | 436 | API Doc 437 | ------- 438 | 439 | ``sha1_hasher_new(void): sha1_hasher_t`` 440 | Allocate and initialize a new hasher. 441 | ``sha1_hasher_del(sha1_hasher_t hasher): void`` 442 | Free the hasher. 443 | ``sha1_hasher_init(sha1_hasher_t hasher)`` 444 | (Re-) Initialize the hasher for hashing. 445 | ``sha1_hasher_putc(sha1_hasher_t hasher, uint8_t byte): int`` 446 | Put ``byte`` to the hasher. Follows the standard 447 | ``putc`` conventions. 448 | ``sha1_hasher_gethash(sha1_hasher_t hasher): uint8_t *`` 449 | Returns **a reference** of the hash. One **must 450 | not** free the result. This modifies the state of 451 | the hasher. Once this function has been called, 452 | ``sha1_hasher_init`` must be invoked or 453 | ``sha1_hasher_putc`` will fail. 454 | ``sha1_hasher_write(sha1_hasher_t hasher, const void * buf, size_t count): ssize_t`` 455 | Writes to the hasher. Follows the standard ``write`` 456 | conventions and uses ``sha1_hasher_putc``. 457 | 458 | If ``SHA1_ENABLE_HMAC`` is defined in ``config.h`` 459 | also the following functions are available: 460 | 461 | ``sha1_hasher_init_hmac(sha1_hasher_t hasher, const uint8_t * key, size_t key_len): void`` 462 | Initialize the hasher for *HMAC*. Invokes 463 | ``sha1_hasher_init``. 464 | ``sha1_hasher_gethmac(sha1_hasher_t hasher): uint8_t *`` 465 | Returns **a reference** of the hash. One **must 466 | not** free the result. This modifies the state of 467 | the hasher. Once this function has been called, 468 | ``sha1_hasher_init`` must be invoked or 469 | ``sha1_hasher_putc`` will fail. 470 | 471 | 472 | 473 | 474 | 475 | .. [1] ``config.h`` includes ``shaX/default.h``. Some 476 | configuration is done here. When using the Arduino 477 | interface one should only edit ``config.h``. 478 | -------------------------------------------------------------------------------- /docs/static/alabaster.css: -------------------------------------------------------------------------------- 1 | @import url("basic.css"); 2 | 3 | /* -- page layout ----------------------------------------------------------- */ 4 | 5 | body { 6 | font-family: Georgia, serif; 7 | font-size: 17px; 8 | background-color: #fff; 9 | color: #000; 10 | margin: 0; 11 | padding: 0; 12 | } 13 | 14 | 15 | div.document { 16 | width: 940px; 17 | margin: 30px auto 0 auto; 18 | } 19 | 20 | div.documentwrapper { 21 | float: left; 22 | width: 100%; 23 | } 24 | 25 | div.bodywrapper { 26 | margin: 0 0 0 220px; 27 | } 28 | 29 | div.sphinxsidebar { 30 | width: 220px; 31 | font-size: 14px; 32 | line-height: 1.5; 33 | } 34 | 35 | hr { 36 | border: 1px solid #B1B4B6; 37 | } 38 | 39 | div.body { 40 | background-color: #fff; 41 | color: #3E4349; 42 | padding: 0 30px 0 30px; 43 | } 44 | 45 | div.body > .section { 46 | text-align: left; 47 | } 48 | 49 | div.footer { 50 | width: 940px; 51 | margin: 20px auto 30px auto; 52 | font-size: 14px; 53 | color: #888; 54 | text-align: right; 55 | } 56 | 57 | div.footer a { 58 | color: #888; 59 | } 60 | 61 | p.caption { 62 | font-family: inherit; 63 | font-size: inherit; 64 | } 65 | 66 | 67 | div.relations { 68 | display: none; 69 | } 70 | 71 | 72 | div.sphinxsidebar a { 73 | color: #444; 74 | text-decoration: none; 75 | border-bottom: 1px dotted #999; 76 | } 77 | 78 | div.sphinxsidebar a:hover { 79 | border-bottom: 1px solid #999; 80 | } 81 | 82 | div.sphinxsidebarwrapper { 83 | padding: 18px 10px; 84 | } 85 | 86 | div.sphinxsidebarwrapper p.logo { 87 | padding: 0; 88 | margin: -10px 0 0 0px; 89 | text-align: center; 90 | } 91 | 92 | div.sphinxsidebarwrapper h1.logo { 93 | margin-top: -10px; 94 | text-align: center; 95 | margin-bottom: 5px; 96 | text-align: left; 97 | } 98 | 99 | div.sphinxsidebarwrapper h1.logo-name { 100 | margin-top: 0px; 101 | } 102 | 103 | div.sphinxsidebarwrapper p.blurb { 104 | margin-top: 0; 105 | font-style: normal; 106 | } 107 | 108 | div.sphinxsidebar h3, 109 | div.sphinxsidebar h4 { 110 | font-family: Georgia, serif; 111 | color: #444; 112 | font-size: 24px; 113 | font-weight: normal; 114 | margin: 0 0 5px 0; 115 | padding: 0; 116 | } 117 | 118 | div.sphinxsidebar h4 { 119 | font-size: 20px; 120 | } 121 | 122 | div.sphinxsidebar h3 a { 123 | color: #444; 124 | } 125 | 126 | div.sphinxsidebar p.logo a, 127 | div.sphinxsidebar h3 a, 128 | div.sphinxsidebar p.logo a:hover, 129 | div.sphinxsidebar h3 a:hover { 130 | border: none; 131 | } 132 | 133 | div.sphinxsidebar p { 134 | color: #555; 135 | margin: 10px 0; 136 | } 137 | 138 | div.sphinxsidebar ul { 139 | margin: 10px 0; 140 | padding: 0; 141 | color: #000; 142 | } 143 | 144 | div.sphinxsidebar ul li.toctree-l1 > a { 145 | font-size: 120%; 146 | } 147 | 148 | div.sphinxsidebar ul li.toctree-l2 > a { 149 | font-size: 110%; 150 | } 151 | 152 | div.sphinxsidebar input { 153 | border: 1px solid #CCC; 154 | font-family: Georgia, serif; 155 | font-size: 1em; 156 | } 157 | 158 | div.sphinxsidebar hr { 159 | border: none; 160 | height: 1px; 161 | color: #AAA; 162 | background: #AAA; 163 | 164 | text-align: left; 165 | margin-left: 0; 166 | width: 50%; 167 | } 168 | 169 | div.sphinxsidebar .badge { 170 | border-bottom: none; 171 | } 172 | 173 | div.sphinxsidebar .badge:hover { 174 | border-bottom: none; 175 | } 176 | 177 | /* To address an issue with donation coming after search */ 178 | div.sphinxsidebar h3.donation { 179 | margin-top: 10px; 180 | } 181 | 182 | /* -- body styles ----------------------------------------------------------- */ 183 | 184 | a { 185 | color: #004B6B; 186 | text-decoration: underline; 187 | } 188 | 189 | a:hover { 190 | color: #6D4100; 191 | text-decoration: underline; 192 | } 193 | 194 | div.body h1, 195 | div.body h2, 196 | div.body h3, 197 | div.body h4, 198 | div.body h5, 199 | div.body h6 { 200 | font-family: Georgia, serif; 201 | font-weight: normal; 202 | margin: 30px 0px 10px 0px; 203 | padding: 0; 204 | } 205 | 206 | div.body h1 { margin-top: 0; padding-top: 0; font-size: 240%; } 207 | div.body h2 { font-size: 180%; } 208 | div.body h3 { font-size: 150%; } 209 | div.body h4 { font-size: 130%; } 210 | div.body h5 { font-size: 100%; } 211 | div.body h6 { font-size: 100%; } 212 | 213 | a.headerlink { 214 | color: #DDD; 215 | padding: 0 4px; 216 | text-decoration: none; 217 | } 218 | 219 | a.headerlink:hover { 220 | color: #444; 221 | background: #EAEAEA; 222 | } 223 | 224 | div.body p, div.body dd, div.body li { 225 | line-height: 1.4em; 226 | } 227 | 228 | div.admonition { 229 | margin: 20px 0px; 230 | padding: 10px 30px; 231 | background-color: #EEE; 232 | border: 1px solid #CCC; 233 | } 234 | 235 | div.admonition tt.xref, div.admonition code.xref, div.admonition a tt { 236 | background-color: #FBFBFB; 237 | border-bottom: 1px solid #fafafa; 238 | } 239 | 240 | div.admonition p.admonition-title { 241 | font-family: Georgia, serif; 242 | font-weight: normal; 243 | font-size: 24px; 244 | margin: 0 0 10px 0; 245 | padding: 0; 246 | line-height: 1; 247 | } 248 | 249 | div.admonition p.last { 250 | margin-bottom: 0; 251 | } 252 | 253 | div.highlight { 254 | background-color: #fff; 255 | } 256 | 257 | dt:target, .highlight { 258 | background: #FAF3E8; 259 | } 260 | 261 | div.warning { 262 | background-color: #FCC; 263 | border: 1px solid #FAA; 264 | } 265 | 266 | div.danger { 267 | background-color: #FCC; 268 | border: 1px solid #FAA; 269 | -moz-box-shadow: 2px 2px 4px #D52C2C; 270 | -webkit-box-shadow: 2px 2px 4px #D52C2C; 271 | box-shadow: 2px 2px 4px #D52C2C; 272 | } 273 | 274 | div.error { 275 | background-color: #FCC; 276 | border: 1px solid #FAA; 277 | -moz-box-shadow: 2px 2px 4px #D52C2C; 278 | -webkit-box-shadow: 2px 2px 4px #D52C2C; 279 | box-shadow: 2px 2px 4px #D52C2C; 280 | } 281 | 282 | div.caution { 283 | background-color: #FCC; 284 | border: 1px solid #FAA; 285 | } 286 | 287 | div.attention { 288 | background-color: #FCC; 289 | border: 1px solid #FAA; 290 | } 291 | 292 | div.important { 293 | background-color: #EEE; 294 | border: 1px solid #CCC; 295 | } 296 | 297 | div.note { 298 | background-color: #EEE; 299 | border: 1px solid #CCC; 300 | } 301 | 302 | div.tip { 303 | background-color: #EEE; 304 | border: 1px solid #CCC; 305 | } 306 | 307 | div.hint { 308 | background-color: #EEE; 309 | border: 1px solid #CCC; 310 | } 311 | 312 | div.seealso { 313 | background-color: #EEE; 314 | border: 1px solid #CCC; 315 | } 316 | 317 | div.topic { 318 | background-color: #EEE; 319 | } 320 | 321 | p.admonition-title { 322 | display: inline; 323 | } 324 | 325 | p.admonition-title:after { 326 | content: ":"; 327 | } 328 | 329 | pre, tt, code { 330 | font-family: 'Consolas', 'Menlo', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace; 331 | font-size: 0.9em; 332 | } 333 | 334 | .hll { 335 | background-color: #FFC; 336 | margin: 0 -12px; 337 | padding: 0 12px; 338 | display: block; 339 | } 340 | 341 | img.screenshot { 342 | } 343 | 344 | tt.descname, tt.descclassname, code.descname, code.descclassname { 345 | font-size: 0.95em; 346 | } 347 | 348 | tt.descname, code.descname { 349 | padding-right: 0.08em; 350 | } 351 | 352 | img.screenshot { 353 | -moz-box-shadow: 2px 2px 4px #EEE; 354 | -webkit-box-shadow: 2px 2px 4px #EEE; 355 | box-shadow: 2px 2px 4px #EEE; 356 | } 357 | 358 | table.docutils { 359 | border: 1px solid #888; 360 | -moz-box-shadow: 2px 2px 4px #EEE; 361 | -webkit-box-shadow: 2px 2px 4px #EEE; 362 | box-shadow: 2px 2px 4px #EEE; 363 | } 364 | 365 | table.docutils td, table.docutils th { 366 | border: 1px solid #888; 367 | padding: 0.25em 0.7em; 368 | } 369 | 370 | table.field-list, table.footnote { 371 | border: none; 372 | -moz-box-shadow: none; 373 | -webkit-box-shadow: none; 374 | box-shadow: none; 375 | } 376 | 377 | table.footnote { 378 | margin: 15px 0; 379 | width: 100%; 380 | border: 1px solid #EEE; 381 | background: #FDFDFD; 382 | font-size: 0.9em; 383 | } 384 | 385 | table.footnote + table.footnote { 386 | margin-top: -15px; 387 | border-top: none; 388 | } 389 | 390 | table.field-list th { 391 | padding: 0 0.8em 0 0; 392 | } 393 | 394 | table.field-list td { 395 | padding: 0; 396 | } 397 | 398 | table.field-list p { 399 | margin-bottom: 0.8em; 400 | } 401 | 402 | /* Cloned from 403 | * https://github.com/sphinx-doc/sphinx/commit/ef60dbfce09286b20b7385333d63a60321784e68 404 | */ 405 | .field-name { 406 | -moz-hyphens: manual; 407 | -ms-hyphens: manual; 408 | -webkit-hyphens: manual; 409 | hyphens: manual; 410 | } 411 | 412 | table.footnote td.label { 413 | width: .1px; 414 | padding: 0.3em 0 0.3em 0.5em; 415 | } 416 | 417 | table.footnote td { 418 | padding: 0.3em 0.5em; 419 | } 420 | 421 | dl { 422 | margin: 0; 423 | padding: 0; 424 | } 425 | 426 | dl dd { 427 | margin-left: 30px; 428 | } 429 | 430 | blockquote { 431 | margin: 0 0 0 30px; 432 | padding: 0; 433 | } 434 | 435 | ul, ol { 436 | /* Matches the 30px from the narrow-screen "li > ul" selector below */ 437 | margin: 10px 0 10px 30px; 438 | padding: 0; 439 | } 440 | 441 | pre { 442 | background: #EEE; 443 | padding: 7px 30px; 444 | margin: 15px 0px; 445 | line-height: 1.3em; 446 | } 447 | 448 | div.viewcode-block:target { 449 | background: #ffd; 450 | } 451 | 452 | dl pre, blockquote pre, li pre { 453 | margin-left: 0; 454 | padding-left: 30px; 455 | } 456 | 457 | tt, code { 458 | background-color: #ecf0f3; 459 | color: #222; 460 | /* padding: 1px 2px; */ 461 | } 462 | 463 | tt.xref, code.xref, a tt { 464 | background-color: #FBFBFB; 465 | border-bottom: 1px solid #fff; 466 | } 467 | 468 | a.reference { 469 | text-decoration: none; 470 | border-bottom: 1px dotted #004B6B; 471 | } 472 | 473 | /* Don't put an underline on images */ 474 | a.image-reference, a.image-reference:hover { 475 | border-bottom: none; 476 | } 477 | 478 | a.reference:hover { 479 | border-bottom: 1px solid #6D4100; 480 | } 481 | 482 | a.footnote-reference { 483 | text-decoration: none; 484 | font-size: 0.7em; 485 | vertical-align: top; 486 | border-bottom: 1px dotted #004B6B; 487 | } 488 | 489 | a.footnote-reference:hover { 490 | border-bottom: 1px solid #6D4100; 491 | } 492 | 493 | a:hover tt, a:hover code { 494 | background: #EEE; 495 | } 496 | 497 | 498 | @media screen and (max-width: 870px) { 499 | 500 | div.sphinxsidebar { 501 | display: none; 502 | } 503 | 504 | div.document { 505 | width: 100%; 506 | 507 | } 508 | 509 | div.documentwrapper { 510 | margin-left: 0; 511 | margin-top: 0; 512 | margin-right: 0; 513 | margin-bottom: 0; 514 | } 515 | 516 | div.bodywrapper { 517 | margin-top: 0; 518 | margin-right: 0; 519 | margin-bottom: 0; 520 | margin-left: 0; 521 | } 522 | 523 | ul { 524 | margin-left: 0; 525 | } 526 | 527 | li > ul { 528 | /* Matches the 30px from the "ul, ol" selector above */ 529 | margin-left: 30px; 530 | } 531 | 532 | .document { 533 | width: auto; 534 | } 535 | 536 | .footer { 537 | width: auto; 538 | } 539 | 540 | .bodywrapper { 541 | margin: 0; 542 | } 543 | 544 | .footer { 545 | width: auto; 546 | } 547 | 548 | .github { 549 | display: none; 550 | } 551 | 552 | 553 | 554 | } 555 | 556 | 557 | 558 | @media screen and (max-width: 875px) { 559 | 560 | body { 561 | margin: 0; 562 | padding: 20px 30px; 563 | } 564 | 565 | div.documentwrapper { 566 | float: none; 567 | background: #fff; 568 | } 569 | 570 | div.sphinxsidebar { 571 | display: block; 572 | float: none; 573 | width: 102.5%; 574 | margin: 50px -30px -20px -30px; 575 | padding: 10px 20px; 576 | background: #333; 577 | color: #FFF; 578 | } 579 | 580 | div.sphinxsidebar h3, div.sphinxsidebar h4, div.sphinxsidebar p, 581 | div.sphinxsidebar h3 a { 582 | color: #fff; 583 | } 584 | 585 | div.sphinxsidebar a { 586 | color: #AAA; 587 | } 588 | 589 | div.sphinxsidebar p.logo { 590 | display: none; 591 | } 592 | 593 | div.document { 594 | width: 100%; 595 | margin: 0; 596 | } 597 | 598 | div.footer { 599 | display: none; 600 | } 601 | 602 | div.bodywrapper { 603 | margin: 0; 604 | } 605 | 606 | div.body { 607 | min-height: 0; 608 | padding: 0; 609 | } 610 | 611 | .rtd_doc_footer { 612 | display: none; 613 | } 614 | 615 | .document { 616 | width: auto; 617 | } 618 | 619 | .footer { 620 | width: auto; 621 | } 622 | 623 | .footer { 624 | width: auto; 625 | } 626 | 627 | .github { 628 | display: none; 629 | } 630 | } 631 | 632 | 633 | /* misc. */ 634 | 635 | .revsys-inline { 636 | display: none!important; 637 | } 638 | 639 | /* Make nested-list/multi-paragraph items look better in Releases changelog 640 | * pages. Without this, docutils' magical list fuckery causes inconsistent 641 | * formatting between different release sub-lists. 642 | */ 643 | div#changelog > div.section > ul > li > p:only-child { 644 | margin-bottom: 0; 645 | } 646 | 647 | /* Hide fugly table cell borders in ..bibliography:: directive output */ 648 | table.docutils.citation, table.docutils.citation td, table.docutils.citation th { 649 | border: none; 650 | /* Below needed in some edge cases; if not applied, bottom shadows appear */ 651 | -moz-box-shadow: none; 652 | -webkit-box-shadow: none; 653 | box-shadow: none; 654 | } 655 | 656 | 657 | /* relbar */ 658 | 659 | .related { 660 | line-height: 30px; 661 | width: 100%; 662 | font-size: 0.9rem; 663 | } 664 | 665 | .related.top { 666 | border-bottom: 1px solid #EEE; 667 | margin-bottom: 20px; 668 | } 669 | 670 | .related.bottom { 671 | border-top: 1px solid #EEE; 672 | } 673 | 674 | .related ul { 675 | padding: 0; 676 | margin: 0; 677 | list-style: none; 678 | } 679 | 680 | .related li { 681 | display: inline; 682 | } 683 | 684 | nav#rellinks { 685 | float: right; 686 | } 687 | 688 | nav#rellinks li+li:before { 689 | content: "|"; 690 | } 691 | 692 | nav#breadcrumbs li+li:before { 693 | content: "\00BB"; 694 | } 695 | 696 | /* Hide certain items when printing */ 697 | @media print { 698 | div.related { 699 | display: none; 700 | } 701 | } --------------------------------------------------------------------------------