Skip to content

Commit 8ccc178

Browse files
Terra Quantum AGuser
authored andcommitted
Version 0.4.0
GitOrigin-RevId: 32f0321f8799530d331b905034a2006e66ae2130
1 parent c0ffee6 commit 8ccc178

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1684
-2025
lines changed

.github/workflows/push.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ jobs:
4343
architecture: x86_64
4444

4545
- os: Linux
46-
image: ubuntu-latest
46+
image: ubuntu-22.04
4747
configuration: Release
4848
sanitize: ON
4949
coverage: OFF
5050
haswell: OFF
5151
compiler: GCC
52+
gcc: 11
5253
architecture: x86_64
5354

5455
- os: Linux

.github/workflows/style.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ jobs:
2222
python3 -c 'if True:
2323
import difflib
2424
import os
25+
import re
2526
import subprocess
2627
import sys
2728
2829
import gitignorefile
2930
3031
gi = gitignorefile.Cache()
32+
r_pattern = re.compile("[^\\u0000-\\u00FF]", re.U)
3133
errors = 0
3234
for root, directories, names in os.walk(os.getcwd()):
3335
directories[:] = [d for d in directories if d != ".git" and not gi(os.path.join(root, d))]
@@ -54,5 +56,15 @@ jobs:
5456
print(f"::error file={rp},line={i1+1},endLine={i2}::{rp}:{i1+1} Please remove line(s) {i1+1}-{i2}")
5557
errors += 1
5658
59+
if os.path.splitext(name)[1] not in (".ico", ".png", ".ent", ".shake") and not gi(path):
60+
with open(path) as f:
61+
for row_n, row in enumerate(f, start = 1):
62+
found = r_pattern.findall(row)
63+
if found:
64+
rp = os.path.relpath(path)
65+
print(f"Error: Found symbols {found} in {rp}:")
66+
print(f"Line {row_n}: {row}")
67+
errors += 1
68+
5769
sys.exit(int(bool(errors)))
5870
'

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,13 @@ endif()
8282
if(BENCHMARK)
8383
add_subdirectory(benchmark)
8484
endif()
85+
86+
include(CheckIncludeFile)
87+
file(GLOB proj_headers "include/pqc/*.h")
88+
foreach(project_header ${proj_headers})
89+
get_filename_component(header_name ${project_header} NAME_WE)
90+
check_include_file("${project_header}" ${header_name}_IS_STANDALONE)
91+
if (NOT ${header_name}_IS_STANDALONE)
92+
message(FATAL_ERROR "Header is not self-sufficient: ${project_header}")
93+
endif()
94+
endforeach()

docs/api_reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@ Below you may find the reference to the all API methods or examples that exist i
118118
## Common functions
119119
- [`PQC_cipher_get_length`](common_functions.html#pqc_cipher_get_length)
120120
- [`PQC_context_get_length`](common_functions.html#pqc_context_get_length)
121-
- [Constants](common_functions.html#сonstants)
121+
- [Constants](common_functions.html#constants)

docs/common_functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ size_t PQC_API PQC_context_get_length(CIPHER_HANDLE context, uint32_t type);
6060
* `0`: Indicates an error, such as an invalid context or type.
6161

6262

63-
## Сonstants
63+
## Constants
6464

6565
### Cipher:
6666

docs/keys/PRNG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Algorithm
4242

4343
* **Hash Truncation and Reuse**: The resulting hash is then truncated, taking a portion of the hash and overwriting the original elements of `dt` with this truncated hash data. This step is essential to mix the entropy and reduce predictability.
4444

45-
* **Initial AES Encryption**: The array `dt` is then encrypted using the AES block cipher in OFB mode. This mode of operation turns a block cipher into a stream cipher, producing a keystream that is then XORed with the plaintextin this case, the data in `dt`.
45+
* **Initial AES Encryption**: The array `dt` is then encrypted using the AES block cipher in OFB mode. This mode of operation turns a block cipher into a stream cipher, producing a keystream that is then XORed with the plaintext - in this case, the data in `dt`.
4646

4747
* **XOR with Internal State**: After the encryption, the `dt` array is XORed with an internal state array `v`. The result of this XOR is stored in a new array `r`.
4848

docs/keys/pbkdf2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ size_t PQC_API PQC_pbkdf_2(
6666
* `key_length`: The length of the key buffer.
6767
* `master_key`: Buffer for storing the derived key.
6868
* `master_key_length`: Define the length of the master key to be derived.
69-
* `salt`: Salt value used in file encryption. Its recommended to use a constant specific to the application for enhanced security.
69+
* `salt`: Salt value used in file encryption. It's recommended to use a constant specific to the application for enhanced security.
7070
* `salt_length`: The length of the salt.
7171
* `iterations`: Number of iterations, positive integer value.
7272

docs/post_quantum_algs/digital_signature/falcon.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ nav_order: 3
2828

2929
Copyright (c) 2017-2019 Falcon Project
3030

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

3333
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
3434

35-
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3636

3737

3838
## Falcon - Parameter set summary

docs/post_quantum_algs/kem/kem.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ The Key Encapsulation Mechanisms (KEMs) for post-quantum algorithms serve as cry
1111

1212
The operational framework of a KEM in post-quantum cryptography involves three main algorithms:
1313

14-
1. **Key Generation (Generate):** This algorithm is responsible for generating a pair of keysan openly shared public key and a privately kept secret key.
14+
1. **Key Generation (Generate):** This algorithm is responsible for generating a pair of keys - an openly shared public key and a privately kept secret key.
1515

1616
2. **Encapsulation (Encapsulate):** In this step, a sender utilizes the recipient's public key to encapsulate a shared secret, resulting in a pair consisting of a ciphertext (or "encapsulation") and a shared secret value, enabling the derivation of encryption keys.
1717

1818
3. **Decapsulation (Decapsulate):** Upon receiving the encapsulated key, the recipient uses their private key to decapsulate the shared secret from the ciphertext, thereby enabling secure communication.
1919

2020

21-
Post-quantum KEMs leverage complex mathematical problems believed to be intractable for quantum computers, such as those based on lattice structures, code-based principles, or other quantum-resistant foundations. These KEMs play a critical role in achieving secure key exchange in the next generation of cryptographic protocols, ensuring secure communications even in the presence of sophisticated quantum computing capabilities. The development and standardization of such mechanisms, as carried out by organizations like NIST, are essential steps towards maintaining global digital security standards in the post-quantum future.
21+
Post-quantum KEMs leverage complex mathematical problems believed to be intractable for quantum computers, such as those based on lattice structures, code-based principles, or other quantum-resistant foundations. These KEMs play a critical role in achieving secure key exchange in the next generation of cryptographic protocols, ensuring secure communications even in the presence of sophisticated quantum computing capabilities. The development and standardization of such mechanisms, as carried out by organizations like NIST, are essential steps towards maintaining global digital security standards in the post-quantum future.

docs/post_quantum_algs/kem/mceliece.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The McEliece algorithm implementation has successfully passed the Known Answer T
3434

3535
## Leveraging McEliece and True Entropy
3636
The customization of the McEliece algorithm within TQ42 Cryptography is designed to work in synergy with true entropy, sourced from the Single Photon Quantum Random Number Generator (QRNG). This technology ensures that the randomness required for cryptographic keys is of the highest quality, providing unparalleled security for company data.
37-
Since the effectiveness of any cryptographic algorithm heavily relies on the randomness of its keys, incorporating QRNG-derived true entropy with TQ42s customized McEliece algorithm ensures that your companys sensitive information is safeguarded in the most robust manner possible.
37+
Since the effectiveness of any cryptographic algorithm heavily relies on the randomness of its keys, incorporating QRNG-derived true entropy with TQ42's customized McEliece algorithm ensures that your company's sensitive information is safeguarded in the most robust manner possible.
3838

3939
## Classic McEliece 8192128f - Parameter set summary
4040

@@ -74,7 +74,7 @@ The latest state of the NIST standardization process for the McEliece Key Encaps
7474
- **Unique Position**: Unlike some other algorithms being considered for standardization, Classic McEliece does not directly compete with many as a general-purpose KEM. Its primary competition, in terms of lattice-based approaches like ML-KEM, differs in key aspects, such as key sizes and computational efficiency. Nevertheless, NIST is evaluating Classic McEliece along with others for its potential unique benefits, such as its long-standing security assumptions resilience to certain types of attacks (<https://blog.cloudflare.com/pq-2024>).
7575

7676
- **Performance Considerations**: Although Classic McEliece provides certain advantages,
77-
including a high level of security, its performance aspectsparticularly in terms of key sizesdo not directly compete
77+
including a high level of security, its performance aspects-particularly in terms of key sizes - do not directly compete
7878
with some of the more computationally efficient algorithms like ML-KEM. This factor is crucial as NIST also considers the
7979
practicality of implementing these algorithms in real-world systems.
8080

docs/post_quantum_algs/kem/ml-kem.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ FIPS 203, which standardizes Module-Lattice-based Key-Encapsulation Mechanisms (
6666
The TQ42 Cryptography ML-KEM algorithm implementation has successfully passed the Known Answer Tests (KAT) provided by NIST. This confirms that the algorithm performs reliably as anticipated. For those interested in a deeper dive into the specifics of these tests, they are available [for review](https://github.com/terra-quantum-public/tq42-pqc-oss/tree/main/test/mlkem).
6767

6868
## Leveraging ML-KEM and True Entropy
69-
The customization of the ML-KEM algorithm within TQ42 Cryptography is designed to work in synergy with true entropy, sourced from the Single Photon Quantum Random Number Generator (QRNG). This technology ensures that the randomness required for cryptographic keys is of the highest quality, providing unparalleled security for company data. Since the effectiveness of any cryptographic algorithm heavily relies on the randomness of its keys, incorporating QRNG-derived true entropy with TQ42s customized ML-KEM algorithm ensures that your companys sensitive information is safeguarded in the most robust manner possible.
69+
The customization of the ML-KEM algorithm within TQ42 Cryptography is designed to work in synergy with true entropy, sourced from the Single Photon Quantum Random Number Generator (QRNG). This technology ensures that the randomness required for cryptographic keys is of the highest quality, providing unparalleled security for company data. Since the effectiveness of any cryptographic algorithm heavily relies on the randomness of its keys, incorporating QRNG-derived true entropy with TQ42's customized ML-KEM algorithm ensures that your company's sensitive information is safeguarded in the most robust manner possible.
7070

7171
## ML-KEM - Parameter set summary
7272

docs/use_cases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ The diagram shows one of the options for building a blockchain based on TQ42 Cry
8484

8585
![image](img/use_cases_PFS.png)
8686

87-
In the example **Perfect Forward Secrecy (PFS)** example, TQ42 Cryptography is used in such a way that each node contributes its share of entropy to the overall symmetric session key. None of the nodes forward the final encryption key in its entirety, and no one from outside can learn the session key by breaking the long-term keys incompletely (n-1 broken keys will not yield the session key).
87+
In the **Perfect Forward Secrecy (PFS)** example, TQ42 Cryptography is used in such a way that each node contributes its share of entropy to the overall symmetric session key. None of the nodes forward the final encryption key in its entirety, and no one from outside can learn the session key by breaking the long-term keys incompletely (n-1 broken keys will not yield the session key).
8888

8989
In the above example, we can integrate TQ42 Cryptography into the overall PFS scheme. To start information sharing, the user obtains keys (TQ42 Cryptography), which are then put into a shared repository where each user must retrieve them. Once the keys are obtained and the shared key is computed, the information sharing between users will be considered secure.

examples/aes/aes_cbc_example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// parties can obtain a common key through asymmetric key exchange
99

1010
// CBC takes a fixed-length iv, fixed-length key and
11-
// fixed-length plaintext. Plaintext size MUST be mutile of AES_BLOCKLEN;
11+
// fixed-length plaintext. Plaintext size MUST be multiple of AES_BLOCKLEN;
1212

1313
// Party A encrypts its plaintext using a key and iv. Then data, its length, key and iv must be
1414
// transmitted to party B

examples/aes/aes_ctr_example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// parties can obtain a common key through asymmetric key exchange
77

88
// CTR encryption doesn't need an iv. It takes a fixed-length key and
9-
// fixed-length plaintext. Plaintext size MUST be mutile of AES_BLOCKLEN;
9+
// fixed-length plaintext. Plaintext size MUST be multiple of AES_BLOCKLEN;
1010
// Decryption works in the same way
1111

1212
// Party A encrypts its plaintext using a key. Then data, its length, and key must be

examples/aes/aes_ofb_example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// OFB
1010

1111
// OFB takes a fixed length iv, fixed-length key and
12-
// fixed-length plaintext. Plaintext size MUST be mutile of AES_BLOCKLEN;
12+
// fixed-length plaintext. Plaintext size MUST be multiple of AES_BLOCKLEN;
1313
// Decryption works in the same way
1414

1515
// Party A encrypts its plaintext using a key and iv. Then data, its length, key and iv must be

examples/asymmetric_container/asymmetric_container_example_2_byte_string_falcon.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <cstring>
22
#include <iostream>
3+
#include <memory>
34

45
#include <pqc/aes.h>
56
#include <pqc/container.h>
@@ -34,15 +35,15 @@ int main()
3435
/*
3536
We can transform container to the encrypted byte string. Let's do it
3637
*/
37-
uint8_t * container_data = new uint8_t[PQC_asymmetric_container_size(new_container)];
38+
std::shared_ptr<uint8_t[]> container_data(new uint8_t[PQC_asymmetric_container_size(new_container)]);
3839

3940
// aes will use for string encryption
4041
uint8_t creation_key[PQC_AES_KEYLEN] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6,
4142
7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2};
4243
uint8_t creation_iv[PQC_AES_IVLEN] = {9, 8, 7, 6, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6};
4344

4445
size_t result = PQC_asymmetric_container_get_data(
45-
new_container, container_data, PQC_asymmetric_container_size(new_container), creation_key, PQC_AES_KEYLEN,
46+
new_container, container_data.get(), PQC_asymmetric_container_size(new_container), creation_key, PQC_AES_KEYLEN,
4647
creation_iv, PQC_AES_IVLEN
4748
);
4849
if (result != PQC_OK)
@@ -55,8 +56,8 @@ int main()
5556
*/
5657

5758
PQC_CONTAINER_HANDLE resultContainer = PQC_asymmetric_container_from_data(
58-
PQC_CIPHER_FALCON, container_data, PQC_asymmetric_container_size(new_container), creation_key, PQC_AES_KEYLEN,
59-
creation_iv, PQC_AES_IVLEN
59+
PQC_CIPHER_FALCON, container_data.get(), PQC_asymmetric_container_size(new_container), creation_key,
60+
PQC_AES_KEYLEN, creation_iv, PQC_AES_IVLEN
6061
);
6162
if (resultContainer == PQC_FAILED_TO_CREATE_CONTAINER)
6263
{
@@ -80,8 +81,6 @@ int main()
8081
std::cout << "\nERROR!!! Keys are not equal!!!\n";
8182
}
8283

83-
delete[] container_data;
84-
8584
PQC_asymmetric_container_close(new_container);
8685
PQC_asymmetric_container_close(resultContainer);
8786

examples/asymmetric_container/asymmetric_container_example_2_byte_string_mceliece.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ int main()
3939
/*
4040
We can transform container to the encrypted byte string. Let's do it
4141
*/
42-
uint8_t * container_data = new uint8_t[PQC_asymmetric_container_size(new_container)];
42+
std::shared_ptr<uint8_t[]> container_data(new uint8_t[PQC_asymmetric_container_size(new_container)]);
4343

4444
// aes will use for string encryption
4545
uint8_t creation_key[PQC_AES_KEYLEN] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6,
4646
7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2};
4747
uint8_t creation_iv[PQC_AES_IVLEN] = {9, 8, 7, 6, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6};
4848

4949
size_t result = PQC_asymmetric_container_get_data(
50-
new_container, container_data, PQC_asymmetric_container_size(new_container), creation_key, PQC_AES_KEYLEN,
50+
new_container, container_data.get(), PQC_asymmetric_container_size(new_container), creation_key, PQC_AES_KEYLEN,
5151
creation_iv, PQC_AES_IVLEN
5252
);
5353
if (result != PQC_OK)
@@ -60,8 +60,8 @@ int main()
6060
Let's restore container from string. The keys inside should be equal with others we generated before
6161
*/
6262
PQC_CONTAINER_HANDLE resultContainer = PQC_asymmetric_container_from_data(
63-
PQC_CIPHER_MCELIECE, container_data, PQC_asymmetric_container_size(new_container), creation_key, PQC_AES_KEYLEN,
64-
creation_iv, PQC_AES_IVLEN
63+
PQC_CIPHER_MCELIECE, container_data.get(), PQC_asymmetric_container_size(new_container), creation_key,
64+
PQC_AES_KEYLEN, creation_iv, PQC_AES_IVLEN
6565
);
6666
if (resultContainer == PQC_FAILED_TO_CREATE_CONTAINER)
6767
{
@@ -88,8 +88,6 @@ int main()
8888
return 1;
8989
}
9090

91-
delete[] container_data;
92-
9391
PQC_asymmetric_container_close(new_container);
9492
PQC_asymmetric_container_close(resultContainer);
9593

examples/sha3/const_size_sha3_example.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Look shake_sha3_example.cpp to use arbitary size of hash.
44
#include <cstring>
55
#include <iostream>
6+
#include <memory>
67

78
#include <pqc/sha3.h>
89

@@ -50,10 +51,10 @@ int main(void)
5051
std::cout << "\nERROR!!! Returned value must be equal to hash size of this mode!" << std::endl;
5152

5253
// create memory space for hash result
53-
uint8_t * hash = new uint8_t[hash_size];
54+
std::shared_ptr<uint8_t[]> hash(new uint8_t[hash_size]);
5455

5556
size_t pqc_hash_retrieve_return = PQC_hash_retrieve(
56-
sha3, hash, hash_size
57+
sha3, hash.get(), hash_size
5758
); // PQC_hash_retrieve gets hash from message. pqc_hash_retrieve_return should be equal to PQC_OK
5859
if (pqc_hash_retrieve_return != PQC_OK)
5960
std::cout << "\nERROR!!! Returned value must be PQC_OK if operation was done successfully";
@@ -65,7 +66,7 @@ int main(void)
6566

6667

6768
// Verification. Hash should be similar with constant digest message for this initial message
68-
if (memcmp(hash, expected, sha_len / 8) == 0)
69+
if (memcmp(hash.get(), expected, sha_len / 8) == 0)
6970
{
7071
std::cout << "Verification successfull" << std::endl;
7172
}
@@ -74,8 +75,5 @@ int main(void)
7475
std::cout << "Verification failed" << std::endl;
7576
}
7677

77-
// Free memory
78-
delete[] hash;
79-
8078
return 0;
8179
}

0 commit comments

Comments
 (0)