MNghia commited on
Commit
77f713a
·
verified ·
1 Parent(s): 24b7829

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. include/Openacc/cupti_openacc.h +98 -0
  2. include/Openmp/cupti_openmp.h +100 -0
  3. include/Openmp/omp-tools.h +1083 -0
  4. include/nettle/aes.h +185 -0
  5. include/nettle/arcfour.h +79 -0
  6. include/nettle/arctwo.h +103 -0
  7. include/nettle/asn1.h +152 -0
  8. include/nettle/base16.h +110 -0
  9. include/nettle/base64.h +172 -0
  10. include/nettle/bignum.h +129 -0
  11. include/nettle/blowfish.h +106 -0
  12. include/nettle/buffer.h +106 -0
  13. include/nettle/camellia.h +143 -0
  14. include/nettle/cast128.h +86 -0
  15. include/nettle/cbc.h +86 -0
  16. include/nettle/ccm.h +302 -0
  17. include/nettle/cfb.h +122 -0
  18. include/nettle/chacha-poly1305.h +98 -0
  19. include/nettle/chacha.h +107 -0
  20. include/nettle/cmac.h +237 -0
  21. include/nettle/ctr.h +71 -0
  22. include/nettle/curve25519.h +60 -0
  23. include/nettle/curve448.h +58 -0
  24. include/nettle/des.h +120 -0
  25. include/nettle/dsa-compat.h +183 -0
  26. include/nettle/dsa.h +210 -0
  27. include/nettle/eax.h +185 -0
  28. include/nettle/ecc-curve.h +58 -0
  29. include/nettle/ecc.h +159 -0
  30. include/nettle/ecdsa.h +103 -0
  31. include/nettle/eddsa.h +90 -0
  32. include/nettle/gcm.h +330 -0
  33. include/nettle/gostdsa.h +107 -0
  34. include/nettle/gosthash94.h +112 -0
  35. include/nettle/hkdf.h +67 -0
  36. include/nettle/hmac.h +280 -0
  37. include/nettle/knuth-lfib.h +80 -0
  38. include/nettle/macros.h +245 -0
  39. include/nettle/memxor.h +25 -0
  40. include/nettle/nettle-meta.h +298 -0
  41. include/nettle/nettle-types.h +131 -0
  42. include/nettle/pbkdf2.h +106 -0
  43. include/nettle/pgp.h +248 -0
  44. include/nettle/pkcs1.h +106 -0
  45. include/nettle/poly1305.h +114 -0
  46. include/nettle/pss-mgf1.h +58 -0
  47. include/nettle/pss.h +65 -0
  48. include/nettle/realloc.h +48 -0
  49. include/nettle/ripemd160.h +83 -0
  50. include/nettle/rsa.h +538 -0
include/Openacc/cupti_openacc.h ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2017 NVIDIA Corporation. All rights reserved.
3
+ *
4
+ * NOTICE TO LICENSEE:
5
+ *
6
+ * This source code and/or documentation ("Licensed Deliverables") are
7
+ * subject to NVIDIA intellectual property rights under U.S. and
8
+ * international Copyright laws.
9
+ *
10
+ * These Licensed Deliverables contained herein is PROPRIETARY and
11
+ * CONFIDENTIAL to NVIDIA and is being provided under the terms and
12
+ * conditions of a form of NVIDIA software license agreement by and
13
+ * between NVIDIA and Licensee ("License Agreement") or electronically
14
+ * accepted by Licensee. Notwithstanding any terms or conditions to
15
+ * the contrary in the License Agreement, reproduction or disclosure
16
+ * of the Licensed Deliverables to any third party without the express
17
+ * written consent of NVIDIA is prohibited.
18
+ *
19
+ * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
20
+ * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE
21
+ * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS
22
+ * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.
23
+ * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED
24
+ * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY,
25
+ * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
26
+ * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
27
+ * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY
28
+ * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
29
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
30
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
31
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
32
+ * OF THESE LICENSED DELIVERABLES.
33
+ *
34
+ * U.S. Government End Users. These Licensed Deliverables are a
35
+ * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT
36
+ * 1995), consisting of "commercial computer software" and "commercial
37
+ * computer software documentation" as such terms are used in 48
38
+ * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government
39
+ * only as a commercial end item. Consistent with 48 C.F.R.12.212 and
40
+ * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all
41
+ * U.S. Government End Users acquire the Licensed Deliverables with
42
+ * only those rights set forth herein.
43
+ *
44
+ * Any use of the Licensed Deliverables in individual and commercial
45
+ * software must include, in the user documentation and internal
46
+ * comments to the code, the above Disclaimer and U.S. Government End
47
+ * Users Notice.
48
+ */
49
+
50
+ #include <cuda_stdint.h>
51
+
52
+ #if !defined(_CUPTI_OPENACC_H_)
53
+ #define _CUPTI_OPENACC_H_
54
+
55
+ #ifndef CUPTIAPI
56
+ #ifdef _WIN32
57
+ #define CUPTIAPI __stdcall
58
+ #else
59
+ #define CUPTIAPI
60
+ #endif
61
+ #endif
62
+
63
+ #if defined(__LP64__)
64
+ #define CUPTILP64 1
65
+ #elif defined(_WIN64)
66
+ #define CUPTILP64 1
67
+ #else
68
+ #undef CUPTILP64
69
+ #endif
70
+
71
+ #if defined(__cplusplus)
72
+ extern "C" {
73
+ #endif
74
+
75
+ #if defined(__GNUC__) && defined(CUPTI_LIB)
76
+ #pragma GCC visibility push(default)
77
+ #endif
78
+
79
+ /**
80
+ * \brief Initialize OpenACC support
81
+ *
82
+ * \param profRegister function of type acc_prof_reg as obtained from acc_register_library
83
+ * \param profUnregister function of type acc_prof_reg as obtained from acc_register_library
84
+ * \param profLookup function of type acc_prof_lookup as obtained from acc_register_library
85
+ */
86
+ CUptiResult CUPTIAPI
87
+ cuptiOpenACCInitialize(void *profRegister, void *profUnregister, void *profLookup);
88
+
89
+ #if defined(__GNUC__) && defined(CUPTI_LIB)
90
+ #pragma GCC visibility pop
91
+ #endif
92
+
93
+ #if defined(__cplusplus)
94
+ }
95
+ #endif
96
+
97
+ #endif /*_CUPTI_OPENACC_H_*/
98
+
include/Openmp/cupti_openmp.h ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2018 NVIDIA Corporation. All rights reserved.
3
+ *
4
+ * NOTICE TO LICENSEE:
5
+ *
6
+ * This source code and/or documentation ("Licensed Deliverables") are
7
+ * subject to NVIDIA intellectual property rights under U.S. and
8
+ * international Copyright laws.
9
+ *
10
+ * These Licensed Deliverables contained herein is PROPRIETARY and
11
+ * CONFIDENTIAL to NVIDIA and is being provided under the terms and
12
+ * conditions of a form of NVIDIA software license agreement by and
13
+ * between NVIDIA and Licensee ("License Agreement") or electronically
14
+ * accepted by Licensee. Notwithstanding any terms or conditions to
15
+ * the contrary in the License Agreement, reproduction or disclosure
16
+ * of the Licensed Deliverables to any third party without the express
17
+ * written consent of NVIDIA is prohibited.
18
+ *
19
+ * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
20
+ * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE
21
+ * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS
22
+ * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.
23
+ * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED
24
+ * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY,
25
+ * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
26
+ * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
27
+ * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY
28
+ * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
29
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
30
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
31
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
32
+ * OF THESE LICENSED DELIVERABLES.
33
+ *
34
+ * U.S. Government End Users. These Licensed Deliverables are a
35
+ * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT
36
+ * 1995), consisting of "commercial computer software" and "commercial
37
+ * computer software documentation" as such terms are used in 48
38
+ * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government
39
+ * only as a commercial end item. Consistent with 48 C.F.R.12.212 and
40
+ * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all
41
+ * U.S. Government End Users acquire the Licensed Deliverables with
42
+ * only those rights set forth herein.
43
+ *
44
+ * Any use of the Licensed Deliverables in individual and commercial
45
+ * software must include, in the user documentation and internal
46
+ * comments to the code, the above Disclaimer and U.S. Government End
47
+ * Users Notice.
48
+ */
49
+
50
+ #include <cuda_stdint.h>
51
+ #include "Openmp/omp-tools.h"
52
+
53
+ #if !defined(_CUPTI_OPENMP_H_)
54
+ #define _CUPTI_OPENMP_H_
55
+
56
+ #ifndef CUPTIAPI
57
+ #ifdef _WIN32
58
+ #define CUPTIAPI __stdcall
59
+ #else
60
+ #define CUPTIAPI
61
+ #endif
62
+ #endif
63
+
64
+ #if defined(__LP64__)
65
+ #define CUPTILP64 1
66
+ #elif defined(_WIN64)
67
+ #define CUPTILP64 1
68
+ #else
69
+ #undef CUPTILP64
70
+ #endif
71
+
72
+ #if defined(__cplusplus)
73
+ extern "C" {
74
+ #endif
75
+
76
+ #if defined(__GNUC__) && defined(CUPTI_LIB)
77
+ #pragma GCC visibility push(default)
78
+ #endif
79
+
80
+ /**
81
+ * \brief Initialize OPENMP support (deprecated, used before OpenMP 5.0)
82
+ *
83
+ */
84
+ int CUPTIAPI cuptiOpenMpInitialize(ompt_function_lookup_t ompt_fn_lookup, const char *runtime_version, unsigned int ompt_version);
85
+
86
+ /**
87
+ * \brief Initialize OPENMP support
88
+ *
89
+ */
90
+ int CUPTIAPI cuptiOpenMpInitialize_v2(ompt_function_lookup_t lookup, int initial_device_num, ompt_data_t *tool_data);
91
+
92
+ #if defined(__GNUC__) && defined(CUPTI_LIB)
93
+ #pragma GCC visibility pop
94
+ #endif
95
+
96
+ #if defined(__cplusplus)
97
+ }
98
+ #endif
99
+
100
+ #endif /*_CUPTI_OPENMP_H_*/
include/Openmp/omp-tools.h ADDED
@@ -0,0 +1,1083 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * include/50/omp-tools.h.var
3
+ */
4
+
5
+ //===----------------------------------------------------------------------===//
6
+ //
7
+ // The LLVM Compiler Infrastructure
8
+ //
9
+ // This file is dual licensed under the MIT and the University of Illinois Open
10
+ // Source Licenses. See LICENSE.txt for details.
11
+ //
12
+ //===----------------------------------------------------------------------===//
13
+
14
+ #ifndef __OMPT__
15
+ #define __OMPT__
16
+
17
+ /*****************************************************************************
18
+ * system include files
19
+ *****************************************************************************/
20
+
21
+ #include <stdint.h>
22
+ #include <stddef.h>
23
+
24
+ /*****************************************************************************
25
+ * iteration macros
26
+ *****************************************************************************/
27
+
28
+ #define FOREACH_OMPT_INQUIRY_FN(macro) \
29
+ macro (ompt_enumerate_states) \
30
+ macro (ompt_enumerate_mutex_impls) \
31
+ \
32
+ macro (ompt_set_callback) \
33
+ macro (ompt_get_callback) \
34
+ \
35
+ macro (ompt_get_state) \
36
+ \
37
+ macro (ompt_get_parallel_info) \
38
+ macro (ompt_get_task_info) \
39
+ macro (ompt_get_task_memory) \
40
+ macro (ompt_get_thread_data) \
41
+ macro (ompt_get_unique_id) \
42
+ macro (ompt_finalize_tool) \
43
+ \
44
+ macro(ompt_get_num_procs) \
45
+ macro(ompt_get_num_places) \
46
+ macro(ompt_get_place_proc_ids) \
47
+ macro(ompt_get_place_num) \
48
+ macro(ompt_get_partition_place_nums) \
49
+ macro(ompt_get_proc_id) \
50
+ \
51
+ macro(ompt_get_target_info) \
52
+ macro(ompt_get_num_devices)
53
+
54
+ #define FOREACH_OMPT_STATE(macro) \
55
+ \
56
+ /* first available state */ \
57
+ macro (ompt_state_undefined, 0x102) /* undefined thread state */ \
58
+ \
59
+ /* work states (0..15) */ \
60
+ macro (ompt_state_work_serial, 0x000) /* working outside parallel */ \
61
+ macro (ompt_state_work_parallel, 0x001) /* working within parallel */ \
62
+ macro (ompt_state_work_reduction, 0x002) /* performing a reduction */ \
63
+ \
64
+ /* barrier wait states (16..31) */ \
65
+ macro (ompt_state_wait_barrier, 0x010) /* waiting at a barrier */ \
66
+ macro (ompt_state_wait_barrier_implicit_parallel, 0x011) \
67
+ /* implicit barrier at the end of parallel region */\
68
+ macro (ompt_state_wait_barrier_implicit_workshare, 0x012) \
69
+ /* implicit barrier at the end of worksharing */ \
70
+ macro (ompt_state_wait_barrier_implicit, 0x013) /* implicit barrier */ \
71
+ macro (ompt_state_wait_barrier_explicit, 0x014) /* explicit barrier */ \
72
+ \
73
+ /* task wait states (32..63) */ \
74
+ macro (ompt_state_wait_taskwait, 0x020) /* waiting at a taskwait */ \
75
+ macro (ompt_state_wait_taskgroup, 0x021) /* waiting at a taskgroup */ \
76
+ \
77
+ /* mutex wait states (64..127) */ \
78
+ macro (ompt_state_wait_mutex, 0x040) \
79
+ macro (ompt_state_wait_lock, 0x041) /* waiting for lock */ \
80
+ macro (ompt_state_wait_critical, 0x042) /* waiting for critical */ \
81
+ macro (ompt_state_wait_atomic, 0x043) /* waiting for atomic */ \
82
+ macro (ompt_state_wait_ordered, 0x044) /* waiting for ordered */ \
83
+ \
84
+ /* target wait states (128..255) */ \
85
+ macro (ompt_state_wait_target, 0x080) /* waiting for target region */ \
86
+ macro (ompt_state_wait_target_map, 0x081) /* waiting for target data mapping operation */ \
87
+ macro (ompt_state_wait_target_update, 0x082) /* waiting for target update operation */ \
88
+ \
89
+ /* misc (256..511) */ \
90
+ macro (ompt_state_idle, 0x100) /* waiting for work */ \
91
+ macro (ompt_state_overhead, 0x101) /* overhead excluding wait states */ \
92
+ \
93
+ /* implementation-specific states (512..) */
94
+
95
+
96
+ #define FOREACH_KMP_MUTEX_IMPL(macro) \
97
+ macro (kmp_mutex_impl_none, 0) /* unknown implementation */ \
98
+ macro (kmp_mutex_impl_spin, 1) /* based on spin */ \
99
+ macro (kmp_mutex_impl_queuing, 2) /* based on some fair policy */ \
100
+ macro (kmp_mutex_impl_speculative, 3) /* based on HW-supported speculation */
101
+
102
+ #define FOREACH_OMPT_EVENT(macro) \
103
+ \
104
+ /*--- Mandatory Events ---*/ \
105
+ macro (ompt_callback_thread_begin, ompt_callback_thread_begin_t, 1) /* thread begin */ \
106
+ macro (ompt_callback_thread_end, ompt_callback_thread_end_t, 2) /* thread end */ \
107
+ \
108
+ macro (ompt_callback_parallel_begin, ompt_callback_parallel_begin_t, 3) /* parallel begin */ \
109
+ macro (ompt_callback_parallel_end, ompt_callback_parallel_end_t, 4) /* parallel end */ \
110
+ \
111
+ macro (ompt_callback_task_create, ompt_callback_task_create_t, 5) /* task begin */ \
112
+ macro (ompt_callback_task_schedule, ompt_callback_task_schedule_t, 6) /* task schedule */ \
113
+ macro (ompt_callback_implicit_task, ompt_callback_implicit_task_t, 7) /* implicit task */ \
114
+ \
115
+ macro (ompt_callback_target, ompt_callback_target_t, 8) /* target */ \
116
+ macro (ompt_callback_target_data_op, ompt_callback_target_data_op_t, 9) /* target data op */ \
117
+ macro (ompt_callback_target_submit, ompt_callback_target_submit_t, 10) /* target submit */ \
118
+ \
119
+ macro (ompt_callback_control_tool, ompt_callback_control_tool_t, 11) /* control tool */ \
120
+ \
121
+ macro (ompt_callback_device_initialize, ompt_callback_device_initialize_t, 12) /* device initialize */ \
122
+ macro (ompt_callback_device_finalize, ompt_callback_device_finalize_t, 13) /* device finalize */ \
123
+ \
124
+ macro (ompt_callback_device_load, ompt_callback_device_load_t, 14) /* device load */ \
125
+ macro (ompt_callback_device_unload, ompt_callback_device_unload_t, 15) /* device unload */ \
126
+ \
127
+ /* Optional Events */ \
128
+ macro (ompt_callback_sync_region_wait, ompt_callback_sync_region_t, 16) /* sync region wait begin or end */ \
129
+ \
130
+ macro (ompt_callback_mutex_released, ompt_callback_mutex_t, 17) /* mutex released */ \
131
+ \
132
+ macro (ompt_callback_dependences, ompt_callback_dependences_t, 18) /* report task dependences */ \
133
+ macro (ompt_callback_task_dependence, ompt_callback_task_dependence_t, 19) /* report task dependence */ \
134
+ \
135
+ macro (ompt_callback_work, ompt_callback_work_t, 20) /* task at work begin or end */ \
136
+ \
137
+ macro (ompt_callback_master, ompt_callback_master_t, 21) /* task at master begin or end */ \
138
+ \
139
+ macro (ompt_callback_target_map, ompt_callback_target_map_t, 22) /* target map */ \
140
+ \
141
+ macro (ompt_callback_sync_region, ompt_callback_sync_region_t, 23) /* sync region begin or end */ \
142
+ \
143
+ macro (ompt_callback_lock_init, ompt_callback_mutex_acquire_t, 24) /* lock init */ \
144
+ macro (ompt_callback_lock_destroy, ompt_callback_mutex_t, 25) /* lock destroy */ \
145
+ \
146
+ macro (ompt_callback_mutex_acquire, ompt_callback_mutex_acquire_t, 26) /* mutex acquire */ \
147
+ macro (ompt_callback_mutex_acquired, ompt_callback_mutex_t, 27) /* mutex acquired */ \
148
+ \
149
+ macro (ompt_callback_nest_lock, ompt_callback_nest_lock_t, 28) /* nest lock */ \
150
+ \
151
+ macro (ompt_callback_flush, ompt_callback_flush_t, 29) /* after executing flush */ \
152
+ \
153
+ macro (ompt_callback_cancel, ompt_callback_cancel_t, 30) /* cancel innermost binding region */ \
154
+ \
155
+ macro (ompt_callback_reduction, ompt_callback_sync_region_t, 31) /* reduction */ \
156
+ \
157
+ macro (ompt_callback_dispatch, ompt_callback_dispatch_t, 32) /* dispatch of work */
158
+
159
+ /*****************************************************************************
160
+ * implementation specific types
161
+ *****************************************************************************/
162
+
163
+ typedef enum kmp_mutex_impl_t {
164
+ #define kmp_mutex_impl_macro(impl, code) impl = code,
165
+ FOREACH_KMP_MUTEX_IMPL(kmp_mutex_impl_macro)
166
+ #undef kmp_mutex_impl_macro
167
+ } kmp_mutex_impl_t;
168
+
169
+ /*****************************************************************************
170
+ * definitions generated from spec
171
+ *****************************************************************************/
172
+
173
+ typedef enum ompt_callbacks_t {
174
+ ompt_callback_thread_begin = 1,
175
+ ompt_callback_thread_end = 2,
176
+ ompt_callback_parallel_begin = 3,
177
+ ompt_callback_parallel_end = 4,
178
+ ompt_callback_task_create = 5,
179
+ ompt_callback_task_schedule = 6,
180
+ ompt_callback_implicit_task = 7,
181
+ ompt_callback_target = 8,
182
+ ompt_callback_target_data_op = 9,
183
+ ompt_callback_target_submit = 10,
184
+ ompt_callback_control_tool = 11,
185
+ ompt_callback_device_initialize = 12,
186
+ ompt_callback_device_finalize = 13,
187
+ ompt_callback_device_load = 14,
188
+ ompt_callback_device_unload = 15,
189
+ ompt_callback_sync_region_wait = 16,
190
+ ompt_callback_mutex_released = 17,
191
+ ompt_callback_dependences = 18,
192
+ ompt_callback_task_dependence = 19,
193
+ ompt_callback_work = 20,
194
+ ompt_callback_master = 21,
195
+ ompt_callback_target_map = 22,
196
+ ompt_callback_sync_region = 23,
197
+ ompt_callback_lock_init = 24,
198
+ ompt_callback_lock_destroy = 25,
199
+ ompt_callback_mutex_acquire = 26,
200
+ ompt_callback_mutex_acquired = 27,
201
+ ompt_callback_nest_lock = 28,
202
+ ompt_callback_flush = 29,
203
+ ompt_callback_cancel = 30,
204
+ ompt_callback_reduction = 31,
205
+ ompt_callback_dispatch = 32
206
+ } ompt_callbacks_t;
207
+
208
+ typedef enum ompt_record_t {
209
+ ompt_record_ompt = 1,
210
+ ompt_record_native = 2,
211
+ ompt_record_invalid = 3
212
+ } ompt_record_t;
213
+
214
+ typedef enum ompt_record_native_t {
215
+ ompt_record_native_info = 1,
216
+ ompt_record_native_event = 2
217
+ } ompt_record_native_t;
218
+
219
+ typedef enum ompt_set_result_t {
220
+ ompt_set_error = 0,
221
+ ompt_set_never = 1,
222
+ ompt_set_impossible = 2,
223
+ ompt_set_sometimes = 3,
224
+ ompt_set_sometimes_paired = 4,
225
+ ompt_set_always = 5
226
+ } ompt_set_result_t;
227
+
228
+ typedef uint64_t ompt_id_t;
229
+
230
+ typedef uint64_t ompt_device_time_t;
231
+
232
+ typedef uint64_t ompt_buffer_cursor_t;
233
+
234
+ typedef enum ompt_thread_t {
235
+ ompt_thread_initial = 1,
236
+ ompt_thread_worker = 2,
237
+ ompt_thread_other = 3,
238
+ ompt_thread_unknown = 4
239
+ } ompt_thread_t;
240
+
241
+ typedef enum ompt_scope_endpoint_t {
242
+ ompt_scope_begin = 1,
243
+ ompt_scope_end = 2
244
+ } ompt_scope_endpoint_t;
245
+
246
+ typedef enum ompt_dispatch_t {
247
+ ompt_dispatch_iteration = 1,
248
+ ompt_dispatch_section = 2
249
+ } ompt_dispatch_t;
250
+
251
+ typedef enum ompt_sync_region_t {
252
+ ompt_sync_region_barrier = 1,
253
+ ompt_sync_region_barrier_implicit = 2,
254
+ ompt_sync_region_barrier_explicit = 3,
255
+ ompt_sync_region_barrier_implementation = 4,
256
+ ompt_sync_region_taskwait = 5,
257
+ ompt_sync_region_taskgroup = 6,
258
+ ompt_sync_region_reduction = 7
259
+ } ompt_sync_region_t;
260
+
261
+ typedef enum ompt_target_data_op_t {
262
+ ompt_target_data_alloc = 1,
263
+ ompt_target_data_transfer_to_device = 2,
264
+ ompt_target_data_transfer_from_device = 3,
265
+ ompt_target_data_delete = 4,
266
+ ompt_target_data_associate = 5,
267
+ ompt_target_data_disassociate = 6
268
+ } ompt_target_data_op_t;
269
+
270
+ typedef enum ompt_work_t {
271
+ ompt_work_loop = 1,
272
+ ompt_work_sections = 2,
273
+ ompt_work_single_executor = 3,
274
+ ompt_work_single_other = 4,
275
+ ompt_work_workshare = 5,
276
+ ompt_work_distribute = 6,
277
+ ompt_work_taskloop = 7
278
+ } ompt_work_t;
279
+
280
+ typedef enum ompt_mutex_t {
281
+ ompt_mutex_lock = 1,
282
+ ompt_mutex_test_lock = 2,
283
+ ompt_mutex_nest_lock = 3,
284
+ ompt_mutex_test_nest_lock = 4,
285
+ ompt_mutex_critical = 5,
286
+ ompt_mutex_atomic = 6,
287
+ ompt_mutex_ordered = 7
288
+ } ompt_mutex_t;
289
+
290
+ typedef enum ompt_native_mon_flag_t {
291
+ ompt_native_data_motion_explicit = 0x01,
292
+ ompt_native_data_motion_implicit = 0x02,
293
+ ompt_native_kernel_invocation = 0x04,
294
+ ompt_native_kernel_execution = 0x08,
295
+ ompt_native_driver = 0x10,
296
+ ompt_native_runtime = 0x20,
297
+ ompt_native_overhead = 0x40,
298
+ ompt_native_idleness = 0x80
299
+ } ompt_native_mon_flag_t;
300
+
301
+ typedef enum ompt_task_flag_t {
302
+ ompt_task_initial = 0x00000001,
303
+ ompt_task_implicit = 0x00000002,
304
+ ompt_task_explicit = 0x00000004,
305
+ ompt_task_target = 0x00000008,
306
+ ompt_task_undeferred = 0x08000000,
307
+ ompt_task_untied = 0x10000000,
308
+ ompt_task_final = 0x20000000,
309
+ ompt_task_mergeable = 0x40000000,
310
+ ompt_task_merged = 0x80000000
311
+ } ompt_task_flag_t;
312
+
313
+ typedef enum ompt_task_status_t {
314
+ ompt_task_complete = 1,
315
+ ompt_task_yield = 2,
316
+ ompt_task_cancel = 3,
317
+ ompt_task_detach = 4,
318
+ ompt_task_early_fulfill = 5,
319
+ ompt_task_late_fulfill = 6,
320
+ ompt_task_switch = 7
321
+ } ompt_task_status_t;
322
+
323
+ typedef enum ompt_target_t {
324
+ ompt_target = 1,
325
+ ompt_target_enter_data = 2,
326
+ ompt_target_exit_data = 3,
327
+ ompt_target_update = 4
328
+ } ompt_target_t;
329
+
330
+ typedef enum ompt_parallel_flag_t {
331
+ ompt_parallel_invoker_program = 0x00000001,
332
+ ompt_parallel_invoker_runtime = 0x00000002,
333
+ ompt_parallel_league = 0x40000000,
334
+ ompt_parallel_team = 0x80000000
335
+ } ompt_parallel_flag_t;
336
+
337
+ typedef enum ompt_target_map_flag_t {
338
+ ompt_target_map_flag_to = 0x01,
339
+ ompt_target_map_flag_from = 0x02,
340
+ ompt_target_map_flag_alloc = 0x04,
341
+ ompt_target_map_flag_release = 0x08,
342
+ ompt_target_map_flag_delete = 0x10,
343
+ ompt_target_map_flag_implicit = 0x20
344
+ } ompt_target_map_flag_t;
345
+
346
+ typedef enum ompt_dependence_type_t {
347
+ ompt_dependence_type_in = 1,
348
+ ompt_dependence_type_out = 2,
349
+ ompt_dependence_type_inout = 3,
350
+ ompt_dependence_type_mutexinoutset = 4,
351
+ ompt_dependence_type_source = 5,
352
+ ompt_dependence_type_sink = 6
353
+ } ompt_dependence_type_t;
354
+
355
+ typedef enum ompt_cancel_flag_t {
356
+ ompt_cancel_parallel = 0x01,
357
+ ompt_cancel_sections = 0x02,
358
+ ompt_cancel_loop = 0x04,
359
+ ompt_cancel_taskgroup = 0x08,
360
+ ompt_cancel_activated = 0x10,
361
+ ompt_cancel_detected = 0x20,
362
+ ompt_cancel_discarded_task = 0x40
363
+ } ompt_cancel_flag_t;
364
+
365
+ typedef uint64_t ompt_hwid_t;
366
+
367
+ typedef uint64_t ompt_wait_id_t;
368
+
369
+ typedef enum ompt_frame_flag_t {
370
+ ompt_frame_runtime = 0x00,
371
+ ompt_frame_application = 0x01,
372
+ ompt_frame_cfa = 0x10,
373
+ ompt_frame_framepointer = 0x20,
374
+ ompt_frame_stackaddress = 0x30
375
+ } ompt_frame_flag_t;
376
+
377
+ typedef enum ompt_state_t {
378
+ ompt_state_work_serial = 0x000,
379
+ ompt_state_work_parallel = 0x001,
380
+ ompt_state_work_reduction = 0x002,
381
+
382
+ ompt_state_wait_barrier = 0x010,
383
+ ompt_state_wait_barrier_implicit_parallel = 0x011,
384
+ ompt_state_wait_barrier_implicit_workshare = 0x012,
385
+ ompt_state_wait_barrier_implicit = 0x013,
386
+ ompt_state_wait_barrier_explicit = 0x014,
387
+
388
+ ompt_state_wait_taskwait = 0x020,
389
+ ompt_state_wait_taskgroup = 0x021,
390
+
391
+ ompt_state_wait_mutex = 0x040,
392
+ ompt_state_wait_lock = 0x041,
393
+ ompt_state_wait_critical = 0x042,
394
+ ompt_state_wait_atomic = 0x043,
395
+ ompt_state_wait_ordered = 0x044,
396
+
397
+ ompt_state_wait_target = 0x080,
398
+ ompt_state_wait_target_map = 0x081,
399
+ ompt_state_wait_target_update = 0x082,
400
+
401
+ ompt_state_idle = 0x100,
402
+ ompt_state_overhead = 0x101,
403
+ ompt_state_undefined = 0x102
404
+ } ompt_state_t;
405
+
406
+ typedef uint64_t (*ompt_get_unique_id_t) (void);
407
+
408
+ typedef uint64_t ompd_size_t;
409
+
410
+ typedef uint64_t ompd_wait_id_t;
411
+
412
+ typedef uint64_t ompd_addr_t;
413
+ typedef int64_t ompd_word_t;
414
+ typedef uint64_t ompd_seg_t;
415
+
416
+ typedef uint64_t ompd_device_t;
417
+
418
+ typedef uint64_t ompd_thread_id_t;
419
+
420
+ typedef enum ompd_scope_t {
421
+ ompd_scope_global = 1,
422
+ ompd_scope_address_space = 2,
423
+ ompd_scope_thread = 3,
424
+ ompd_scope_parallel = 4,
425
+ ompd_scope_implicit_task = 5,
426
+ ompd_scope_task = 6
427
+ } ompd_scope_t;
428
+
429
+ typedef uint64_t ompd_icv_id_t;
430
+
431
+ typedef enum ompd_rc_t {
432
+ ompd_rc_ok = 0,
433
+ ompd_rc_unavailable = 1,
434
+ ompd_rc_stale_handle = 2,
435
+ ompd_rc_bad_input = 3,
436
+ ompd_rc_error = 4,
437
+ ompd_rc_unsupported = 5,
438
+ ompd_rc_needs_state_tracking = 6,
439
+ ompd_rc_incompatible = 7,
440
+ ompd_rc_device_read_error = 8,
441
+ ompd_rc_device_write_error = 9,
442
+ ompd_rc_nomem = 10,
443
+ } ompd_rc_t;
444
+
445
+ typedef void (*ompt_interface_fn_t) (void);
446
+
447
+ typedef ompt_interface_fn_t (*ompt_function_lookup_t) (
448
+ const char *interface_function_name
449
+ );
450
+
451
+ typedef union ompt_data_t {
452
+ uint64_t value;
453
+ void *ptr;
454
+ } ompt_data_t;
455
+
456
+ typedef struct ompt_frame_t {
457
+ ompt_data_t exit_frame;
458
+ ompt_data_t enter_frame;
459
+ int exit_frame_flags;
460
+ int enter_frame_flags;
461
+ } ompt_frame_t;
462
+
463
+ typedef void (*ompt_callback_t) (void);
464
+
465
+ typedef void ompt_device_t;
466
+
467
+ typedef void ompt_buffer_t;
468
+
469
+ typedef void (*ompt_callback_buffer_request_t) (
470
+ int device_num,
471
+ ompt_buffer_t **buffer,
472
+ size_t *bytes
473
+ );
474
+
475
+ typedef void (*ompt_callback_buffer_complete_t) (
476
+ int device_num,
477
+ ompt_buffer_t *buffer,
478
+ size_t bytes,
479
+ ompt_buffer_cursor_t begin,
480
+ int buffer_owned
481
+ );
482
+
483
+ typedef void (*ompt_finalize_t) (
484
+ ompt_data_t *tool_data
485
+ );
486
+
487
+ typedef int (*ompt_initialize_t) (
488
+ ompt_function_lookup_t lookup,
489
+ int initial_device_num,
490
+ ompt_data_t *tool_data
491
+ );
492
+
493
+ typedef struct ompt_start_tool_result_t {
494
+ ompt_initialize_t initialize;
495
+ ompt_finalize_t finalize;
496
+ ompt_data_t tool_data;
497
+ } ompt_start_tool_result_t;
498
+
499
+ typedef struct ompt_record_abstract_t {
500
+ ompt_record_native_t rclass;
501
+ const char *type;
502
+ ompt_device_time_t start_time;
503
+ ompt_device_time_t end_time;
504
+ ompt_hwid_t hwid;
505
+ } ompt_record_abstract_t;
506
+
507
+ typedef struct ompt_dependence_t {
508
+ ompt_data_t variable;
509
+ ompt_dependence_type_t dependence_type;
510
+ } ompt_dependence_t;
511
+
512
+ typedef int (*ompt_enumerate_states_t) (
513
+ int current_state,
514
+ int *next_state,
515
+ const char **next_state_name
516
+ );
517
+
518
+ typedef int (*ompt_enumerate_mutex_impls_t) (
519
+ int current_impl,
520
+ int *next_impl,
521
+ const char **next_impl_name
522
+ );
523
+
524
+ typedef ompt_set_result_t (*ompt_set_callback_t) (
525
+ ompt_callbacks_t event,
526
+ ompt_callback_t callback
527
+ );
528
+
529
+ typedef int (*ompt_get_callback_t) (
530
+ ompt_callbacks_t event,
531
+ ompt_callback_t *callback
532
+ );
533
+
534
+ typedef ompt_data_t *(*ompt_get_thread_data_t) (void);
535
+
536
+ typedef int (*ompt_get_num_procs_t) (void);
537
+
538
+ typedef int (*ompt_get_num_places_t) (void);
539
+
540
+ typedef int (*ompt_get_place_proc_ids_t) (
541
+ int place_num,
542
+ int ids_size,
543
+ int *ids
544
+ );
545
+
546
+ typedef int (*ompt_get_place_num_t) (void);
547
+
548
+ typedef int (*ompt_get_partition_place_nums_t) (
549
+ int place_nums_size,
550
+ int *place_nums
551
+ );
552
+
553
+ typedef int (*ompt_get_proc_id_t) (void);
554
+
555
+ typedef int (*ompt_get_state_t) (
556
+ ompt_wait_id_t *wait_id
557
+ );
558
+
559
+ typedef int (*ompt_get_parallel_info_t) (
560
+ int ancestor_level,
561
+ ompt_data_t **parallel_data,
562
+ int *team_size
563
+ );
564
+
565
+ typedef int (*ompt_get_task_info_t) (
566
+ int ancestor_level,
567
+ int *flags,
568
+ ompt_data_t **task_data,
569
+ ompt_frame_t **task_frame,
570
+ ompt_data_t **parallel_data,
571
+ int *thread_num
572
+ );
573
+
574
+ typedef int (*ompt_get_task_memory_t)(
575
+ void **addr,
576
+ size_t *size,
577
+ int block
578
+ );
579
+
580
+ typedef int (*ompt_get_target_info_t) (
581
+ uint64_t *device_num,
582
+ ompt_id_t *target_id,
583
+ ompt_id_t *host_op_id
584
+ );
585
+
586
+ typedef int (*ompt_get_num_devices_t) (void);
587
+
588
+ typedef void (*ompt_finalize_tool_t) (void);
589
+
590
+ typedef int (*ompt_get_device_num_procs_t) (
591
+ ompt_device_t *device
592
+ );
593
+
594
+ typedef ompt_device_time_t (*ompt_get_device_time_t) (
595
+ ompt_device_t *device
596
+ );
597
+
598
+ typedef double (*ompt_translate_time_t) (
599
+ ompt_device_t *device,
600
+ ompt_device_time_t time
601
+ );
602
+
603
+ typedef ompt_set_result_t (*ompt_set_trace_ompt_t) (
604
+ ompt_device_t *device,
605
+ unsigned int enable,
606
+ unsigned int etype
607
+ );
608
+
609
+ typedef ompt_set_result_t (*ompt_set_trace_native_t) (
610
+ ompt_device_t *device,
611
+ int enable,
612
+ int flags
613
+ );
614
+
615
+ typedef int (*ompt_start_trace_t) (
616
+ ompt_device_t *device,
617
+ ompt_callback_buffer_request_t request,
618
+ ompt_callback_buffer_complete_t complete
619
+ );
620
+
621
+ typedef int (*ompt_pause_trace_t) (
622
+ ompt_device_t *device,
623
+ int begin_pause
624
+ );
625
+
626
+ typedef int (*ompt_flush_trace_t) (
627
+ ompt_device_t *device
628
+ );
629
+
630
+ typedef int (*ompt_stop_trace_t) (
631
+ ompt_device_t *device
632
+ );
633
+
634
+ typedef int (*ompt_advance_buffer_cursor_t) (
635
+ ompt_device_t *device,
636
+ ompt_buffer_t *buffer,
637
+ size_t size,
638
+ ompt_buffer_cursor_t current,
639
+ ompt_buffer_cursor_t *next
640
+ );
641
+
642
+ typedef ompt_record_t (*ompt_get_record_type_t) (
643
+ ompt_buffer_t *buffer,
644
+ ompt_buffer_cursor_t current
645
+ );
646
+
647
+ typedef void *(*ompt_get_record_native_t) (
648
+ ompt_buffer_t *buffer,
649
+ ompt_buffer_cursor_t current,
650
+ ompt_id_t *host_op_id
651
+ );
652
+
653
+ typedef ompt_record_abstract_t *
654
+ (*ompt_get_record_abstract_t) (
655
+ void *native_record
656
+ );
657
+
658
+ typedef void (*ompt_callback_thread_begin_t) (
659
+ ompt_thread_t thread_type,
660
+ ompt_data_t *thread_data
661
+ );
662
+
663
+ typedef struct ompt_record_thread_begin_t {
664
+ ompt_thread_t thread_type;
665
+ } ompt_record_thread_begin_t;
666
+
667
+ typedef void (*ompt_callback_thread_end_t) (
668
+ ompt_data_t *thread_data
669
+ );
670
+
671
+ typedef void (*ompt_callback_parallel_begin_t) (
672
+ ompt_data_t *encountering_task_data,
673
+ const ompt_frame_t *encountering_task_frame,
674
+ ompt_data_t *parallel_data,
675
+ unsigned int requested_parallelism,
676
+ int flags,
677
+ const void *codeptr_ra
678
+ );
679
+
680
+ typedef struct ompt_record_parallel_begin_t {
681
+ ompt_id_t encountering_task_id;
682
+ ompt_id_t parallel_id;
683
+ unsigned int requested_parallelism;
684
+ int flags;
685
+ const void *codeptr_ra;
686
+ } ompt_record_parallel_begin_t;
687
+
688
+ typedef void (*ompt_callback_parallel_end_t) (
689
+ ompt_data_t *parallel_data,
690
+ ompt_data_t *encountering_task_data,
691
+ int flags,
692
+ const void *codeptr_ra
693
+ );
694
+
695
+ typedef struct ompt_record_parallel_end_t {
696
+ ompt_id_t parallel_id;
697
+ ompt_id_t encountering_task_id;
698
+ int flags;
699
+ const void *codeptr_ra;
700
+ } ompt_record_parallel_end_t;
701
+
702
+ typedef void (*ompt_callback_work_t) (
703
+ ompt_work_t wstype,
704
+ ompt_scope_endpoint_t endpoint,
705
+ ompt_data_t *parallel_data,
706
+ ompt_data_t *task_data,
707
+ uint64_t count,
708
+ const void *codeptr_ra
709
+ );
710
+
711
+ typedef struct ompt_record_work_t {
712
+ ompt_work_t wstype;
713
+ ompt_scope_endpoint_t endpoint;
714
+ ompt_id_t parallel_id;
715
+ ompt_id_t task_id;
716
+ uint64_t count;
717
+ const void *codeptr_ra;
718
+ } ompt_record_work_t;
719
+
720
+ typedef void (*ompt_callback_dispatch_t) (
721
+ ompt_data_t *parallel_data,
722
+ ompt_data_t *task_data,
723
+ ompt_dispatch_t kind,
724
+ ompt_data_t instance
725
+ );
726
+
727
+ typedef struct ompt_record_dispatch_t {
728
+ ompt_id_t parallel_id;
729
+ ompt_id_t task_id;
730
+ ompt_dispatch_t kind;
731
+ ompt_data_t instance;
732
+ } ompt_record_dispatch_t;
733
+
734
+ typedef void (*ompt_callback_task_create_t) (
735
+ ompt_data_t *encountering_task_data,
736
+ const ompt_frame_t *encountering_task_frame,
737
+ ompt_data_t *new_task_data,
738
+ int flags,
739
+ int has_dependences,
740
+ const void *codeptr_ra
741
+ );
742
+
743
+ typedef struct ompt_record_task_create_t {
744
+ ompt_id_t encountering_task_id;
745
+ ompt_id_t new_task_id;
746
+ int flags;
747
+ int has_dependences;
748
+ const void *codeptr_ra;
749
+ } ompt_record_task_create_t;
750
+
751
+ typedef void (*ompt_callback_dependences_t) (
752
+ ompt_data_t *task_data,
753
+ const ompt_dependence_t *deps,
754
+ int ndeps
755
+ );
756
+
757
+ typedef struct ompt_record_dependences_t {
758
+ ompt_id_t task_id;
759
+ ompt_dependence_t dep;
760
+ int ndeps;
761
+ } ompt_record_dependences_t;
762
+
763
+ typedef void (*ompt_callback_task_dependence_t) (
764
+ ompt_data_t *src_task_data,
765
+ ompt_data_t *sink_task_data
766
+ );
767
+
768
+ typedef struct ompt_record_task_dependence_t {
769
+ ompt_id_t src_task_id;
770
+ ompt_id_t sink_task_id;
771
+ } ompt_record_task_dependence_t;
772
+
773
+ typedef void (*ompt_callback_task_schedule_t) (
774
+ ompt_data_t *prior_task_data,
775
+ ompt_task_status_t prior_task_status,
776
+ ompt_data_t *next_task_data
777
+ );
778
+
779
+ typedef struct ompt_record_task_schedule_t {
780
+ ompt_id_t prior_task_id;
781
+ ompt_task_status_t prior_task_status;
782
+ ompt_id_t next_task_id;
783
+ } ompt_record_task_schedule_t;
784
+
785
+ typedef void (*ompt_callback_implicit_task_t) (
786
+ ompt_scope_endpoint_t endpoint,
787
+ ompt_data_t *parallel_data,
788
+ ompt_data_t *task_data,
789
+ unsigned int actual_parallelism,
790
+ unsigned int index,
791
+ int flags
792
+ );
793
+
794
+ typedef struct ompt_record_implicit_task_t {
795
+ ompt_scope_endpoint_t endpoint;
796
+ ompt_id_t parallel_id;
797
+ ompt_id_t task_id;
798
+ unsigned int actual_parallelism;
799
+ unsigned int index;
800
+ int flags;
801
+ } ompt_record_implicit_task_t;
802
+
803
+ typedef void (*ompt_callback_master_t) (
804
+ ompt_scope_endpoint_t endpoint,
805
+ ompt_data_t *parallel_data,
806
+ ompt_data_t *task_data,
807
+ const void *codeptr_ra
808
+ );
809
+
810
+ typedef struct ompt_record_master_t {
811
+ ompt_scope_endpoint_t endpoint;
812
+ ompt_id_t parallel_id;
813
+ ompt_id_t task_id;
814
+ const void *codeptr_ra;
815
+ } ompt_record_master_t;
816
+
817
+ typedef void (*ompt_callback_sync_region_t) (
818
+ ompt_sync_region_t kind,
819
+ ompt_scope_endpoint_t endpoint,
820
+ ompt_data_t *parallel_data,
821
+ ompt_data_t *task_data,
822
+ const void *codeptr_ra
823
+ );
824
+
825
+ typedef struct ompt_record_sync_region_t {
826
+ ompt_sync_region_t kind;
827
+ ompt_scope_endpoint_t endpoint;
828
+ ompt_id_t parallel_id;
829
+ ompt_id_t task_id;
830
+ const void *codeptr_ra;
831
+ } ompt_record_sync_region_t;
832
+
833
+ typedef void (*ompt_callback_mutex_acquire_t) (
834
+ ompt_mutex_t kind,
835
+ unsigned int hint,
836
+ unsigned int impl,
837
+ ompt_wait_id_t wait_id,
838
+ const void *codeptr_ra
839
+ );
840
+
841
+ typedef struct ompt_record_mutex_acquire_t {
842
+ ompt_mutex_t kind;
843
+ unsigned int hint;
844
+ unsigned int impl;
845
+ ompt_wait_id_t wait_id;
846
+ const void *codeptr_ra;
847
+ } ompt_record_mutex_acquire_t;
848
+
849
+ typedef void (*ompt_callback_mutex_t) (
850
+ ompt_mutex_t kind,
851
+ ompt_wait_id_t wait_id,
852
+ const void *codeptr_ra
853
+ );
854
+
855
+ typedef struct ompt_record_mutex_t {
856
+ ompt_mutex_t kind;
857
+ ompt_wait_id_t wait_id;
858
+ const void *codeptr_ra;
859
+ } ompt_record_mutex_t;
860
+
861
+ typedef void (*ompt_callback_nest_lock_t) (
862
+ ompt_scope_endpoint_t endpoint,
863
+ ompt_wait_id_t wait_id,
864
+ const void *codeptr_ra
865
+ );
866
+
867
+ typedef struct ompt_record_nest_lock_t {
868
+ ompt_scope_endpoint_t endpoint;
869
+ ompt_wait_id_t wait_id;
870
+ const void *codeptr_ra;
871
+ } ompt_record_nest_lock_t;
872
+
873
+ typedef void (*ompt_callback_flush_t) (
874
+ ompt_data_t *thread_data,
875
+ const void *codeptr_ra
876
+ );
877
+
878
+ typedef struct ompt_record_flush_t {
879
+ const void *codeptr_ra;
880
+ } ompt_record_flush_t;
881
+
882
+ typedef void (*ompt_callback_cancel_t) (
883
+ ompt_data_t *task_data,
884
+ int flags,
885
+ const void *codeptr_ra
886
+ );
887
+
888
+ typedef struct ompt_record_cancel_t {
889
+ ompt_id_t task_id;
890
+ int flags;
891
+ const void *codeptr_ra;
892
+ } ompt_record_cancel_t;
893
+
894
+ typedef void (*ompt_callback_device_initialize_t) (
895
+ int device_num,
896
+ const char *type,
897
+ ompt_device_t *device,
898
+ ompt_function_lookup_t lookup,
899
+ const char *documentation
900
+ );
901
+
902
+ typedef void (*ompt_callback_device_finalize_t) (
903
+ int device_num
904
+ );
905
+
906
+ typedef void (*ompt_callback_device_load_t) (
907
+ int device_num,
908
+ const char *filename,
909
+ int64_t offset_in_file,
910
+ void *vma_in_file,
911
+ size_t bytes,
912
+ void *host_addr,
913
+ void *device_addr,
914
+ uint64_t module_id
915
+ );
916
+
917
+ typedef void (*ompt_callback_device_unload_t) (
918
+ int device_num,
919
+ uint64_t module_id
920
+ );
921
+
922
+ typedef void (*ompt_callback_target_data_op_t) (
923
+ ompt_id_t target_id,
924
+ ompt_id_t host_op_id,
925
+ ompt_target_data_op_t optype,
926
+ void *src_addr,
927
+ int src_device_num,
928
+ void *dest_addr,
929
+ int dest_device_num,
930
+ size_t bytes,
931
+ const void *codeptr_ra
932
+ );
933
+
934
+ typedef struct ompt_record_target_data_op_t {
935
+ ompt_id_t host_op_id;
936
+ ompt_target_data_op_t optype;
937
+ void *src_addr;
938
+ int src_device_num;
939
+ void *dest_addr;
940
+ int dest_device_num;
941
+ size_t bytes;
942
+ ompt_device_time_t end_time;
943
+ const void *codeptr_ra;
944
+ } ompt_record_target_data_op_t;
945
+
946
+ typedef void (*ompt_callback_target_t) (
947
+ ompt_target_t kind,
948
+ ompt_scope_endpoint_t endpoint,
949
+ int device_num,
950
+ ompt_data_t *task_data,
951
+ ompt_id_t target_id,
952
+ const void *codeptr_ra
953
+ );
954
+
955
+ typedef struct ompt_record_target_t {
956
+ ompt_target_t kind;
957
+ ompt_scope_endpoint_t endpoint;
958
+ int device_num;
959
+ ompt_id_t task_id;
960
+ ompt_id_t target_id;
961
+ const void *codeptr_ra;
962
+ } ompt_record_target_t;
963
+
964
+ typedef void (*ompt_callback_target_map_t) (
965
+ ompt_id_t target_id,
966
+ unsigned int nitems,
967
+ void **host_addr,
968
+ void **device_addr,
969
+ size_t *bytes,
970
+ unsigned int *mapping_flags,
971
+ const void *codeptr_ra
972
+ );
973
+
974
+ typedef struct ompt_record_target_map_t {
975
+ ompt_id_t target_id;
976
+ unsigned int nitems;
977
+ void **host_addr;
978
+ void **device_addr;
979
+ size_t *bytes;
980
+ unsigned int *mapping_flags;
981
+ const void *codeptr_ra;
982
+ } ompt_record_target_map_t;
983
+
984
+ typedef void (*ompt_callback_target_submit_t) (
985
+ ompt_id_t target_id,
986
+ ompt_id_t host_op_id,
987
+ unsigned int requested_num_teams
988
+ );
989
+
990
+ typedef struct ompt_record_target_kernel_t {
991
+ ompt_id_t host_op_id;
992
+ unsigned int requested_num_teams;
993
+ unsigned int granted_num_teams;
994
+ ompt_device_time_t end_time;
995
+ } ompt_record_target_kernel_t;
996
+
997
+ typedef int (*ompt_callback_control_tool_t) (
998
+ uint64_t command,
999
+ uint64_t modifier,
1000
+ void *arg,
1001
+ const void *codeptr_ra
1002
+ );
1003
+
1004
+ typedef struct ompt_record_control_tool_t {
1005
+ uint64_t command;
1006
+ uint64_t modifier;
1007
+ const void *codeptr_ra;
1008
+ } ompt_record_control_tool_t;
1009
+
1010
+ typedef struct ompd_address_t {
1011
+ ompd_seg_t segment;
1012
+ ompd_addr_t address;
1013
+ } ompd_address_t;
1014
+
1015
+ typedef struct ompd_frame_info_t {
1016
+ ompd_address_t frame_address;
1017
+ ompd_word_t frame_flag;
1018
+ } ompd_frame_info_t;
1019
+
1020
+ typedef struct _ompd_aspace_handle ompd_address_space_handle_t;
1021
+ typedef struct _ompd_thread_handle ompd_thread_handle_t;
1022
+ typedef struct _ompd_parallel_handle ompd_parallel_handle_t;
1023
+ typedef struct _ompd_task_handle ompd_task_handle_t;
1024
+
1025
+ typedef struct _ompd_aspace_cont ompd_address_space_context_t;
1026
+ typedef struct _ompd_thread_cont ompd_thread_context_t;
1027
+
1028
+ typedef struct ompd_device_type_sizes_t {
1029
+ uint8_t sizeof_char;
1030
+ uint8_t sizeof_short;
1031
+ uint8_t sizeof_int;
1032
+ uint8_t sizeof_long;
1033
+ uint8_t sizeof_long_long;
1034
+ uint8_t sizeof_pointer;
1035
+ } ompd_device_type_sizes_t;
1036
+
1037
+ typedef struct ompt_record_ompt_t {
1038
+ ompt_callbacks_t type;
1039
+ ompt_device_time_t time;
1040
+ ompt_id_t thread_id;
1041
+ ompt_id_t target_id;
1042
+ union {
1043
+ ompt_record_thread_begin_t thread_begin;
1044
+ ompt_record_parallel_begin_t parallel_begin;
1045
+ ompt_record_parallel_end_t parallel_end;
1046
+ ompt_record_work_t work;
1047
+ ompt_record_dispatch_t dispatch;
1048
+ ompt_record_task_create_t task_create;
1049
+ ompt_record_dependences_t dependences;
1050
+ ompt_record_task_dependence_t task_dependence;
1051
+ ompt_record_task_schedule_t task_schedule;
1052
+ ompt_record_implicit_task_t implicit_task;
1053
+ ompt_record_master_t master;
1054
+ ompt_record_sync_region_t sync_region;
1055
+ ompt_record_mutex_acquire_t mutex_acquire;
1056
+ ompt_record_mutex_t mutex;
1057
+ ompt_record_nest_lock_t nest_lock;
1058
+ ompt_record_flush_t flush;
1059
+ ompt_record_cancel_t cancel;
1060
+ ompt_record_target_t target;
1061
+ ompt_record_target_data_op_t target_data_op;
1062
+ ompt_record_target_map_t target_map;
1063
+ ompt_record_target_kernel_t target_kernel;
1064
+ ompt_record_control_tool_t control_tool;
1065
+ } record;
1066
+ } ompt_record_ompt_t;
1067
+
1068
+ typedef ompt_record_ompt_t *(*ompt_get_record_ompt_t) (
1069
+ ompt_buffer_t *buffer,
1070
+ ompt_buffer_cursor_t current
1071
+ );
1072
+
1073
+ #define ompt_id_none 0
1074
+ #define ompt_data_none {0}
1075
+ #define ompt_time_none 0
1076
+ #define ompt_hwid_none 0
1077
+ #define ompt_addr_none ~0
1078
+ #define ompt_mutex_impl_none 0
1079
+ #define ompt_wait_id_none 0
1080
+
1081
+ #define ompd_segment_none 0
1082
+
1083
+ #endif /* __OMPT__ */
include/nettle/aes.h ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* aes.h
2
+
3
+ The aes/rijndael block cipher.
4
+
5
+ Copyright (C) 2001, 2013 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_AES_H_INCLUDED
35
+ #define NETTLE_AES_H_INCLUDED
36
+
37
+ #include "nettle-types.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /* Name mangling */
44
+ #define aes_set_encrypt_key nettle_aes_set_encrypt_key
45
+ #define aes_set_decrypt_key nettle_aes_set_decrypt_key
46
+ #define aes_invert_key nettle_aes_invert_key
47
+ #define aes_encrypt nettle_aes_encrypt
48
+ #define aes_decrypt nettle_aes_decrypt
49
+ #define aes128_set_encrypt_key nettle_aes128_set_encrypt_key
50
+ #define aes128_set_decrypt_key nettle_aes128_set_decrypt_key
51
+ #define aes128_invert_key nettle_aes128_invert_key
52
+ #define aes128_encrypt nettle_aes128_encrypt
53
+ #define aes128_decrypt nettle_aes128_decrypt
54
+ #define aes192_set_encrypt_key nettle_aes192_set_encrypt_key
55
+ #define aes192_set_decrypt_key nettle_aes192_set_decrypt_key
56
+ #define aes192_invert_key nettle_aes192_invert_key
57
+ #define aes192_encrypt nettle_aes192_encrypt
58
+ #define aes192_decrypt nettle_aes192_decrypt
59
+ #define aes256_set_encrypt_key nettle_aes256_set_encrypt_key
60
+ #define aes256_set_decrypt_key nettle_aes256_set_decrypt_key
61
+ #define aes256_invert_key nettle_aes256_invert_key
62
+ #define aes256_encrypt nettle_aes256_encrypt
63
+ #define aes256_decrypt nettle_aes256_decrypt
64
+
65
+ #define AES_BLOCK_SIZE 16
66
+
67
+ #define AES128_KEY_SIZE 16
68
+ #define AES192_KEY_SIZE 24
69
+ #define AES256_KEY_SIZE 32
70
+ #define _AES128_ROUNDS 10
71
+ #define _AES192_ROUNDS 12
72
+ #define _AES256_ROUNDS 14
73
+
74
+ struct aes128_ctx
75
+ {
76
+ uint32_t keys[4 * (_AES128_ROUNDS + 1)];
77
+ };
78
+
79
+ void
80
+ aes128_set_encrypt_key(struct aes128_ctx *ctx, const uint8_t *key);
81
+ void
82
+ aes128_set_decrypt_key(struct aes128_ctx *ctx, const uint8_t *key);
83
+ void
84
+ aes128_invert_key(struct aes128_ctx *dst,
85
+ const struct aes128_ctx *src);
86
+ void
87
+ aes128_encrypt(const struct aes128_ctx *ctx,
88
+ size_t length, uint8_t *dst,
89
+ const uint8_t *src);
90
+ void
91
+ aes128_decrypt(const struct aes128_ctx *ctx,
92
+ size_t length, uint8_t *dst,
93
+ const uint8_t *src);
94
+
95
+ struct aes192_ctx
96
+ {
97
+ uint32_t keys[4 * (_AES192_ROUNDS + 1)];
98
+ };
99
+
100
+ void
101
+ aes192_set_encrypt_key(struct aes192_ctx *ctx, const uint8_t *key);
102
+ void
103
+ aes192_set_decrypt_key(struct aes192_ctx *ctx, const uint8_t *key);
104
+ void
105
+ aes192_invert_key(struct aes192_ctx *dst,
106
+ const struct aes192_ctx *src);
107
+ void
108
+ aes192_encrypt(const struct aes192_ctx *ctx,
109
+ size_t length, uint8_t *dst,
110
+ const uint8_t *src);
111
+ void
112
+ aes192_decrypt(const struct aes192_ctx *ctx,
113
+ size_t length, uint8_t *dst,
114
+ const uint8_t *src);
115
+
116
+ struct aes256_ctx
117
+ {
118
+ uint32_t keys[4 * (_AES256_ROUNDS + 1)];
119
+ };
120
+
121
+ void
122
+ aes256_set_encrypt_key(struct aes256_ctx *ctx, const uint8_t *key);
123
+ void
124
+ aes256_set_decrypt_key(struct aes256_ctx *ctx, const uint8_t *key);
125
+ void
126
+ aes256_invert_key(struct aes256_ctx *dst,
127
+ const struct aes256_ctx *src);
128
+ void
129
+ aes256_encrypt(const struct aes256_ctx *ctx,
130
+ size_t length, uint8_t *dst,
131
+ const uint8_t *src);
132
+ void
133
+ aes256_decrypt(const struct aes256_ctx *ctx,
134
+ size_t length, uint8_t *dst,
135
+ const uint8_t *src);
136
+
137
+ /* The older nettle-2.7 AES interface is deprecated, please migrate to
138
+ the newer interface where each algorithm has a fixed key size. */
139
+
140
+ /* Variable key size between 128 and 256 bits. But the only valid
141
+ * values are 16 (128 bits), 24 (192 bits) and 32 (256 bits). */
142
+ #define AES_MIN_KEY_SIZE AES128_KEY_SIZE
143
+ #define AES_MAX_KEY_SIZE AES256_KEY_SIZE
144
+
145
+ #define AES_KEY_SIZE 32
146
+
147
+ struct aes_ctx
148
+ {
149
+ unsigned key_size; /* In octets */
150
+ union {
151
+ struct aes128_ctx ctx128;
152
+ struct aes192_ctx ctx192;
153
+ struct aes256_ctx ctx256;
154
+ } u;
155
+ };
156
+
157
+ void
158
+ aes_set_encrypt_key(struct aes_ctx *ctx,
159
+ size_t length, const uint8_t *key)
160
+ _NETTLE_ATTRIBUTE_DEPRECATED;
161
+
162
+ void
163
+ aes_set_decrypt_key(struct aes_ctx *ctx,
164
+ size_t length, const uint8_t *key)
165
+ _NETTLE_ATTRIBUTE_DEPRECATED;
166
+
167
+ void
168
+ aes_invert_key(struct aes_ctx *dst,
169
+ const struct aes_ctx *src)
170
+ _NETTLE_ATTRIBUTE_DEPRECATED;
171
+
172
+ void
173
+ aes_encrypt(const struct aes_ctx *ctx,
174
+ size_t length, uint8_t *dst,
175
+ const uint8_t *src) _NETTLE_ATTRIBUTE_DEPRECATED;
176
+ void
177
+ aes_decrypt(const struct aes_ctx *ctx,
178
+ size_t length, uint8_t *dst,
179
+ const uint8_t *src) _NETTLE_ATTRIBUTE_DEPRECATED;
180
+
181
+ #ifdef __cplusplus
182
+ }
183
+ #endif
184
+
185
+ #endif /* NETTLE_AES_H_INCLUDED */
include/nettle/arcfour.h ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* arcfour.h
2
+
3
+ The arcfour/rc4 stream cipher.
4
+
5
+ Copyright (C) 2001, 2014 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_ARCFOUR_H_INCLUDED
35
+ #define NETTLE_ARCFOUR_H_INCLUDED
36
+
37
+ #include "nettle-types.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /* Name mangling */
44
+ #define arcfour128_set_key nettle_arcfour128_set_key
45
+ #define arcfour_set_key nettle_arcfour_set_key
46
+ #define arcfour_crypt nettle_arcfour_crypt
47
+
48
+ /* Minimum and maximum keysizes, and a reasonable default. In
49
+ * octets.*/
50
+ #define ARCFOUR_MIN_KEY_SIZE 1
51
+ #define ARCFOUR_MAX_KEY_SIZE 256
52
+ #define ARCFOUR_KEY_SIZE 16
53
+ #define ARCFOUR128_KEY_SIZE 16
54
+
55
+ struct arcfour_ctx
56
+ {
57
+ uint8_t S[256];
58
+ uint8_t i;
59
+ uint8_t j;
60
+ };
61
+
62
+ void
63
+ arcfour_set_key(struct arcfour_ctx *ctx,
64
+ size_t length, const uint8_t *key);
65
+
66
+ void
67
+ arcfour128_set_key(struct arcfour_ctx *ctx, const uint8_t *key);
68
+
69
+ void
70
+ arcfour_crypt(struct arcfour_ctx *ctx,
71
+ size_t length, uint8_t *dst,
72
+ const uint8_t *src);
73
+
74
+ #ifdef __cplusplus
75
+ }
76
+ #endif
77
+
78
+ #endif /* NETTLE_ARCFOUR_H_INCLUDED */
79
+
include/nettle/arctwo.h ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* arctwo.h
2
+
3
+ The arctwo/rfc2268 block cipher.
4
+
5
+ Copyright (C) 2004 Simon Josefsson
6
+ Copyright (C) 2002, 2004, 2014 Niels Möller
7
+
8
+ This file is part of GNU Nettle.
9
+
10
+ GNU Nettle is free software: you can redistribute it and/or
11
+ modify it under the terms of either:
12
+
13
+ * the GNU Lesser General Public License as published by the Free
14
+ Software Foundation; either version 3 of the License, or (at your
15
+ option) any later version.
16
+
17
+ or
18
+
19
+ * the GNU General Public License as published by the Free
20
+ Software Foundation; either version 2 of the License, or (at your
21
+ option) any later version.
22
+
23
+ or both in parallel, as here.
24
+
25
+ GNU Nettle is distributed in the hope that it will be useful,
26
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
+ General Public License for more details.
29
+
30
+ You should have received copies of the GNU General Public License and
31
+ the GNU Lesser General Public License along with this program. If
32
+ not, see http://www.gnu.org/licenses/.
33
+ */
34
+
35
+ #ifndef NETTLE_ARCTWO_H_INCLUDED
36
+ #define NETTLE_ARCTWO_H_INCLUDED
37
+
38
+ #include "nettle-types.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* Name mangling */
45
+ #define arctwo_set_key nettle_arctwo_set_key
46
+ #define arctwo_set_key_ekb nettle_arctwo_set_key_ekb
47
+ #define arctwo_set_key_gutmann nettle_arctwo_set_key_gutmann
48
+ #define arctwo40_set_key nettle_arctwo40_set_key
49
+ #define arctwo64_set_key nettle_arctwo64_set_key
50
+ #define arctwo128_set_key nettle_arctwo128_set_key
51
+ #define arctwo128_set_key_gutmann nettle_arctwo128_set_key_gutmann
52
+ #define arctwo_encrypt nettle_arctwo_encrypt
53
+ #define arctwo_decrypt nettle_arctwo_decrypt
54
+
55
+ #define ARCTWO_BLOCK_SIZE 8
56
+
57
+ /* Variable key size from 1 byte to 128 bytes. */
58
+ #define ARCTWO_MIN_KEY_SIZE 1
59
+ #define ARCTWO_MAX_KEY_SIZE 128
60
+
61
+ #define ARCTWO_KEY_SIZE 8
62
+
63
+ struct arctwo_ctx
64
+ {
65
+ uint16_t S[64];
66
+ };
67
+
68
+ /* Key expansion function that takes the "effective key bits", 1-1024,
69
+ as an explicit argument. 0 means maximum key bits. */
70
+ void
71
+ arctwo_set_key_ekb (struct arctwo_ctx *ctx,
72
+ size_t length, const uint8_t * key, unsigned ekb);
73
+
74
+ /* Equvivalent to arctwo_set_key_ekb, with ekb = 8 * length */
75
+ void
76
+ arctwo_set_key (struct arctwo_ctx *ctx, size_t length, const uint8_t *key);
77
+ void
78
+ arctwo40_set_key (struct arctwo_ctx *ctx, const uint8_t *key);
79
+ void
80
+ arctwo64_set_key (struct arctwo_ctx *ctx, const uint8_t *key);
81
+ void
82
+ arctwo128_set_key (struct arctwo_ctx *ctx, const uint8_t *key);
83
+
84
+ /* Equvivalent to arctwo_set_key_ekb, with ekb = 1024 */
85
+ void
86
+ arctwo_set_key_gutmann (struct arctwo_ctx *ctx,
87
+ size_t length, const uint8_t *key);
88
+ void
89
+ arctwo128_set_key_gutmann (struct arctwo_ctx *ctx,
90
+ const uint8_t *key);
91
+
92
+ void
93
+ arctwo_encrypt (struct arctwo_ctx *ctx,
94
+ size_t length, uint8_t *dst, const uint8_t *src);
95
+ void
96
+ arctwo_decrypt (struct arctwo_ctx *ctx,
97
+ size_t length, uint8_t *dst, const uint8_t *src);
98
+
99
+ #ifdef __cplusplus
100
+ }
101
+ #endif
102
+
103
+ #endif /* NETTLE_ARCTWO_H_INCLUDED */
include/nettle/asn1.h ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* asn1.h
2
+
3
+ Limited support for ASN.1 DER decoding.
4
+
5
+ Copyright (C) 2005 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_ASN1_H_INCLUDED
35
+ #define NETTLE_ASN1_H_INCLUDED
36
+
37
+ #include "nettle-types.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /* Name mangling */
44
+ #define asn1_der_iterator_first nettle_asn1_der_iterator_first
45
+ #define asn1_der_iterator_next nettle_asn1_der_iterator_next
46
+ #define asn1_der_decode_constructed nettle_asn1_der_decode_constructed
47
+ #define asn1_der_decode_constructed_last nettle_asn1_der_decode_constructed_last
48
+ #define asn1_der_decode_bitstring nettle_asn1_der_decode_bitstring
49
+ #define asn1_der_decode_bitstring_last nettle_asn1_der_decode_bitstring_last
50
+ #define asn1_der_get_uint32 nettle_asn1_der_get_uint32
51
+ #define asn1_der_get_bignum nettle_asn1_der_get_bignum
52
+
53
+
54
+ /* enum asn1_type keeps the class number and the constructive in bits
55
+ 13-14, and the constructive flag in bit 12. The remaining 14 bits
56
+ are the tag (although currently, only tags in the range 0-30 are
57
+ supported). */
58
+
59
+ enum
60
+ {
61
+ ASN1_TYPE_CONSTRUCTED = 1 << 12,
62
+
63
+ ASN1_CLASS_UNIVERSAL = 0,
64
+ ASN1_CLASS_APPLICATION = 1 << 13,
65
+ ASN1_CLASS_CONTEXT_SPECIFIC = 2 << 13,
66
+ ASN1_CLASS_PRIVATE = 3 << 13,
67
+
68
+ ASN1_CLASS_MASK = 3 << 13,
69
+ ASN1_CLASS_SHIFT = 13,
70
+ };
71
+
72
+ enum asn1_type
73
+ {
74
+ ASN1_BOOLEAN = 1,
75
+ ASN1_INTEGER = 2,
76
+ ASN1_BITSTRING = 3,
77
+ ASN1_OCTETSTRING = 4,
78
+ ASN1_NULL = 5,
79
+ ASN1_IDENTIFIER = 6,
80
+ ASN1_REAL = 9,
81
+ ASN1_ENUMERATED = 10,
82
+ ASN1_UTF8STRING = 12,
83
+ ASN1_SEQUENCE = 16 | ASN1_TYPE_CONSTRUCTED,
84
+ ASN1_SET = 17 | ASN1_TYPE_CONSTRUCTED,
85
+ ASN1_PRINTABLESTRING = 19,
86
+ ASN1_TELETEXSTRING = 20,
87
+ ASN1_IA5STRING = 22,
88
+ ASN1_UTC = 23,
89
+ ASN1_UNIVERSALSTRING = 28,
90
+ ASN1_BMPSTRING = 30,
91
+ };
92
+
93
+ enum asn1_iterator_result
94
+ {
95
+ ASN1_ITERATOR_ERROR,
96
+ ASN1_ITERATOR_PRIMITIVE,
97
+ ASN1_ITERATOR_CONSTRUCTED,
98
+ ASN1_ITERATOR_END,
99
+ };
100
+
101
+ /* Parsing DER objects. */
102
+ struct asn1_der_iterator
103
+ {
104
+ size_t buffer_length;
105
+ const uint8_t *buffer;
106
+
107
+ /* Next object to parse. */
108
+ size_t pos;
109
+
110
+ enum asn1_type type;
111
+
112
+ /* Pointer to the current object */
113
+ size_t length;
114
+ const uint8_t *data;
115
+ };
116
+
117
+ /* Initializes the iterator. */
118
+ enum asn1_iterator_result
119
+ asn1_der_iterator_first(struct asn1_der_iterator *iterator,
120
+ size_t length, const uint8_t *input);
121
+
122
+ enum asn1_iterator_result
123
+ asn1_der_iterator_next(struct asn1_der_iterator *iterator);
124
+
125
+ /* Starts parsing of a constructed object. */
126
+ enum asn1_iterator_result
127
+ asn1_der_decode_constructed(struct asn1_der_iterator *i,
128
+ struct asn1_der_iterator *contents);
129
+
130
+ /* For the common case that we have a sequence at the end of the
131
+ object. Checks that the current object is the final one, and then
132
+ reinitializes the iterator to parse its ontents. */
133
+ enum asn1_iterator_result
134
+ asn1_der_decode_constructed_last(struct asn1_der_iterator *i);
135
+
136
+ enum asn1_iterator_result
137
+ asn1_der_decode_bitstring(struct asn1_der_iterator *i,
138
+ struct asn1_der_iterator *contents);
139
+
140
+ enum asn1_iterator_result
141
+ asn1_der_decode_bitstring_last(struct asn1_der_iterator *i);
142
+
143
+ /* All these functions return 1 on success, 0 on failure */
144
+ int
145
+ asn1_der_get_uint32(struct asn1_der_iterator *i,
146
+ uint32_t *x);
147
+
148
+ #ifdef __cplusplus
149
+ }
150
+ #endif
151
+
152
+ #endif /* NETTLE_ASN1_H_INCLUDED */
include/nettle/base16.h ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* base16.h
2
+
3
+ Hex encoding and decoding, following spki conventions (i.e.
4
+ allowing whitespace between digits).
5
+
6
+ Copyright (C) 2002 Niels Möller
7
+
8
+ This file is part of GNU Nettle.
9
+
10
+ GNU Nettle is free software: you can redistribute it and/or
11
+ modify it under the terms of either:
12
+
13
+ * the GNU Lesser General Public License as published by the Free
14
+ Software Foundation; either version 3 of the License, or (at your
15
+ option) any later version.
16
+
17
+ or
18
+
19
+ * the GNU General Public License as published by the Free
20
+ Software Foundation; either version 2 of the License, or (at your
21
+ option) any later version.
22
+
23
+ or both in parallel, as here.
24
+
25
+ GNU Nettle is distributed in the hope that it will be useful,
26
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
+ General Public License for more details.
29
+
30
+ You should have received copies of the GNU General Public License and
31
+ the GNU Lesser General Public License along with this program. If
32
+ not, see http://www.gnu.org/licenses/.
33
+ */
34
+
35
+ #ifndef NETTLE_BASE16_H_INCLUDED
36
+ #define NETTLE_BASE16_H_INCLUDED
37
+
38
+ #include "nettle-types.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* Name mangling */
45
+ #define base16_encode_single nettle_base16_encode_single
46
+ #define base16_encode_update nettle_base16_encode_update
47
+ #define base16_decode_init nettle_base16_decode_init
48
+ #define base16_decode_single nettle_base16_decode_single
49
+ #define base16_decode_update nettle_base16_decode_update
50
+ #define base16_decode_final nettle_base16_decode_final
51
+
52
+ /* Base16 encoding */
53
+
54
+ /* Maximum length of output for base16_encode_update. */
55
+ #define BASE16_ENCODE_LENGTH(length) ((length) * 2)
56
+
57
+ /* Encodes a single byte. Always stores two digits in dst[0] and dst[1]. */
58
+ void
59
+ base16_encode_single(char *dst,
60
+ uint8_t src);
61
+
62
+ /* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */
63
+ void
64
+ base16_encode_update(char *dst,
65
+ size_t length,
66
+ const uint8_t *src);
67
+
68
+
69
+ /* Base16 decoding */
70
+
71
+ /* Maximum length of output for base16_decode_update. */
72
+ /* We have at most 4 buffered bits, and a total of (length + 1) * 4 bits. */
73
+ #define BASE16_DECODE_LENGTH(length) (((length) + 1) / 2)
74
+
75
+ struct base16_decode_ctx
76
+ {
77
+ unsigned char word; /* Leftover bits */
78
+ unsigned char bits; /* Number buffered bits */
79
+ };
80
+
81
+ void
82
+ base16_decode_init(struct base16_decode_ctx *ctx);
83
+
84
+ /* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
85
+ * errors. */
86
+ int
87
+ base16_decode_single(struct base16_decode_ctx *ctx,
88
+ uint8_t *dst,
89
+ char src);
90
+
91
+ /* Returns 1 on success, 0 on error. DST should point to an area of
92
+ * size at least BASE16_DECODE_LENGTH(length). The amount of data
93
+ * generated is returned in *DST_LENGTH. */
94
+
95
+ int
96
+ base16_decode_update(struct base16_decode_ctx *ctx,
97
+ size_t *dst_length,
98
+ uint8_t *dst,
99
+ size_t src_length,
100
+ const char *src);
101
+
102
+ /* Returns 1 on success. */
103
+ int
104
+ base16_decode_final(struct base16_decode_ctx *ctx);
105
+
106
+ #ifdef __cplusplus
107
+ }
108
+ #endif
109
+
110
+ #endif /* NETTLE_BASE16_H_INCLUDED */
include/nettle/base64.h ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* base64.h
2
+
3
+ Base-64 encoding and decoding.
4
+
5
+ Copyright (C) 2002 Niels Möller, Dan Egnor
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_BASE64_H_INCLUDED
35
+ #define NETTLE_BASE64_H_INCLUDED
36
+
37
+ #include "nettle-types.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /* Name mangling */
44
+ #define base64_encode_init nettle_base64_encode_init
45
+ #define base64url_encode_init nettle_base64url_encode_init
46
+ #define base64_encode_single nettle_base64_encode_single
47
+ #define base64_encode_update nettle_base64_encode_update
48
+ #define base64_encode_final nettle_base64_encode_final
49
+ #define base64_encode_raw nettle_base64_encode_raw
50
+ #define base64_encode_group nettle_base64_encode_group
51
+ #define base64_decode_init nettle_base64_decode_init
52
+ #define base64url_decode_init nettle_base64url_decode_init
53
+ #define base64_decode_single nettle_base64_decode_single
54
+ #define base64_decode_update nettle_base64_decode_update
55
+ #define base64_decode_final nettle_base64_decode_final
56
+
57
+ #define BASE64_BINARY_BLOCK_SIZE 3
58
+ #define BASE64_TEXT_BLOCK_SIZE 4
59
+
60
+ /* Base64 encoding */
61
+
62
+ /* Maximum length of output for base64_encode_update. NOTE: Doesn't
63
+ * include any padding that base64_encode_final may add. */
64
+ /* We have at most 4 buffered bits, and a total of (4 + length * 8) bits. */
65
+ #define BASE64_ENCODE_LENGTH(length) (((length) * 8 + 4)/6)
66
+
67
+ /* Maximum length of output generated by base64_encode_final. */
68
+ #define BASE64_ENCODE_FINAL_LENGTH 3
69
+
70
+ /* Exact length of output generated by base64_encode_raw, including
71
+ * padding. */
72
+ #define BASE64_ENCODE_RAW_LENGTH(length) ((((length) + 2)/3)*4)
73
+
74
+ struct base64_encode_ctx
75
+ {
76
+ const char *alphabet; /* Alphabet to use for encoding */
77
+ unsigned short word; /* Leftover bits */
78
+ unsigned char bits; /* Number of bits, always 0, 2, or 4. */
79
+ };
80
+
81
+ /* Initialize encoding context for base-64 */
82
+ void
83
+ base64_encode_init(struct base64_encode_ctx *ctx);
84
+
85
+ /* Initialize encoding context for URL safe alphabet, RFC 4648. */
86
+ void
87
+ base64url_encode_init(struct base64_encode_ctx *ctx);
88
+
89
+ /* Encodes a single byte. Returns amount of output (always 1 or 2). */
90
+ size_t
91
+ base64_encode_single(struct base64_encode_ctx *ctx,
92
+ char *dst,
93
+ uint8_t src);
94
+
95
+ /* Returns the number of output characters. DST should point to an
96
+ * area of size at least BASE64_ENCODE_LENGTH(length). */
97
+ size_t
98
+ base64_encode_update(struct base64_encode_ctx *ctx,
99
+ char *dst,
100
+ size_t length,
101
+ const uint8_t *src);
102
+
103
+ /* DST should point to an area of size at least
104
+ * BASE64_ENCODE_FINAL_LENGTH */
105
+ size_t
106
+ base64_encode_final(struct base64_encode_ctx *ctx,
107
+ char *dst);
108
+
109
+ /* Lower level functions */
110
+
111
+ /* Encodes a string in one go, including any padding at the end.
112
+ * Generates exactly BASE64_ENCODE_RAW_LENGTH(length) bytes of output.
113
+ * Supports overlapped operation, if src <= dst. FIXME: Use of overlap
114
+ * is deprecated, if needed there should be a separate public fucntion
115
+ * to do that.*/
116
+ void
117
+ base64_encode_raw(char *dst, size_t length, const uint8_t *src);
118
+
119
+ void
120
+ base64_encode_group(char *dst, uint32_t group);
121
+
122
+
123
+ /* Base64 decoding */
124
+
125
+ /* Maximum length of output for base64_decode_update. */
126
+ /* We have at most 6 buffered bits, and a total of (length + 1) * 6 bits. */
127
+ #define BASE64_DECODE_LENGTH(length) ((((length) + 1) * 6) / 8)
128
+
129
+ struct base64_decode_ctx
130
+ {
131
+ const signed char *table; /* Decoding table */
132
+ unsigned short word; /* Leftover bits */
133
+ unsigned char bits; /* Number buffered bits */
134
+
135
+ /* Number of padding characters encountered */
136
+ unsigned char padding;
137
+ };
138
+
139
+ /* Initialize decoding context for base-64 */
140
+ void
141
+ base64_decode_init(struct base64_decode_ctx *ctx);
142
+
143
+ /* Initialize encoding context for URL safe alphabet, RFC 4648. */
144
+ void
145
+ base64url_decode_init(struct base64_decode_ctx *ctx);
146
+
147
+ /* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
148
+ * errors. */
149
+ int
150
+ base64_decode_single(struct base64_decode_ctx *ctx,
151
+ uint8_t *dst,
152
+ char src);
153
+
154
+ /* Returns 1 on success, 0 on error. DST should point to an area of
155
+ * size at least BASE64_DECODE_LENGTH(length). The amount of data
156
+ * generated is returned in *DST_LENGTH. */
157
+ int
158
+ base64_decode_update(struct base64_decode_ctx *ctx,
159
+ size_t *dst_length,
160
+ uint8_t *dst,
161
+ size_t src_length,
162
+ const char *src);
163
+
164
+ /* Returns 1 on success. */
165
+ int
166
+ base64_decode_final(struct base64_decode_ctx *ctx);
167
+
168
+ #ifdef __cplusplus
169
+ }
170
+ #endif
171
+
172
+ #endif /* NETTLE_BASE64_H_INCLUDED */
include/nettle/bignum.h ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* bignum.h
2
+
3
+ Bignum operations that are missing from gmp.
4
+
5
+ Copyright (C) 2001 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_BIGNUM_H_INCLUDED
35
+ #define NETTLE_BIGNUM_H_INCLUDED
36
+
37
+ #include "nettle-types.h"
38
+
39
+ /* For NETTLE_USE_MINI_GMP */
40
+ #include "version.h"
41
+
42
+ #if NETTLE_USE_MINI_GMP
43
+ # include "mini-gmp.h"
44
+
45
+ # define GMP_NUMB_MASK (~(mp_limb_t) 0)
46
+
47
+ /* Side-channel silent powm not available in mini-gmp. */
48
+ # define mpz_powm_sec mpz_powm
49
+ #else
50
+ # include <gmp.h>
51
+ #endif
52
+
53
+ #ifdef __cplusplus
54
+ extern "C" {
55
+ #endif
56
+
57
+ /* Size needed for signed encoding, including extra sign byte if
58
+ * necessary. */
59
+ size_t
60
+ nettle_mpz_sizeinbase_256_s(const mpz_t x);
61
+
62
+ /* Size needed for unsigned encoding */
63
+ size_t
64
+ nettle_mpz_sizeinbase_256_u(const mpz_t x);
65
+
66
+ /* Writes an integer as length octets, using big endian byte order,
67
+ * and two's complement for negative numbers. */
68
+ void
69
+ nettle_mpz_get_str_256(size_t length, uint8_t *s, const mpz_t x);
70
+
71
+ /* Reads a big endian, two's complement, integer. */
72
+ void
73
+ nettle_mpz_set_str_256_s(mpz_t x,
74
+ size_t length, const uint8_t *s);
75
+
76
+ void
77
+ nettle_mpz_init_set_str_256_s(mpz_t x,
78
+ size_t length, const uint8_t *s);
79
+
80
+ /* Similar, but for unsigned format. These function don't interpret
81
+ * the most significant bit as the sign. */
82
+ void
83
+ nettle_mpz_set_str_256_u(mpz_t x,
84
+ size_t length, const uint8_t *s);
85
+
86
+ void
87
+ nettle_mpz_init_set_str_256_u(mpz_t x,
88
+ size_t length, const uint8_t *s);
89
+
90
+ /* Returns a uniformly distributed random number 0 <= x < 2^n */
91
+ void
92
+ nettle_mpz_random_size(mpz_t x,
93
+ void *ctx, nettle_random_func *random,
94
+ unsigned bits);
95
+
96
+ /* Returns a number x, almost uniformly random in the range
97
+ * 0 <= x < n. */
98
+ void
99
+ nettle_mpz_random(mpz_t x,
100
+ void *ctx, nettle_random_func *random,
101
+ const mpz_t n);
102
+
103
+ void
104
+ nettle_random_prime(mpz_t p, unsigned bits, int top_bits_set,
105
+ void *ctx, nettle_random_func *random,
106
+ void *progress_ctx, nettle_progress_func *progress);
107
+
108
+
109
+ /* sexp parsing */
110
+ struct sexp_iterator;
111
+
112
+ /* If LIMIT is non-zero, the number must be at most LIMIT bits.
113
+ * Implies sexp_iterator_next. */
114
+ int
115
+ nettle_mpz_set_sexp(mpz_t x, unsigned limit, struct sexp_iterator *i);
116
+
117
+
118
+ /* der parsing */
119
+ struct asn1_der_iterator;
120
+
121
+ int
122
+ nettle_asn1_der_get_bignum(struct asn1_der_iterator *iterator,
123
+ mpz_t x, unsigned max_bits);
124
+
125
+ #ifdef __cplusplus
126
+ }
127
+ #endif
128
+
129
+ #endif /* NETTLE_BIGNUM_H_INCLUDED */
include/nettle/blowfish.h ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* blowfish.h
2
+
3
+ Blowfish block cipher.
4
+
5
+ Copyright (C) 2014 Niels Möller
6
+ Copyright (C) 1998, 2001 FSF, Ray Dassen, Niels Möller
7
+
8
+ This file is part of GNU Nettle.
9
+
10
+ GNU Nettle is free software: you can redistribute it and/or
11
+ modify it under the terms of either:
12
+
13
+ * the GNU Lesser General Public License as published by the Free
14
+ Software Foundation; either version 3 of the License, or (at your
15
+ option) any later version.
16
+
17
+ or
18
+
19
+ * the GNU General Public License as published by the Free
20
+ Software Foundation; either version 2 of the License, or (at your
21
+ option) any later version.
22
+
23
+ or both in parallel, as here.
24
+
25
+ GNU Nettle is distributed in the hope that it will be useful,
26
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
+ General Public License for more details.
29
+
30
+ You should have received copies of the GNU General Public License and
31
+ the GNU Lesser General Public License along with this program. If
32
+ not, see http://www.gnu.org/licenses/.
33
+ */
34
+
35
+ #ifndef NETTLE_BLOWFISH_H_INCLUDED
36
+ #define NETTLE_BLOWFISH_H_INCLUDED
37
+
38
+ #include "nettle-types.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* Name mangling */
45
+ #define blowfish_set_key nettle_blowfish_set_key
46
+ #define blowfish128_set_key nettle_blowfish128_set_key
47
+ #define blowfish_encrypt nettle_blowfish_encrypt
48
+ #define blowfish_decrypt nettle_blowfish_decrypt
49
+ #define blowfish_bcrypt_hash nettle_blowfish_bcrypt_hash
50
+ #define blowfish_bcrypt_verify nettle_blowfish_bcrypt_verify
51
+
52
+ #define BLOWFISH_BLOCK_SIZE 8
53
+
54
+ /* Variable key size between 64 and 448 bits. */
55
+ #define BLOWFISH_MIN_KEY_SIZE 8
56
+ #define BLOWFISH_MAX_KEY_SIZE 56
57
+
58
+ /* Default to 128 bits */
59
+ #define BLOWFISH_KEY_SIZE 16
60
+
61
+ #define BLOWFISH128_KEY_SIZE 16
62
+
63
+ #define _BLOWFISH_ROUNDS 16
64
+
65
+ #define BLOWFISH_BCRYPT_HASH_SIZE (60 + 1) /* Including null-terminator */
66
+ #define BLOWFISH_BCRYPT_BINSALT_SIZE 16 /* Binary string size */
67
+
68
+ struct blowfish_ctx
69
+ {
70
+ uint32_t s[4][256];
71
+ uint32_t p[_BLOWFISH_ROUNDS+2];
72
+ };
73
+
74
+ /* Returns 0 for weak keys, otherwise 1. */
75
+ int
76
+ blowfish_set_key(struct blowfish_ctx *ctx,
77
+ size_t length, const uint8_t *key);
78
+ int
79
+ blowfish128_set_key(struct blowfish_ctx *ctx, const uint8_t *key);
80
+
81
+ void
82
+ blowfish_encrypt(const struct blowfish_ctx *ctx,
83
+ size_t length, uint8_t *dst,
84
+ const uint8_t *src);
85
+ void
86
+ blowfish_decrypt(const struct blowfish_ctx *ctx,
87
+ size_t length, uint8_t *dst,
88
+ const uint8_t *src);
89
+
90
+ /* dst parameter must point to a buffer of minimally
91
+ * BLOWFISH_BCRYPT_HASH_SIZE bytes */
92
+ int
93
+ blowfish_bcrypt_hash(uint8_t *dst,
94
+ size_t lenkey, const uint8_t *key,
95
+ size_t lenscheme, const uint8_t *scheme,
96
+ int log2rounds,
97
+ const uint8_t *salt);
98
+ int
99
+ blowfish_bcrypt_verify(size_t lenkey, const uint8_t *key,
100
+ size_t lenhashed, const uint8_t *hashed);
101
+
102
+ #ifdef __cplusplus
103
+ }
104
+ #endif
105
+
106
+ #endif /* NETTLE_BLOWFISH_H_INCLUDED */
include/nettle/buffer.h ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* buffer.h
2
+
3
+ A bare-bones string stream.
4
+
5
+ Copyright (C) 2002 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_BUFFER_H_INCLUDED
35
+ #define NETTLE_BUFFER_H_INCLUDED
36
+
37
+ #include "realloc.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ struct nettle_buffer
44
+ {
45
+ uint8_t *contents;
46
+ /* Allocated size */
47
+ size_t alloc;
48
+
49
+ void *realloc_ctx;
50
+ nettle_realloc_func *realloc;
51
+
52
+ /* Current size */
53
+ size_t size;
54
+ };
55
+
56
+ /* Initializes a buffer that uses plain realloc */
57
+ void
58
+ nettle_buffer_init(struct nettle_buffer *buffer);
59
+
60
+ void
61
+ nettle_buffer_init_realloc(struct nettle_buffer *buffer,
62
+ void *realloc_ctx,
63
+ nettle_realloc_func *realloc);
64
+
65
+ /* Initializes a buffer of fix size */
66
+ void
67
+ nettle_buffer_init_size(struct nettle_buffer *buffer,
68
+ size_t length, uint8_t *space);
69
+
70
+ void
71
+ nettle_buffer_clear(struct nettle_buffer *buffer);
72
+
73
+ /* Resets the buffer, without freeing the buffer space. */
74
+ void
75
+ nettle_buffer_reset(struct nettle_buffer *buffer);
76
+
77
+ int
78
+ nettle_buffer_grow(struct nettle_buffer *buffer,
79
+ size_t length);
80
+
81
+ #define NETTLE_BUFFER_PUTC(buffer, c) \
82
+ ( (((buffer)->size < (buffer)->alloc) || nettle_buffer_grow((buffer), 1)) \
83
+ && ((buffer)->contents[(buffer)->size++] = (c), 1) )
84
+
85
+ int
86
+ nettle_buffer_write(struct nettle_buffer *buffer,
87
+ size_t length, const uint8_t *data);
88
+
89
+ /* Like nettle_buffer_write, but instead of copying data to the
90
+ * buffer, it returns a pointer to the area where the caller can copy
91
+ * the data. The pointer is valid only until the next call that can
92
+ * reallocate the buffer. */
93
+ uint8_t *
94
+ nettle_buffer_space(struct nettle_buffer *buffer,
95
+ size_t length);
96
+
97
+ /* Copy the contents of SRC to the end of DST. */
98
+ int
99
+ nettle_buffer_copy(struct nettle_buffer *dst,
100
+ const struct nettle_buffer *src);
101
+
102
+ #ifdef __cplusplus
103
+ }
104
+ #endif
105
+
106
+ #endif /* NETTLE_BUFFER_H_INCLUDED */
include/nettle/camellia.h ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* camellia.h
2
+
3
+ Copyright (C) 2006,2007 NTT
4
+ (Nippon Telegraph and Telephone Corporation).
5
+
6
+ Copyright (C) 2010, 2013 Niels Möller
7
+
8
+ This file is part of GNU Nettle.
9
+
10
+ GNU Nettle is free software: you can redistribute it and/or
11
+ modify it under the terms of either:
12
+
13
+ * the GNU Lesser General Public License as published by the Free
14
+ Software Foundation; either version 3 of the License, or (at your
15
+ option) any later version.
16
+
17
+ or
18
+
19
+ * the GNU General Public License as published by the Free
20
+ Software Foundation; either version 2 of the License, or (at your
21
+ option) any later version.
22
+
23
+ or both in parallel, as here.
24
+
25
+ GNU Nettle is distributed in the hope that it will be useful,
26
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
+ General Public License for more details.
29
+
30
+ You should have received copies of the GNU General Public License and
31
+ the GNU Lesser General Public License along with this program. If
32
+ not, see http://www.gnu.org/licenses/.
33
+ */
34
+
35
+ #ifndef NETTLE_CAMELLIA_H_INCLUDED
36
+ #define NETTLE_CAMELLIA_H_INCLUDED
37
+
38
+ #include "nettle-types.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* Name mangling */
45
+ #define camellia128_set_encrypt_key nettle_camellia128_set_encrypt_key
46
+ #define camellia128_set_decrypt_key nettle_camellia_set_decrypt_key
47
+ #define camellia128_invert_key nettle_camellia128_invert_key
48
+ #define camellia128_crypt nettle_camellia128_crypt
49
+
50
+ #define camellia192_set_encrypt_key nettle_camellia192_set_encrypt_key
51
+ #define camellia192_set_decrypt_key nettle_camellia192_set_decrypt_key
52
+
53
+ #define camellia256_set_encrypt_key nettle_camellia256_set_encrypt_key
54
+ #define camellia256_set_decrypt_key nettle_camellia256_set_decrypt_key
55
+ #define camellia256_invert_key nettle_camellia256_invert_key
56
+ #define camellia256_crypt nettle_camellia256_crypt
57
+
58
+
59
+ #define CAMELLIA_BLOCK_SIZE 16
60
+ /* Valid key sizes are 128, 192 or 256 bits (16, 24 or 32 bytes) */
61
+ #define CAMELLIA128_KEY_SIZE 16
62
+ #define CAMELLIA192_KEY_SIZE 24
63
+ #define CAMELLIA256_KEY_SIZE 32
64
+
65
+ /* For 128-bit keys, there are 18 regular rounds, pre- and
66
+ post-whitening, and two FL and FLINV rounds, using a total of 26
67
+ subkeys, each of 64 bit. For 192- and 256-bit keys, there are 6
68
+ additional regular rounds and one additional FL and FLINV, using a
69
+ total of 34 subkeys. */
70
+ /* The clever combination of subkeys imply one of the pre- and
71
+ post-whitening keys is folded with the round keys, so that subkey
72
+ #1 and the last one (#25 or #33) is not used. The result is that we
73
+ have only 24 or 32 subkeys at the end of key setup. */
74
+
75
+ #define _CAMELLIA128_NKEYS 24
76
+ #define _CAMELLIA256_NKEYS 32
77
+
78
+ struct camellia128_ctx
79
+ {
80
+ uint64_t keys[_CAMELLIA128_NKEYS];
81
+ };
82
+
83
+ void
84
+ camellia128_set_encrypt_key(struct camellia128_ctx *ctx,
85
+ const uint8_t *key);
86
+
87
+ void
88
+ camellia128_set_decrypt_key(struct camellia128_ctx *ctx,
89
+ const uint8_t *key);
90
+
91
+ void
92
+ camellia128_invert_key(struct camellia128_ctx *dst,
93
+ const struct camellia128_ctx *src);
94
+
95
+ void
96
+ camellia128_crypt(const struct camellia128_ctx *ctx,
97
+ size_t length, uint8_t *dst,
98
+ const uint8_t *src);
99
+
100
+ struct camellia256_ctx
101
+ {
102
+ uint64_t keys[_CAMELLIA256_NKEYS];
103
+ };
104
+
105
+ void
106
+ camellia256_set_encrypt_key(struct camellia256_ctx *ctx,
107
+ const uint8_t *key);
108
+
109
+ void
110
+ camellia256_set_decrypt_key(struct camellia256_ctx *ctx,
111
+ const uint8_t *key);
112
+
113
+ void
114
+ camellia256_invert_key(struct camellia256_ctx *dst,
115
+ const struct camellia256_ctx *src);
116
+
117
+ void
118
+ camellia256_crypt(const struct camellia256_ctx *ctx,
119
+ size_t length, uint8_t *dst,
120
+ const uint8_t *src);
121
+
122
+ /* camellia192 is the same as camellia256, except for the key
123
+ schedule. */
124
+ /* Slightly ugly with a #define on a struct tag, since it might cause
125
+ surprises if also used as a name of a variable. */
126
+ #define camellia192_ctx camellia256_ctx
127
+
128
+ void
129
+ camellia192_set_encrypt_key(struct camellia256_ctx *ctx,
130
+ const uint8_t *key);
131
+
132
+ void
133
+ camellia192_set_decrypt_key(struct camellia256_ctx *ctx,
134
+ const uint8_t *key);
135
+
136
+ #define camellia192_invert_key camellia256_invert_key
137
+ #define camellia192_crypt camellia256_crypt
138
+
139
+ #ifdef __cplusplus
140
+ }
141
+ #endif
142
+
143
+ #endif /* NETTLE_CAMELLIA_H_INCLUDED */
include/nettle/cast128.h ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* cast128.h
2
+
3
+ The CAST-128 block cipher.
4
+
5
+ Copyright (C) 2001, 2014 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_CAST128_H_INCLUDED
35
+ #define NETTLE_CAST128_H_INCLUDED
36
+
37
+ #include "nettle-types.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /* Name mangling */
44
+ #define cast5_set_key nettle_cast5_set_key
45
+ #define cast128_set_key nettle_cast128_set_key
46
+ #define cast128_encrypt nettle_cast128_encrypt
47
+ #define cast128_decrypt nettle_cast128_decrypt
48
+
49
+ #define CAST128_BLOCK_SIZE 8
50
+
51
+ /* Variable key size between 40 and 128. */
52
+ #define CAST5_MIN_KEY_SIZE 5
53
+ #define CAST5_MAX_KEY_SIZE 16
54
+
55
+ #define CAST128_KEY_SIZE 16
56
+
57
+ struct cast128_ctx
58
+ {
59
+ unsigned rounds; /* Number of rounds to use, 12 or 16 */
60
+ /* Expanded key, rotations (5 bits only) and 32-bit masks. */
61
+ unsigned char Kr[16];
62
+ uint32_t Km[16];
63
+ };
64
+
65
+ /* Using variable key size. */
66
+ void
67
+ cast5_set_key(struct cast128_ctx *ctx,
68
+ size_t length, const uint8_t *key);
69
+
70
+ void
71
+ cast128_set_key(struct cast128_ctx *ctx, const uint8_t *key);
72
+
73
+ void
74
+ cast128_encrypt(const struct cast128_ctx *ctx,
75
+ size_t length, uint8_t *dst,
76
+ const uint8_t *src);
77
+ void
78
+ cast128_decrypt(const struct cast128_ctx *ctx,
79
+ size_t length, uint8_t *dst,
80
+ const uint8_t *src);
81
+
82
+ #ifdef __cplusplus
83
+ }
84
+ #endif
85
+
86
+ #endif /* NETTLE_CAST128_H_INCLUDED */
include/nettle/cbc.h ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* cbc.h
2
+
3
+ Cipher block chaining mode.
4
+
5
+ Copyright (C) 2001 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_CBC_H_INCLUDED
35
+ #define NETTLE_CBC_H_INCLUDED
36
+
37
+ #include "nettle-types.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /* Name mangling */
44
+ #define cbc_encrypt nettle_cbc_encrypt
45
+ #define cbc_decrypt nettle_cbc_decrypt
46
+
47
+ void
48
+ cbc_encrypt(const void *ctx, nettle_cipher_func *f,
49
+ size_t block_size, uint8_t *iv,
50
+ size_t length, uint8_t *dst,
51
+ const uint8_t *src);
52
+
53
+ void
54
+ cbc_decrypt(const void *ctx, nettle_cipher_func *f,
55
+ size_t block_size, uint8_t *iv,
56
+ size_t length, uint8_t *dst,
57
+ const uint8_t *src);
58
+
59
+ #define CBC_CTX(type, size) \
60
+ { type ctx; uint8_t iv[size]; }
61
+
62
+ #define CBC_SET_IV(ctx, data) \
63
+ memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
64
+
65
+ /* NOTE: Avoid using NULL, as we don't include anything defining it. */
66
+ #define CBC_ENCRYPT(self, f, length, dst, src) \
67
+ (0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
68
+ (uint8_t *) 0, (const uint8_t *) 0)) \
69
+ : cbc_encrypt((void *) &(self)->ctx, \
70
+ (nettle_cipher_func *) (f), \
71
+ sizeof((self)->iv), (self)->iv, \
72
+ (length), (dst), (src)))
73
+
74
+ #define CBC_DECRYPT(self, f, length, dst, src) \
75
+ (0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
76
+ (uint8_t *) 0, (const uint8_t *) 0)) \
77
+ : cbc_decrypt((void *) &(self)->ctx, \
78
+ (nettle_cipher_func *) (f), \
79
+ sizeof((self)->iv), (self)->iv, \
80
+ (length), (dst), (src)))
81
+
82
+ #ifdef __cplusplus
83
+ }
84
+ #endif
85
+
86
+ #endif /* NETTLE_CBC_H_INCLUDED */
include/nettle/ccm.h ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* ccm.h
2
+
3
+ Counter with CBC-MAC mode, specified by NIST,
4
+ http://csrc.nist.gov/publications/nistpubs/800-38C/SP800-38C_updated-July20_2007.pdf
5
+
6
+ Copyright (C) 2014 Exegin Technologies Limited
7
+ Copyright (C) 2014 Owen Kirby
8
+
9
+ Contributed to GNU Nettle by Owen Kirby
10
+
11
+ This file is part of GNU Nettle.
12
+
13
+ GNU Nettle is free software: you can redistribute it and/or
14
+ modify it under the terms of either:
15
+
16
+ * the GNU Lesser General Public License as published by the Free
17
+ Software Foundation; either version 3 of the License, or (at your
18
+ option) any later version.
19
+
20
+ or
21
+
22
+ * the GNU General Public License as published by the Free
23
+ Software Foundation; either version 2 of the License, or (at your
24
+ option) any later version.
25
+
26
+ or both in parallel, as here.
27
+
28
+ GNU Nettle is distributed in the hope that it will be useful,
29
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
30
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31
+ General Public License for more details.
32
+
33
+ You should have received copies of the GNU General Public License and
34
+ the GNU Lesser General Public License along with this program. If
35
+ not, see http://www.gnu.org/licenses/.
36
+ */
37
+
38
+ /* NIST SP800-38C doesn't specify the particular formatting and
39
+ * counter generation algorithm for CCM, but it does include an
40
+ * example algorithm. This example has become the de-factor standard,
41
+ * and has been adopted by both the IETF and IEEE across a wide
42
+ * variety of protocols.
43
+ */
44
+
45
+ #ifndef NETTLE_CCM_H_INCLUDED
46
+ #define NETTLE_CCM_H_INCLUDED
47
+
48
+ #include "aes.h"
49
+
50
+ #ifdef __cplusplus
51
+ extern "C" {
52
+ #endif
53
+
54
+ /* Name mangling */
55
+ #define ccm_set_nonce nettle_ccm_set_nonce
56
+ #define ccm_update nettle_ccm_update
57
+ #define ccm_encrypt nettle_ccm_encrypt
58
+ #define ccm_decrypt nettle_ccm_decrypt
59
+ #define ccm_digest nettle_ccm_digest
60
+ #define ccm_encrypt_message nettle_ccm_encrypt_message
61
+ #define ccm_decrypt_message nettle_ccm_decrypt_message
62
+
63
+ #define ccm_aes128_set_key nettle_ccm_aes128_set_key
64
+ #define ccm_aes128_set_nonce nettle_ccm_aes128_set_nonce
65
+ #define ccm_aes128_update nettle_ccm_aes128_update
66
+ #define ccm_aes128_encrypt nettle_ccm_aes128_encrypt
67
+ #define ccm_aes128_decrypt nettle_ccm_aes128_decrypt
68
+ #define ccm_aes128_digest nettle_ccm_aes128_digest
69
+ #define ccm_aes128_encrypt_message nettle_ccm_aes128_encrypt_message
70
+ #define ccm_aes128_decrypt_message nettle_ccm_aes128_decrypt_message
71
+
72
+ #define ccm_aes192_set_key nettle_ccm_aes192_set_key
73
+ #define ccm_aes192_set_nonce nettle_ccm_aes192_set_nonce
74
+ #define ccm_aes192_update nettle_ccm_aes192_update
75
+ #define ccm_aes192_encrypt nettle_ccm_aes192_encrypt
76
+ #define ccm_aes192_decrypt nettle_ccm_aes192_decrypt
77
+ #define ccm_aes192_digest nettle_ccm_aes192_digest
78
+ #define ccm_aes192_encrypt_message nettle_ccm_aes192_encrypt_message
79
+ #define ccm_aes192_decrypt_message nettle_ccm_aes192_decrypt_message
80
+
81
+ #define ccm_aes256_set_key nettle_ccm_aes256_set_key
82
+ #define ccm_aes256_set_nonce nettle_ccm_aes256_set_nonce
83
+ #define ccm_aes256_update nettle_ccm_aes256_update
84
+ #define ccm_aes256_encrypt nettle_ccm_aes256_encrypt
85
+ #define ccm_aes256_decrypt nettle_ccm_aes256_decrypt
86
+ #define ccm_aes256_digest nettle_ccm_aes256_digest
87
+ #define ccm_aes256_encrypt_message nettle_ccm_aes256_encrypt_message
88
+ #define ccm_aes256_decrypt_message nettle_ccm_aes256_decrypt_message
89
+
90
+ /* For CCM, the block size of the block cipher shall be 128 bits. */
91
+ #define CCM_BLOCK_SIZE 16
92
+ #define CCM_DIGEST_SIZE 16
93
+ #define CCM_MIN_NONCE_SIZE 7
94
+ #define CCM_MAX_NONCE_SIZE 14
95
+
96
+ /* Maximum cleartext message size, as a function of the nonce size N.
97
+ The length field is L octets, with L = 15 - N, and then the maximum
98
+ size M = 2^{8L} - 1. */
99
+ #define CCM_MAX_MSG_SIZE(N) \
100
+ ((sizeof(size_t) + (N) <= 15) \
101
+ ? ~(size_t) 0 \
102
+ : ((size_t) 1 << (8*(15 - N))) - 1)
103
+
104
+ /* Per-message state */
105
+ struct ccm_ctx {
106
+ union nettle_block16 ctr; /* Counter for CTR encryption. */
107
+ union nettle_block16 tag; /* CBC-MAC message tag. */
108
+ /* Length of data processed by the CBC-MAC modulus the block size */
109
+ unsigned int blength;
110
+ };
111
+
112
+ /*
113
+ * CCM mode requires the adata and message lengths when building the IV, which
114
+ * prevents streaming processing and it incompatible with the AEAD API.
115
+ */
116
+ void
117
+ ccm_set_nonce(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
118
+ size_t noncelen, const uint8_t *nonce,
119
+ size_t authlen, size_t msglen, size_t taglen);
120
+
121
+ void
122
+ ccm_update(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
123
+ size_t length, const uint8_t *data);
124
+
125
+ void
126
+ ccm_encrypt(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
127
+ size_t length, uint8_t *dst, const uint8_t *src);
128
+
129
+ void
130
+ ccm_decrypt(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
131
+ size_t length, uint8_t *dst, const uint8_t *src);
132
+
133
+ void
134
+ ccm_digest(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
135
+ size_t length, uint8_t *digest);
136
+
137
+ /*
138
+ * All-in-one encryption and decryption API:
139
+ * tlength = sizeof(digest)
140
+ * mlength = sizeof(cleartext)
141
+ * clength = sizeof(ciphertext) = mlength + tlength
142
+ *
143
+ * The ciphertext will contain the encrypted payload with the message digest
144
+ * appended to the end.
145
+ */
146
+ void
147
+ ccm_encrypt_message(const void *cipher, nettle_cipher_func *f,
148
+ size_t nlength, const uint8_t *nonce,
149
+ size_t alength, const uint8_t *adata,
150
+ size_t tlength,
151
+ size_t clength, uint8_t *dst, const uint8_t *src);
152
+
153
+ /*
154
+ * The decryption function will write the plaintext to dst and parse the digest
155
+ * from the final tlength bytes of the ciphertext. If the digest matched the
156
+ * value computed during decryption then this will return 1, or it will return
157
+ * 0 if the digest was invalid.
158
+ */
159
+ int
160
+ ccm_decrypt_message(const void *cipher, nettle_cipher_func *f,
161
+ size_t nlength, const uint8_t *nonce,
162
+ size_t alength, const uint8_t *adata,
163
+ size_t tlength,
164
+ size_t mlength, uint8_t *dst, const uint8_t *src);
165
+
166
+ /* CCM Mode with AES-128 */
167
+ struct ccm_aes128_ctx {
168
+ struct ccm_ctx ccm;
169
+ struct aes128_ctx cipher;
170
+ };
171
+
172
+ void
173
+ ccm_aes128_set_key(struct ccm_aes128_ctx *ctx, const uint8_t *key);
174
+
175
+ void
176
+ ccm_aes128_set_nonce(struct ccm_aes128_ctx *ctx,
177
+ size_t length, const uint8_t *nonce,
178
+ size_t authlen, size_t msglen, size_t taglen);
179
+
180
+ void
181
+ ccm_aes128_update (struct ccm_aes128_ctx *ctx,
182
+ size_t length, const uint8_t *data);
183
+
184
+ void
185
+ ccm_aes128_encrypt(struct ccm_aes128_ctx *ctx,
186
+ size_t length, uint8_t *dst, const uint8_t *src);
187
+
188
+ void
189
+ ccm_aes128_decrypt(struct ccm_aes128_ctx *ctx,
190
+ size_t length, uint8_t *dst, const uint8_t *src);
191
+
192
+ void
193
+ ccm_aes128_digest(struct ccm_aes128_ctx *ctx,
194
+ size_t length, uint8_t *digest);
195
+
196
+ void
197
+ ccm_aes128_encrypt_message(struct ccm_aes128_ctx *ctx,
198
+ size_t nlength, const uint8_t *nonce,
199
+ size_t alength, const uint8_t *adata,
200
+ size_t tlength,
201
+ size_t clength, uint8_t *dst, const uint8_t *src);
202
+
203
+ int
204
+ ccm_aes128_decrypt_message(struct ccm_aes128_ctx *ctx,
205
+ size_t nlength, const uint8_t *nonce,
206
+ size_t alength, const uint8_t *adata,
207
+ size_t tlength,
208
+ size_t mlength, uint8_t *dst, const uint8_t *src);
209
+
210
+ struct ccm_aes192_ctx {
211
+ struct ccm_ctx ccm;
212
+ struct aes192_ctx cipher;
213
+ };
214
+
215
+ /* CCM Mode with AES-192 */
216
+ void
217
+ ccm_aes192_set_key(struct ccm_aes192_ctx *ctx, const uint8_t *key);
218
+
219
+ void
220
+ ccm_aes192_set_nonce(struct ccm_aes192_ctx *ctx,
221
+ size_t length, const uint8_t *nonce,
222
+ size_t authlen, size_t msglen, size_t taglen);
223
+
224
+ void
225
+ ccm_aes192_update(struct ccm_aes192_ctx *ctx,
226
+ size_t length, const uint8_t *data);
227
+
228
+ void
229
+ ccm_aes192_encrypt(struct ccm_aes192_ctx *ctx,
230
+ size_t length, uint8_t *dst, const uint8_t *src);
231
+
232
+ void
233
+ ccm_aes192_decrypt(struct ccm_aes192_ctx *ctx,
234
+ size_t length, uint8_t *dst, const uint8_t *src);
235
+
236
+ void
237
+ ccm_aes192_digest(struct ccm_aes192_ctx *ctx,
238
+ size_t length, uint8_t *digest);
239
+
240
+ void
241
+ ccm_aes192_encrypt_message(struct ccm_aes192_ctx *ctx,
242
+ size_t nlength, const uint8_t *nonce,
243
+ size_t alength, const uint8_t *adata,
244
+ size_t tlength,
245
+ size_t clength, uint8_t *dst, const uint8_t *src);
246
+
247
+ int
248
+ ccm_aes192_decrypt_message(struct ccm_aes192_ctx *ctx,
249
+ size_t nlength, const uint8_t *nonce,
250
+ size_t alength, const uint8_t *adata,
251
+ size_t tlength,
252
+ size_t mlength, uint8_t *dst, const uint8_t *src);
253
+
254
+ /* CCM Mode with AES-256 */
255
+ struct ccm_aes256_ctx {
256
+ struct ccm_ctx ccm;
257
+ struct aes256_ctx cipher;
258
+ };
259
+
260
+ void
261
+ ccm_aes256_set_key(struct ccm_aes256_ctx *ctx, const uint8_t *key);
262
+
263
+ void
264
+ ccm_aes256_set_nonce(struct ccm_aes256_ctx *ctx,
265
+ size_t length, const uint8_t *nonce,
266
+ size_t authlen, size_t msglen, size_t taglen);
267
+
268
+ void
269
+ ccm_aes256_update(struct ccm_aes256_ctx *ctx,
270
+ size_t length, const uint8_t *data);
271
+
272
+ void
273
+ ccm_aes256_encrypt(struct ccm_aes256_ctx *ctx,
274
+ size_t length, uint8_t *dst, const uint8_t *src);
275
+
276
+ void
277
+ ccm_aes256_decrypt(struct ccm_aes256_ctx *ctx,
278
+ size_t length, uint8_t *dst, const uint8_t *src);
279
+
280
+ void
281
+ ccm_aes256_digest(struct ccm_aes256_ctx *ctx,
282
+ size_t length, uint8_t *digest);
283
+
284
+ void
285
+ ccm_aes256_encrypt_message(struct ccm_aes256_ctx *ctx,
286
+ size_t nlength, const uint8_t *nonce,
287
+ size_t alength, const uint8_t *adata,
288
+ size_t tlength,
289
+ size_t clength, uint8_t *dst, const uint8_t *src);
290
+
291
+ int
292
+ ccm_aes256_decrypt_message(struct ccm_aes256_ctx *ctx,
293
+ size_t nlength, const uint8_t *nonce,
294
+ size_t alength, const uint8_t *adata,
295
+ size_t tlength,
296
+ size_t mlength, uint8_t *dst, const uint8_t *src);
297
+
298
+ #ifdef __cplusplus
299
+ }
300
+ #endif
301
+
302
+ #endif /* NETTLE_CCM_H_INCLUDED */
include/nettle/cfb.h ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* cfb.h
2
+
3
+ Cipher feedback mode.
4
+
5
+ Copyright (C) 2015, 2017 Dmitry Eremin-Solenikov
6
+ Copyright (C) 2001 Niels Möller
7
+
8
+ This file is part of GNU Nettle.
9
+
10
+ GNU Nettle is free software: you can redistribute it and/or
11
+ modify it under the terms of either:
12
+
13
+ * the GNU Lesser General Public License as published by the Free
14
+ Software Foundation; either version 3 of the License, or (at your
15
+ option) any later version.
16
+
17
+ or
18
+
19
+ * the GNU General Public License as published by the Free
20
+ Software Foundation; either version 2 of the License, or (at your
21
+ option) any later version.
22
+
23
+ or both in parallel, as here.
24
+
25
+ GNU Nettle is distributed in the hope that it will be useful,
26
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
+ General Public License for more details.
29
+
30
+ You should have received copies of the GNU General Public License and
31
+ the GNU Lesser General Public License along with this program. If
32
+ not, see http://www.gnu.org/licenses/.
33
+ */
34
+
35
+ #ifndef NETTLE_CFB_H_INCLUDED
36
+ #define NETTLE_CFB_H_INCLUDED
37
+
38
+ #include "nettle-types.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* Name mangling */
45
+ #define cfb_encrypt nettle_cfb_encrypt
46
+ #define cfb_decrypt nettle_cfb_decrypt
47
+
48
+ #define cfb8_encrypt nettle_cfb8_encrypt
49
+ #define cfb8_decrypt nettle_cfb8_decrypt
50
+
51
+ void
52
+ cfb_encrypt(const void *ctx, nettle_cipher_func *f,
53
+ size_t block_size, uint8_t *iv,
54
+ size_t length, uint8_t *dst,
55
+ const uint8_t *src);
56
+
57
+ void
58
+ cfb_decrypt(const void *ctx, nettle_cipher_func *f,
59
+ size_t block_size, uint8_t *iv,
60
+ size_t length, uint8_t *dst,
61
+ const uint8_t *src);
62
+
63
+ void
64
+ cfb8_encrypt(const void *ctx, nettle_cipher_func *f,
65
+ size_t block_size, uint8_t *iv,
66
+ size_t length, uint8_t *dst,
67
+ const uint8_t *src);
68
+
69
+ void
70
+ cfb8_decrypt(const void *ctx, nettle_cipher_func *f,
71
+ size_t block_size, uint8_t *iv,
72
+ size_t length, uint8_t *dst,
73
+ const uint8_t *src);
74
+
75
+
76
+ #define CFB_CTX(type, size) \
77
+ { type ctx; uint8_t iv[size]; }
78
+
79
+ #define CFB_SET_IV(ctx, data) \
80
+ memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
81
+
82
+ #define CFB8_CTX CFB_CTX
83
+ #define CFB8_SET_IV CFB_SET_IV
84
+
85
+ /* NOTE: Avoid using NULL, as we don't include anything defining it. */
86
+ #define CFB_ENCRYPT(self, f, length, dst, src) \
87
+ (0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
88
+ (uint8_t *) 0, (const uint8_t *) 0)) \
89
+ : cfb_encrypt((void *) &(self)->ctx, \
90
+ (nettle_cipher_func *) (f), \
91
+ sizeof((self)->iv), (self)->iv, \
92
+ (length), (dst), (src)))
93
+
94
+ #define CFB_DECRYPT(self, f, length, dst, src) \
95
+ (0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
96
+ (uint8_t *) 0, (const uint8_t *) 0)) \
97
+ : cfb_decrypt((void *) &(self)->ctx, \
98
+ (nettle_cipher_func *) (f), \
99
+ sizeof((self)->iv), (self)->iv, \
100
+ (length), (dst), (src)))
101
+
102
+ #define CFB8_ENCRYPT(self, f, length, dst, src) \
103
+ (0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
104
+ (uint8_t *) 0, (const uint8_t *) 0)) \
105
+ : cfb8_encrypt((void *) &(self)->ctx, \
106
+ (nettle_cipher_func *) (f), \
107
+ sizeof((self)->iv), (self)->iv, \
108
+ (length), (dst), (src)))
109
+
110
+ #define CFB8_DECRYPT(self, f, length, dst, src) \
111
+ (0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
112
+ (uint8_t *) 0, (const uint8_t *) 0)) \
113
+ : cfb8_decrypt((void *) &(self)->ctx, \
114
+ (nettle_cipher_func *) (f), \
115
+ sizeof((self)->iv), (self)->iv, \
116
+ (length), (dst), (src)))
117
+
118
+ #ifdef __cplusplus
119
+ }
120
+ #endif
121
+
122
+ #endif /* NETTLE_CFB_H_INCLUDED */
include/nettle/chacha-poly1305.h ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* chacha-poly1305.h
2
+
3
+ AEAD mechanism based on chacha and poly1305.
4
+ See draft-agl-tls-chacha20poly1305-04.
5
+
6
+ Copyright (C) 2014 Niels Möller
7
+
8
+ This file is part of GNU Nettle.
9
+
10
+ GNU Nettle is free software: you can redistribute it and/or
11
+ modify it under the terms of either:
12
+
13
+ * the GNU Lesser General Public License as published by the Free
14
+ Software Foundation; either version 3 of the License, or (at your
15
+ option) any later version.
16
+
17
+ or
18
+
19
+ * the GNU General Public License as published by the Free
20
+ Software Foundation; either version 2 of the License, or (at your
21
+ option) any later version.
22
+
23
+ or both in parallel, as here.
24
+
25
+ GNU Nettle is distributed in the hope that it will be useful,
26
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
+ General Public License for more details.
29
+
30
+ You should have received copies of the GNU General Public License and
31
+ the GNU Lesser General Public License along with this program. If
32
+ not, see http://www.gnu.org/licenses/.
33
+ */
34
+
35
+ #ifndef NETTLE_CHACHA_POLY1305_H_INCLUDED
36
+ #define NETTLE_CHACHA_POLY1305_H_INCLUDED
37
+
38
+ #include "chacha.h"
39
+ #include "poly1305.h"
40
+
41
+ #ifdef __cplusplus
42
+ extern "C" {
43
+ #endif
44
+
45
+ /* Name mangling */
46
+ #define chacha_poly1305_set_key nettle_chacha_poly1305_set_key
47
+ #define chacha_poly1305_set_nonce nettle_chacha_poly1305_set_nonce
48
+ #define chacha_poly1305_update nettle_chacha_poly1305_update
49
+ #define chacha_poly1305_decrypt nettle_chacha_poly1305_decrypt
50
+ #define chacha_poly1305_encrypt nettle_chacha_poly1305_encrypt
51
+ #define chacha_poly1305_digest nettle_chacha_poly1305_digest
52
+
53
+ #define CHACHA_POLY1305_BLOCK_SIZE 64
54
+ /* FIXME: Any need for 128-bit variant? */
55
+ #define CHACHA_POLY1305_KEY_SIZE 32
56
+ #define CHACHA_POLY1305_NONCE_SIZE CHACHA_NONCE96_SIZE
57
+ #define CHACHA_POLY1305_DIGEST_SIZE 16
58
+
59
+ struct chacha_poly1305_ctx
60
+ {
61
+ struct chacha_ctx chacha;
62
+ struct poly1305_ctx poly1305;
63
+ union nettle_block16 s;
64
+ uint64_t auth_size;
65
+ uint64_t data_size;
66
+ /* poly1305 block */
67
+ uint8_t block[POLY1305_BLOCK_SIZE];
68
+ unsigned index;
69
+ };
70
+
71
+ void
72
+ chacha_poly1305_set_key (struct chacha_poly1305_ctx *ctx,
73
+ const uint8_t *key);
74
+ void
75
+ chacha_poly1305_set_nonce (struct chacha_poly1305_ctx *ctx,
76
+ const uint8_t *nonce);
77
+
78
+ void
79
+ chacha_poly1305_update (struct chacha_poly1305_ctx *ctx,
80
+ size_t length, const uint8_t *data);
81
+
82
+ void
83
+ chacha_poly1305_encrypt (struct chacha_poly1305_ctx *ctx,
84
+ size_t length, uint8_t *dst, const uint8_t *src);
85
+
86
+ void
87
+ chacha_poly1305_decrypt (struct chacha_poly1305_ctx *ctx,
88
+ size_t length, uint8_t *dst, const uint8_t *src);
89
+
90
+ void
91
+ chacha_poly1305_digest (struct chacha_poly1305_ctx *ctx,
92
+ size_t length, uint8_t *digest);
93
+
94
+ #ifdef __cplusplus
95
+ }
96
+ #endif
97
+
98
+ #endif /* NETTLE_CHACHA_POLY1305_H_INCLUDED */
include/nettle/chacha.h ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* chacha.h
2
+
3
+ The ChaCha stream cipher.
4
+
5
+ Copyright (C) 2013 Joachim Strömbergson
6
+ Copyright (C) 2012 Simon Josefsson
7
+ Copyright (C) 2014 Niels Möller
8
+
9
+ This file is part of GNU Nettle.
10
+
11
+ GNU Nettle is free software: you can redistribute it and/or
12
+ modify it under the terms of either:
13
+
14
+ * the GNU Lesser General Public License as published by the Free
15
+ Software Foundation; either version 3 of the License, or (at your
16
+ option) any later version.
17
+
18
+ or
19
+
20
+ * the GNU General Public License as published by the Free
21
+ Software Foundation; either version 2 of the License, or (at your
22
+ option) any later version.
23
+
24
+ or both in parallel, as here.
25
+
26
+ GNU Nettle is distributed in the hope that it will be useful,
27
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
28
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29
+ General Public License for more details.
30
+
31
+ You should have received copies of the GNU General Public License and
32
+ the GNU Lesser General Public License along with this program. If
33
+ not, see http://www.gnu.org/licenses/.
34
+ */
35
+
36
+ #ifndef NETTLE_CHACHA_H_INCLUDED
37
+ #define NETTLE_CHACHA_H_INCLUDED
38
+
39
+ #include "nettle-types.h"
40
+
41
+ #ifdef __cplusplus
42
+ extern "C" {
43
+ #endif
44
+
45
+ /* Name mangling */
46
+ #define chacha_set_key nettle_chacha_set_key
47
+ #define chacha_set_nonce nettle_chacha_set_nonce
48
+ #define chacha_set_nonce96 nettle_chacha_set_nonce96
49
+ #define chacha_set_counter nettle_chacha_set_counter
50
+ #define chacha_set_counter32 nettle_chacha_set_counter32
51
+ #define chacha_crypt nettle_chacha_crypt
52
+ #define chacha_crypt32 nettle_chacha_crypt32
53
+
54
+ /* Currently, only 256-bit keys are supported. */
55
+ #define CHACHA_KEY_SIZE 32
56
+ #define CHACHA_BLOCK_SIZE 64
57
+ #define CHACHA_NONCE_SIZE 8
58
+ #define CHACHA_NONCE96_SIZE 12
59
+ #define CHACHA_COUNTER_SIZE 8
60
+ #define CHACHA_COUNTER32_SIZE 4
61
+
62
+ #define _CHACHA_STATE_LENGTH 16
63
+
64
+ struct chacha_ctx
65
+ {
66
+ /* Indices 0-3 holds a constant (SIGMA or TAU).
67
+ Indices 4-11 holds the key.
68
+ Indices 12-13 holds the block counter.
69
+ Indices 14-15 holds the IV:
70
+
71
+ This creates the state matrix:
72
+ C C C C
73
+ K K K K
74
+ K K K K
75
+ B B I I
76
+ */
77
+ uint32_t state[_CHACHA_STATE_LENGTH];
78
+ };
79
+
80
+ void
81
+ chacha_set_key(struct chacha_ctx *ctx, const uint8_t *key);
82
+
83
+ void
84
+ chacha_set_nonce(struct chacha_ctx *ctx, const uint8_t *nonce);
85
+
86
+ void
87
+ chacha_set_nonce96(struct chacha_ctx *ctx, const uint8_t *nonce);
88
+
89
+ void
90
+ chacha_set_counter(struct chacha_ctx *ctx, const uint8_t *counter);
91
+
92
+ void
93
+ chacha_set_counter32(struct chacha_ctx *ctx, const uint8_t *counter);
94
+
95
+ void
96
+ chacha_crypt(struct chacha_ctx *ctx, size_t length,
97
+ uint8_t *dst, const uint8_t *src);
98
+
99
+ void
100
+ chacha_crypt32(struct chacha_ctx *ctx, size_t length,
101
+ uint8_t *dst, const uint8_t *src);
102
+
103
+ #ifdef __cplusplus
104
+ }
105
+ #endif
106
+
107
+ #endif /* NETTLE_CHACHA_H_INCLUDED */
include/nettle/cmac.h ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* cmac.h
2
+
3
+ CMAC mode, as specified in RFC4493
4
+
5
+ Copyright (C) 2017 Red Hat, Inc.
6
+
7
+ Contributed by Nikos Mavrogiannopoulos
8
+
9
+ This file is part of GNU Nettle.
10
+
11
+ GNU Nettle is free software: you can redistribute it and/or
12
+ modify it under the terms of either:
13
+
14
+ * the GNU Lesser General Public License as published by the Free
15
+ Software Foundation; either version 3 of the License, or (at your
16
+ option) any later version.
17
+
18
+ or
19
+
20
+ * the GNU General Public License as published by the Free
21
+ Software Foundation; either version 2 of the License, or (at your
22
+ option) any later version.
23
+
24
+ or both in parallel, as here.
25
+
26
+ GNU Nettle is distributed in the hope that it will be useful,
27
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
28
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29
+ General Public License for more details.
30
+
31
+ You should have received copies of the GNU General Public License and
32
+ the GNU Lesser General Public License along with this program. If
33
+ not, see http://www.gnu.org/licenses/.
34
+ */
35
+
36
+ #ifndef NETTLE_CMAC_H_INCLUDED
37
+ #define NETTLE_CMAC_H_INCLUDED
38
+
39
+ #include "aes.h"
40
+ #include "des.h"
41
+ #include "nettle-types.h"
42
+
43
+ #ifdef __cplusplus
44
+ extern "C" {
45
+ #endif
46
+
47
+ #define CMAC128_DIGEST_SIZE 16
48
+ #define CMAC64_DIGEST_SIZE 8
49
+
50
+ #define cmac128_set_key nettle_cmac128_set_key
51
+ #define cmac128_init nettle_cmac128_init
52
+ #define cmac128_update nettle_cmac128_update
53
+ #define cmac128_digest nettle_cmac128_digest
54
+ #define cmac_aes128_set_key nettle_cmac_aes128_set_key
55
+ #define cmac_aes128_update nettle_cmac_aes128_update
56
+ #define cmac_aes128_digest nettle_cmac_aes128_digest
57
+ #define cmac_aes256_set_key nettle_cmac_aes256_set_key
58
+ #define cmac_aes256_update nettle_cmac_aes256_update
59
+ #define cmac_aes256_digest nettle_cmac_aes256_digest
60
+
61
+ #define cmac64_set_key nettle_cmac64_set_key
62
+ #define cmac64_init nettle_cmac64_init
63
+ #define cmac64_update nettle_cmac64_update
64
+ #define cmac64_digest nettle_cmac64_digest
65
+ #define cmac_des3_set_key nettle_cmac_des3_set_key
66
+ #define cmac_des3_update nettle_cmac_des3_update
67
+ #define cmac_des3_digest nettle_cmac_des3_digest
68
+
69
+ struct cmac128_key
70
+ {
71
+ union nettle_block16 K1;
72
+ union nettle_block16 K2;
73
+ };
74
+
75
+ struct cmac128_ctx
76
+ {
77
+ /* MAC state */
78
+ union nettle_block16 X;
79
+
80
+ /* Block buffer */
81
+ union nettle_block16 block;
82
+ size_t index;
83
+ };
84
+
85
+ struct cmac64_key
86
+ {
87
+ union nettle_block8 K1;
88
+ union nettle_block8 K2;
89
+ };
90
+
91
+ struct cmac64_ctx
92
+ {
93
+ /* MAC state */
94
+ union nettle_block8 X;
95
+
96
+ /* Block buffer */
97
+ union nettle_block8 block;
98
+ size_t index;
99
+ };
100
+
101
+ void
102
+ cmac128_set_key(struct cmac128_key *key, const void *cipher,
103
+ nettle_cipher_func *encrypt);
104
+
105
+ void
106
+ cmac128_init(struct cmac128_ctx *ctx);
107
+
108
+ void
109
+ cmac128_update(struct cmac128_ctx *ctx, const void *cipher,
110
+ nettle_cipher_func *encrypt,
111
+ size_t msg_len, const uint8_t *msg);
112
+ void
113
+ cmac128_digest(struct cmac128_ctx *ctx, const struct cmac128_key *key,
114
+ const void *cipher, nettle_cipher_func *encrypt,
115
+ unsigned length, uint8_t *digest);
116
+
117
+
118
+ #define CMAC128_CTX(type) \
119
+ { struct cmac128_key key; struct cmac128_ctx ctx; type cipher; }
120
+
121
+ /* NOTE: Avoid using NULL, as we don't include anything defining it. */
122
+ #define CMAC128_SET_KEY(self, set_key, encrypt, cmac_key) \
123
+ do { \
124
+ (set_key)(&(self)->cipher, (cmac_key)); \
125
+ if (0) (encrypt)(&(self)->cipher, ~(size_t) 0, \
126
+ (uint8_t *) 0, (const uint8_t *) 0); \
127
+ cmac128_set_key(&(self)->key, &(self)->cipher, \
128
+ (nettle_cipher_func *) (encrypt)); \
129
+ cmac128_init(&(self)->ctx); \
130
+ } while (0)
131
+
132
+ #define CMAC128_UPDATE(self, encrypt, length, src) \
133
+ (0 ? (encrypt)(&(self)->cipher, ~(size_t) 0, \
134
+ (uint8_t *) 0, (const uint8_t *) 0) \
135
+ : cmac128_update(&(self)->ctx, &(self)->cipher, \
136
+ (nettle_cipher_func *)encrypt, \
137
+ (length), (src)))
138
+
139
+ #define CMAC128_DIGEST(self, encrypt, length, digest) \
140
+ (0 ? (encrypt)(&(self)->cipher, ~(size_t) 0, \
141
+ (uint8_t *) 0, (const uint8_t *) 0) \
142
+ : cmac128_digest(&(self)->ctx, &(self)->key, \
143
+ &(self)->cipher, \
144
+ (nettle_cipher_func *) (encrypt), \
145
+ (length), (digest)))
146
+
147
+ void
148
+ cmac64_set_key(struct cmac64_key *key, const void *cipher,
149
+ nettle_cipher_func *encrypt);
150
+
151
+ void
152
+ cmac64_init(struct cmac64_ctx *ctx);
153
+
154
+ void
155
+ cmac64_update(struct cmac64_ctx *ctx, const void *cipher,
156
+ nettle_cipher_func *encrypt,
157
+ size_t msg_len, const uint8_t *msg);
158
+
159
+ void
160
+ cmac64_digest(struct cmac64_ctx *ctx, const struct cmac64_key *key,
161
+ const void *cipher, nettle_cipher_func *encrypt,
162
+ unsigned length, uint8_t *digest);
163
+
164
+
165
+ #define CMAC64_CTX(type) \
166
+ { struct cmac64_key key; struct cmac64_ctx ctx; type cipher; }
167
+
168
+ /* NOTE: Avoid using NULL, as we don't include anything defining it. */
169
+ #define CMAC64_SET_KEY(self, set_key, encrypt, cmac_key) \
170
+ do { \
171
+ (set_key)(&(self)->cipher, (cmac_key)); \
172
+ if (0) (encrypt)(&(self)->cipher, ~(size_t) 0, \
173
+ (uint8_t *) 0, (const uint8_t *) 0); \
174
+ cmac64_set_key(&(self)->key, &(self)->cipher, \
175
+ (nettle_cipher_func *) (encrypt)); \
176
+ cmac64_init(&(self)->ctx); \
177
+ } while (0)
178
+
179
+ #define CMAC64_UPDATE(self, encrypt, length, src) \
180
+ (0 ? (encrypt)(&(self)->cipher, ~(size_t) 0, \
181
+ (uint8_t *) 0, (const uint8_t *) 0) \
182
+ : cmac64_update(&(self)->ctx, &(self)->cipher, \
183
+ (nettle_cipher_func *)encrypt, \
184
+ (length), (src)))
185
+
186
+ #define CMAC64_DIGEST(self, encrypt, length, digest) \
187
+ (0 ? (encrypt)(&(self)->cipher, ~(size_t) 0, \
188
+ (uint8_t *) 0, (const uint8_t *) 0) \
189
+ : cmac64_digest(&(self)->ctx, &(self)->key, \
190
+ &(self)->cipher, \
191
+ (nettle_cipher_func *) (encrypt), \
192
+ (length), (digest)))
193
+
194
+ struct cmac_aes128_ctx CMAC128_CTX(struct aes128_ctx);
195
+
196
+ void
197
+ cmac_aes128_set_key(struct cmac_aes128_ctx *ctx, const uint8_t *key);
198
+
199
+ void
200
+ cmac_aes128_update(struct cmac_aes128_ctx *ctx,
201
+ size_t length, const uint8_t *data);
202
+
203
+ void
204
+ cmac_aes128_digest(struct cmac_aes128_ctx *ctx,
205
+ size_t length, uint8_t *digest);
206
+
207
+ struct cmac_aes256_ctx CMAC128_CTX(struct aes256_ctx);
208
+
209
+ void
210
+ cmac_aes256_set_key(struct cmac_aes256_ctx *ctx, const uint8_t *key);
211
+
212
+ void
213
+ cmac_aes256_update(struct cmac_aes256_ctx *ctx,
214
+ size_t length, const uint8_t *data);
215
+
216
+ void
217
+ cmac_aes256_digest(struct cmac_aes256_ctx *ctx,
218
+ size_t length, uint8_t *digest);
219
+
220
+ struct cmac_des3_ctx CMAC64_CTX(struct des3_ctx);
221
+
222
+ void
223
+ cmac_des3_set_key(struct cmac_des3_ctx *ctx, const uint8_t *key);
224
+
225
+ void
226
+ cmac_des3_update(struct cmac_des3_ctx *ctx,
227
+ size_t length, const uint8_t *data);
228
+
229
+ void
230
+ cmac_des3_digest(struct cmac_des3_ctx *ctx,
231
+ size_t length, uint8_t *digest);
232
+
233
+ #ifdef __cplusplus
234
+ }
235
+ #endif
236
+
237
+ #endif /* CMAC_H_INCLUDED */
include/nettle/ctr.h ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* ctr.h
2
+
3
+ Counter mode, using an network byte order incremented counter,
4
+ matching the testcases of NIST 800-38A.
5
+
6
+ Copyright (C) 2005 Niels Möller
7
+
8
+ This file is part of GNU Nettle.
9
+
10
+ GNU Nettle is free software: you can redistribute it and/or
11
+ modify it under the terms of either:
12
+
13
+ * the GNU Lesser General Public License as published by the Free
14
+ Software Foundation; either version 3 of the License, or (at your
15
+ option) any later version.
16
+
17
+ or
18
+
19
+ * the GNU General Public License as published by the Free
20
+ Software Foundation; either version 2 of the License, or (at your
21
+ option) any later version.
22
+
23
+ or both in parallel, as here.
24
+
25
+ GNU Nettle is distributed in the hope that it will be useful,
26
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
+ General Public License for more details.
29
+
30
+ You should have received copies of the GNU General Public License and
31
+ the GNU Lesser General Public License along with this program. If
32
+ not, see http://www.gnu.org/licenses/.
33
+ */
34
+
35
+ #ifndef NETTLE_CTR_H_INCLUDED
36
+ #define NETTLE_CTR_H_INCLUDED
37
+
38
+ #include "nettle-types.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* Name mangling */
45
+ #define ctr_crypt nettle_ctr_crypt
46
+
47
+ void
48
+ ctr_crypt(const void *ctx, nettle_cipher_func *f,
49
+ size_t block_size, uint8_t *ctr,
50
+ size_t length, uint8_t *dst,
51
+ const uint8_t *src);
52
+
53
+ #define CTR_CTX(type, size) \
54
+ { type ctx; uint8_t ctr[size]; }
55
+
56
+ #define CTR_SET_COUNTER(ctx, data) \
57
+ memcpy((ctx)->ctr, (data), sizeof((ctx)->ctr))
58
+
59
+ #define CTR_CRYPT(self, f, length, dst, src) \
60
+ (0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
61
+ (uint8_t *) 0, (const uint8_t *) 0)) \
62
+ : ctr_crypt((void *) &(self)->ctx, \
63
+ (nettle_cipher_func *) (f), \
64
+ sizeof((self)->ctr), (self)->ctr, \
65
+ (length), (dst), (src)))
66
+
67
+ #ifdef __cplusplus
68
+ }
69
+ #endif
70
+
71
+ #endif /* NETTLE_CTR_H_INCLUDED */
include/nettle/curve25519.h ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* curve25519.h
2
+
3
+ Copyright (C) 2014 Niels Möller
4
+
5
+ This file is part of GNU Nettle.
6
+
7
+ GNU Nettle is free software: you can redistribute it and/or
8
+ modify it under the terms of either:
9
+
10
+ * the GNU Lesser General Public License as published by the Free
11
+ Software Foundation; either version 3 of the License, or (at your
12
+ option) any later version.
13
+
14
+ or
15
+
16
+ * the GNU General Public License as published by the Free
17
+ Software Foundation; either version 2 of the License, or (at your
18
+ option) any later version.
19
+
20
+ or both in parallel, as here.
21
+
22
+ GNU Nettle is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
+ General Public License for more details.
26
+
27
+ You should have received copies of the GNU General Public License and
28
+ the GNU Lesser General Public License along with this program. If
29
+ not, see http://www.gnu.org/licenses/.
30
+ */
31
+
32
+ #ifndef NETTLE_CURVE25519_H
33
+ #define NETTLE_CURVE25519_H
34
+
35
+ #include "nettle-types.h"
36
+
37
+ #ifdef __cplusplus
38
+ extern "C" {
39
+ #endif
40
+
41
+ /* Name mangling */
42
+ #define curve25519_mul_g nettle_curve25519_mul_g
43
+ #define curve25519_mul nettle_curve25519_mul
44
+
45
+ #define CURVE25519_SIZE 32
46
+
47
+ /* Indicates that curve25519_mul conforms to RFC 7748. */
48
+ #define NETTLE_CURVE25519_RFC7748 1
49
+
50
+ void
51
+ curve25519_mul_g (uint8_t *q, const uint8_t *n);
52
+
53
+ void
54
+ curve25519_mul (uint8_t *q, const uint8_t *n, const uint8_t *p);
55
+
56
+ #ifdef __cplusplus
57
+ }
58
+ #endif
59
+
60
+ #endif /* NETTLE_CURVE25519_H */
include/nettle/curve448.h ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* curve448.h
2
+
3
+ Copyright (C) 2017 Daiki Ueno
4
+ Copyright (C) 2017 Red Hat, Inc.
5
+
6
+ This file is part of GNU Nettle.
7
+
8
+ GNU Nettle is free software: you can redistribute it and/or
9
+ modify it under the terms of either:
10
+
11
+ * the GNU Lesser General Public License as published by the Free
12
+ Software Foundation; either version 3 of the License, or (at your
13
+ option) any later version.
14
+
15
+ or
16
+
17
+ * the GNU General Public License as published by the Free
18
+ Software Foundation; either version 2 of the License, or (at your
19
+ option) any later version.
20
+
21
+ or both in parallel, as here.
22
+
23
+ GNU Nettle is distributed in the hope that it will be useful,
24
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26
+ General Public License for more details.
27
+
28
+ You should have received copies of the GNU General Public License and
29
+ the GNU Lesser General Public License along with this program. If
30
+ not, see http://www.gnu.org/licenses/.
31
+ */
32
+
33
+ #ifndef NETTLE_CURVE448_H
34
+ #define NETTLE_CURVE448_H
35
+
36
+ #include "nettle-types.h"
37
+
38
+ #ifdef __cplusplus
39
+ extern "C" {
40
+ #endif
41
+
42
+ /* Name mangling */
43
+ #define curve448_mul_g nettle_curve448_mul_g
44
+ #define curve448_mul nettle_curve448_mul
45
+
46
+ #define CURVE448_SIZE 56
47
+
48
+ void
49
+ curve448_mul_g (uint8_t *q, const uint8_t *n);
50
+
51
+ void
52
+ curve448_mul (uint8_t *q, const uint8_t *n, const uint8_t *p);
53
+
54
+ #ifdef __cplusplus
55
+ }
56
+ #endif
57
+
58
+ #endif /* NETTLE_CURVE448_H */
include/nettle/des.h ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* des.h
2
+
3
+ The des block cipher. And triple des.
4
+
5
+ Copyright (C) 1992 Dana L. How
6
+ Copyright (C) 2001 Niels Möller
7
+
8
+ This file is part of GNU Nettle.
9
+
10
+ GNU Nettle is free software: you can redistribute it and/or
11
+ modify it under the terms of either:
12
+
13
+ * the GNU Lesser General Public License as published by the Free
14
+ Software Foundation; either version 3 of the License, or (at your
15
+ option) any later version.
16
+
17
+ or
18
+
19
+ * the GNU General Public License as published by the Free
20
+ Software Foundation; either version 2 of the License, or (at your
21
+ option) any later version.
22
+
23
+ or both in parallel, as here.
24
+
25
+ GNU Nettle is distributed in the hope that it will be useful,
26
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
+ General Public License for more details.
29
+
30
+ You should have received copies of the GNU General Public License and
31
+ the GNU Lesser General Public License along with this program. If
32
+ not, see http://www.gnu.org/licenses/.
33
+ */
34
+
35
+ /*
36
+ * des - fast & portable DES encryption & decryption.
37
+ * Copyright (C) 1992 Dana L. How
38
+ * Please see the file `../lib/descore.README' for the complete copyright
39
+ * notice.
40
+ *
41
+ * Slightly edited by Niels Möller, 1997
42
+ */
43
+
44
+ #ifndef NETTLE_DES_H_INCLUDED
45
+ #define NETTLE_DES_H_INCLUDED
46
+
47
+ #include "nettle-types.h"
48
+
49
+ #ifdef __cplusplus
50
+ extern "C" {
51
+ #endif
52
+
53
+ /* Namespace mangling */
54
+ #define des_set_key nettle_des_set_key
55
+ #define des_encrypt nettle_des_encrypt
56
+ #define des_decrypt nettle_des_decrypt
57
+ #define des_check_parity nettle_des_check_parity
58
+ #define des_fix_parity nettle_des_fix_parity
59
+ #define des3_set_key nettle_des3_set_key
60
+ #define des3_encrypt nettle_des3_encrypt
61
+ #define des3_decrypt nettle_des3_decrypt
62
+
63
+ #define DES_KEY_SIZE 8
64
+ #define DES_BLOCK_SIZE 8
65
+
66
+ /* Expanded key length */
67
+ #define _DES_KEY_LENGTH 32
68
+
69
+ struct des_ctx
70
+ {
71
+ uint32_t key[_DES_KEY_LENGTH];
72
+ };
73
+
74
+ /* Returns 1 for good keys and 0 for weak keys. */
75
+ int
76
+ des_set_key(struct des_ctx *ctx, const uint8_t *key);
77
+
78
+ void
79
+ des_encrypt(const struct des_ctx *ctx,
80
+ size_t length, uint8_t *dst,
81
+ const uint8_t *src);
82
+ void
83
+ des_decrypt(const struct des_ctx *ctx,
84
+ size_t length, uint8_t *dst,
85
+ const uint8_t *src);
86
+
87
+ int
88
+ des_check_parity(size_t length, const uint8_t *key);
89
+
90
+ void
91
+ des_fix_parity(size_t length, uint8_t *dst,
92
+ const uint8_t *src);
93
+
94
+ #define DES3_KEY_SIZE 24
95
+ #define DES3_BLOCK_SIZE DES_BLOCK_SIZE
96
+
97
+ struct des3_ctx
98
+ {
99
+ struct des_ctx des[3];
100
+ };
101
+
102
+
103
+ /* Returns 1 for good keys and 0 for weak keys. */
104
+ int
105
+ des3_set_key(struct des3_ctx *ctx, const uint8_t *key);
106
+
107
+ void
108
+ des3_encrypt(const struct des3_ctx *ctx,
109
+ size_t length, uint8_t *dst,
110
+ const uint8_t *src);
111
+ void
112
+ des3_decrypt(const struct des3_ctx *ctx,
113
+ size_t length, uint8_t *dst,
114
+ const uint8_t *src);
115
+
116
+ #ifdef __cplusplus
117
+ }
118
+ #endif
119
+
120
+ #endif /* NETTLE_DES_H_INCLUDED */
include/nettle/dsa-compat.h ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* dsa-compat.h
2
+
3
+ Old DSA publickey interface.
4
+
5
+ Copyright (C) 2002, 2013, 2014 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_DSA_COMPAT_H_INCLUDED
35
+ #define NETTLE_DSA_COMPAT_H_INCLUDED
36
+
37
+ #include "dsa.h"
38
+
39
+ #include "sha1.h"
40
+ #include "sha2.h"
41
+
42
+ /* Name mangling */
43
+ #define dsa_public_key_init nettle_dsa_public_key_init
44
+ #define dsa_public_key_clear nettle_dsa_public_key_clear
45
+ #define dsa_private_key_init nettle_dsa_private_key_init
46
+ #define dsa_private_key_clear nettle_dsa_private_key_clear
47
+ #define dsa_sha1_sign nettle_dsa_sha1_sign
48
+ #define dsa_sha1_verify nettle_dsa_sha1_verify
49
+ #define dsa_sha256_sign nettle_dsa_sha256_sign
50
+ #define dsa_sha256_verify nettle_dsa_sha256_verify
51
+ #define dsa_sha1_sign_digest nettle_dsa_sha1_sign_digest
52
+ #define dsa_sha1_verify_digest nettle_dsa_sha1_verify_digest
53
+ #define dsa_sha256_sign_digest nettle_dsa_sha256_sign_digest
54
+ #define dsa_sha256_verify_digest nettle_dsa_sha256_verify_digest
55
+ #define dsa_compat_generate_keypair nettle_dsa_compat_generate_keypair
56
+
57
+ /* Switch meaning of dsa_generate_keypair */
58
+ #undef dsa_generate_keypair
59
+ #define dsa_generate_keypair nettle_dsa_compat_generate_keypair
60
+
61
+ #ifdef __cplusplus
62
+ extern "C" {
63
+ #endif
64
+
65
+ struct dsa_public_key
66
+ {
67
+ /* Same as struct dsa_params, but can't use that struct here without
68
+ breaking backwards compatibility. Layout must be identical, since
69
+ this is cast to a struct dsa_param pointer for calling _dsa_sign
70
+ and _dsa_verify */
71
+ mpz_t p;
72
+ mpz_t q;
73
+ mpz_t g;
74
+
75
+ /* Public value */
76
+ mpz_t y;
77
+ };
78
+
79
+ struct dsa_private_key
80
+ {
81
+ /* Unlike an rsa public key, private key operations will need both
82
+ * the private and the public information. */
83
+ mpz_t x;
84
+ };
85
+
86
+ /* Signing a message works as follows:
87
+ *
88
+ * Store the private key in a dsa_private_key struct.
89
+ *
90
+ * Initialize a hashing context, by callling
91
+ * sha1_init
92
+ *
93
+ * Hash the message by calling
94
+ * sha1_update
95
+ *
96
+ * Create the signature by calling
97
+ * dsa_sha1_sign
98
+ *
99
+ * The signature is represented as a struct dsa_signature. This call also
100
+ * resets the hashing context.
101
+ *
102
+ * When done with the key and signature, don't forget to call
103
+ * dsa_signature_clear.
104
+ */
105
+
106
+ /* Calls mpz_init to initialize bignum storage. */
107
+ void
108
+ dsa_public_key_init(struct dsa_public_key *key);
109
+
110
+ /* Calls mpz_clear to deallocate bignum storage. */
111
+ void
112
+ dsa_public_key_clear(struct dsa_public_key *key);
113
+
114
+
115
+ /* Calls mpz_init to initialize bignum storage. */
116
+ void
117
+ dsa_private_key_init(struct dsa_private_key *key);
118
+
119
+ /* Calls mpz_clear to deallocate bignum storage. */
120
+ void
121
+ dsa_private_key_clear(struct dsa_private_key *key);
122
+
123
+ int
124
+ dsa_sha1_sign(const struct dsa_public_key *pub,
125
+ const struct dsa_private_key *key,
126
+ void *random_ctx, nettle_random_func *random,
127
+ struct sha1_ctx *hash,
128
+ struct dsa_signature *signature);
129
+
130
+ int
131
+ dsa_sha256_sign(const struct dsa_public_key *pub,
132
+ const struct dsa_private_key *key,
133
+ void *random_ctx, nettle_random_func *random,
134
+ struct sha256_ctx *hash,
135
+ struct dsa_signature *signature);
136
+
137
+ int
138
+ dsa_sha1_verify(const struct dsa_public_key *key,
139
+ struct sha1_ctx *hash,
140
+ const struct dsa_signature *signature);
141
+
142
+ int
143
+ dsa_sha256_verify(const struct dsa_public_key *key,
144
+ struct sha256_ctx *hash,
145
+ const struct dsa_signature *signature);
146
+
147
+ int
148
+ dsa_sha1_sign_digest(const struct dsa_public_key *pub,
149
+ const struct dsa_private_key *key,
150
+ void *random_ctx, nettle_random_func *random,
151
+ const uint8_t *digest,
152
+ struct dsa_signature *signature);
153
+ int
154
+ dsa_sha256_sign_digest(const struct dsa_public_key *pub,
155
+ const struct dsa_private_key *key,
156
+ void *random_ctx, nettle_random_func *random,
157
+ const uint8_t *digest,
158
+ struct dsa_signature *signature);
159
+
160
+ int
161
+ dsa_sha1_verify_digest(const struct dsa_public_key *key,
162
+ const uint8_t *digest,
163
+ const struct dsa_signature *signature);
164
+
165
+ int
166
+ dsa_sha256_verify_digest(const struct dsa_public_key *key,
167
+ const uint8_t *digest,
168
+ const struct dsa_signature *signature);
169
+
170
+ /* Key generation */
171
+ int
172
+ dsa_generate_keypair(struct dsa_public_key *pub,
173
+ struct dsa_private_key *key,
174
+
175
+ void *random_ctx, nettle_random_func *random,
176
+ void *progress_ctx, nettle_progress_func *progress,
177
+ unsigned p_bits, unsigned q_bits);
178
+
179
+ #ifdef __cplusplus
180
+ }
181
+ #endif
182
+
183
+ #endif /* NETTLE_DSA_COMPAT_H_INCLUDED */
include/nettle/dsa.h ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* dsa.h
2
+
3
+ The DSA publickey algorithm.
4
+
5
+ Copyright (C) 2002, 2013, 2014 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_DSA_H_INCLUDED
35
+ #define NETTLE_DSA_H_INCLUDED
36
+
37
+ #include "nettle-types.h"
38
+ #include "bignum.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* Name mangling */
45
+ #define dsa_params_init nettle_dsa_params_init
46
+ #define dsa_params_clear nettle_dsa_params_clear
47
+ #define dsa_signature_init nettle_dsa_signature_init
48
+ #define dsa_signature_clear nettle_dsa_signature_clear
49
+ #define dsa_sign nettle_dsa_sign
50
+ #define dsa_verify nettle_dsa_verify
51
+ #define dsa_generate_params nettle_dsa_generate_params
52
+ #define dsa_generate_keypair nettle_dsa_generate_keypair
53
+ #define dsa_signature_from_sexp nettle_dsa_signature_from_sexp
54
+ #define dsa_keypair_to_sexp nettle_dsa_keypair_to_sexp
55
+ #define dsa_keypair_from_sexp_alist nettle_dsa_keypair_from_sexp_alist
56
+ #define dsa_sha1_keypair_from_sexp nettle_dsa_sha1_keypair_from_sexp
57
+ #define dsa_sha256_keypair_from_sexp nettle_dsa_sha256_keypair_from_sexp
58
+ #define dsa_params_from_der_iterator nettle_dsa_params_from_der_iterator
59
+ #define dsa_public_key_from_der_iterator nettle_dsa_public_key_from_der_iterator
60
+ #define dsa_openssl_private_key_from_der_iterator nettle_dsa_openssl_private_key_from_der_iterator
61
+ #define dsa_openssl_private_key_from_der nettle_openssl_provate_key_from_der
62
+
63
+ /* For FIPS approved parameters */
64
+ #define DSA_SHA1_MIN_P_BITS 512
65
+ #define DSA_SHA1_Q_OCTETS 20
66
+ #define DSA_SHA1_Q_BITS 160
67
+
68
+ #define DSA_SHA256_MIN_P_BITS 1024
69
+ #define DSA_SHA256_Q_OCTETS 32
70
+ #define DSA_SHA256_Q_BITS 256
71
+
72
+ struct dsa_params
73
+ {
74
+ /* Modulo */
75
+ mpz_t p;
76
+
77
+ /* Group order */
78
+ mpz_t q;
79
+
80
+ /* Generator */
81
+ mpz_t g;
82
+ };
83
+
84
+ void
85
+ dsa_params_init (struct dsa_params *params);
86
+
87
+ void
88
+ dsa_params_clear (struct dsa_params *params);
89
+
90
+ struct dsa_signature
91
+ {
92
+ mpz_t r;
93
+ mpz_t s;
94
+ };
95
+
96
+ /* Calls mpz_init to initialize bignum storage. */
97
+ void
98
+ dsa_signature_init(struct dsa_signature *signature);
99
+
100
+ /* Calls mpz_clear to deallocate bignum storage. */
101
+ void
102
+ dsa_signature_clear(struct dsa_signature *signature);
103
+
104
+ int
105
+ dsa_sign(const struct dsa_params *params,
106
+ const mpz_t x,
107
+ void *random_ctx, nettle_random_func *random,
108
+ size_t digest_size,
109
+ const uint8_t *digest,
110
+ struct dsa_signature *signature);
111
+
112
+ int
113
+ dsa_verify(const struct dsa_params *params,
114
+ const mpz_t y,
115
+ size_t digest_size,
116
+ const uint8_t *digest,
117
+ const struct dsa_signature *signature);
118
+
119
+
120
+ /* Key generation */
121
+
122
+ int
123
+ dsa_generate_params(struct dsa_params *params,
124
+ void *random_ctx, nettle_random_func *random,
125
+ void *progress_ctx, nettle_progress_func *progress,
126
+ unsigned p_bits, unsigned q_bits);
127
+
128
+ void
129
+ dsa_generate_keypair (const struct dsa_params *params,
130
+ mpz_t pub, mpz_t key,
131
+ void *random_ctx, nettle_random_func *random);
132
+
133
+ /* Keys in sexp form. */
134
+
135
+ struct nettle_buffer;
136
+
137
+ /* Generates a public-key expression if PRIV is NULL .*/
138
+ int
139
+ dsa_keypair_to_sexp(struct nettle_buffer *buffer,
140
+ const char *algorithm_name, /* NULL means "dsa" */
141
+ const struct dsa_params *params,
142
+ const mpz_t pub,
143
+ const mpz_t priv);
144
+
145
+ struct sexp_iterator;
146
+
147
+ int
148
+ dsa_signature_from_sexp(struct dsa_signature *rs,
149
+ struct sexp_iterator *i,
150
+ unsigned q_bits);
151
+
152
+ int
153
+ dsa_keypair_from_sexp_alist(struct dsa_params *params,
154
+ mpz_t pub,
155
+ mpz_t priv,
156
+ unsigned p_max_bits,
157
+ unsigned q_bits,
158
+ struct sexp_iterator *i);
159
+
160
+ /* If PRIV is NULL, expect a public-key expression. If PUB is NULL,
161
+ * expect a private key expression and ignore the parts not needed for
162
+ * the public key. */
163
+ /* Keys must be initialized before calling this function, as usual. */
164
+ int
165
+ dsa_sha1_keypair_from_sexp(struct dsa_params *params,
166
+ mpz_t pub,
167
+ mpz_t priv,
168
+ unsigned p_max_bits,
169
+ size_t length, const uint8_t *expr);
170
+
171
+ int
172
+ dsa_sha256_keypair_from_sexp(struct dsa_params *params,
173
+ mpz_t pub,
174
+ mpz_t priv,
175
+ unsigned p_max_bits,
176
+ size_t length, const uint8_t *expr);
177
+
178
+ /* Keys in X.509 andd OpenSSL format. */
179
+ struct asn1_der_iterator;
180
+
181
+ int
182
+ dsa_params_from_der_iterator(struct dsa_params *params,
183
+ unsigned max_bits, unsigned q_bits,
184
+ struct asn1_der_iterator *i);
185
+
186
+ int
187
+ dsa_public_key_from_der_iterator(const struct dsa_params *params,
188
+ mpz_t pub,
189
+ struct asn1_der_iterator *i);
190
+
191
+ int
192
+ dsa_openssl_private_key_from_der_iterator(struct dsa_params *params,
193
+ mpz_t pub,
194
+ mpz_t priv,
195
+ unsigned p_max_bits,
196
+ struct asn1_der_iterator *i);
197
+
198
+ int
199
+ dsa_openssl_private_key_from_der(struct dsa_params *params,
200
+ mpz_t pub,
201
+ mpz_t priv,
202
+ unsigned p_max_bits,
203
+ size_t length, const uint8_t *data);
204
+
205
+
206
+ #ifdef __cplusplus
207
+ }
208
+ #endif
209
+
210
+ #endif /* NETTLE_DSA_H_INCLUDED */
include/nettle/eax.h ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* eax.h
2
+
3
+ EAX mode, see http://www.cs.ucdavis.edu/~rogaway/papers/eax.pdf
4
+
5
+ Copyright (C) 2013 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_EAX_H_INCLUDED
35
+ #define NETTLE_EAX_H_INCLUDED
36
+
37
+ #include "aes.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /* Name mangling */
44
+ #define eax_set_key nettle_eax_set_key
45
+ #define eax_set_nonce nettle_eax_set_nonce
46
+ #define eax_update nettle_eax_update
47
+ #define eax_encrypt nettle_eax_encrypt
48
+ #define eax_decrypt nettle_eax_decrypt
49
+ #define eax_digest nettle_eax_digest
50
+
51
+ #define eax_aes128_set_key nettle_eax_aes128_set_key
52
+ #define eax_aes128_set_nonce nettle_eax_aes128_set_nonce
53
+ #define eax_aes128_update nettle_eax_aes128_update
54
+ #define eax_aes128_encrypt nettle_eax_aes128_encrypt
55
+ #define eax_aes128_decrypt nettle_eax_aes128_decrypt
56
+ #define eax_aes128_digest nettle_eax_aes128_digest
57
+
58
+ /* Restricted to block ciphers with 128 bit block size. FIXME: Reflect
59
+ this in naming? */
60
+
61
+ #define EAX_BLOCK_SIZE 16
62
+ #define EAX_DIGEST_SIZE 16
63
+ /* FIXME: Reasonable default? */
64
+ #define EAX_IV_SIZE 16
65
+
66
+ /* Values independent of message and nonce */
67
+ struct eax_key
68
+ {
69
+ union nettle_block16 pad_block;
70
+ union nettle_block16 pad_partial;
71
+ };
72
+
73
+ struct eax_ctx
74
+ {
75
+ union nettle_block16 omac_nonce;
76
+ union nettle_block16 omac_data;
77
+ union nettle_block16 omac_message;
78
+ union nettle_block16 ctr;
79
+ };
80
+
81
+ void
82
+ eax_set_key (struct eax_key *key, const void *cipher, nettle_cipher_func *f);
83
+
84
+ void
85
+ eax_set_nonce (struct eax_ctx *eax, const struct eax_key *key,
86
+ const void *cipher, nettle_cipher_func *f,
87
+ size_t nonce_length, const uint8_t *nonce);
88
+
89
+ void
90
+ eax_update (struct eax_ctx *eax, const struct eax_key *key,
91
+ const void *cipher, nettle_cipher_func *f,
92
+ size_t data_length, const uint8_t *data);
93
+
94
+ void
95
+ eax_encrypt (struct eax_ctx *eax, const struct eax_key *key,
96
+ const void *cipher, nettle_cipher_func *f,
97
+ size_t length, uint8_t *dst, const uint8_t *src);
98
+
99
+ void
100
+ eax_decrypt (struct eax_ctx *eax, const struct eax_key *key,
101
+ const void *cipher, nettle_cipher_func *f,
102
+ size_t length, uint8_t *dst, const uint8_t *src);
103
+
104
+ void
105
+ eax_digest (struct eax_ctx *eax, const struct eax_key *key,
106
+ const void *cipher, nettle_cipher_func *f,
107
+ size_t length, uint8_t *digest);
108
+
109
+ /* Put the cipher last, to get cipher-independent offsets for the EAX
110
+ * state. */
111
+ #define EAX_CTX(type) \
112
+ { struct eax_key key; struct eax_ctx eax; type cipher; }
113
+
114
+ #define EAX_SET_KEY(ctx, set_key, encrypt, data) \
115
+ do { \
116
+ (set_key)(&(ctx)->cipher, (data)); \
117
+ if (0) (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
118
+ (uint8_t *) 0, (const uint8_t *) 0); \
119
+ eax_set_key (&(ctx)->key, &(ctx)->cipher, (nettle_cipher_func *) encrypt); \
120
+ } while (0)
121
+
122
+ #define EAX_SET_NONCE(ctx, encrypt, length, nonce) \
123
+ (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
124
+ (uint8_t *) 0, (const uint8_t *) 0) \
125
+ : eax_set_nonce (&(ctx)->eax, &(ctx)->key, \
126
+ &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
127
+ (length), (nonce)))
128
+
129
+ #define EAX_UPDATE(ctx, encrypt, length, data) \
130
+ (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
131
+ (uint8_t *) 0, (const uint8_t *) 0) \
132
+ : eax_update (&(ctx)->eax, &(ctx)->key, \
133
+ &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
134
+ (length), (data)))
135
+
136
+ #define EAX_ENCRYPT(ctx, encrypt, length, dst, src) \
137
+ (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
138
+ (uint8_t *) 0, (const uint8_t *) 0) \
139
+ : eax_encrypt (&(ctx)->eax, &(ctx)->key, \
140
+ &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
141
+ (length), (dst), (src)))
142
+
143
+ #define EAX_DECRYPT(ctx, encrypt, length, dst, src) \
144
+ (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
145
+ (uint8_t *) 0, (const uint8_t *) 0) \
146
+ : eax_decrypt (&(ctx)->eax, &(ctx)->key, \
147
+ &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
148
+ (length), (dst), (src)))
149
+
150
+ #define EAX_DIGEST(ctx, encrypt, length, digest) \
151
+ (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
152
+ (uint8_t *) 0, (const uint8_t *) 0) \
153
+ : eax_digest (&(ctx)->eax, &(ctx)->key, \
154
+ &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
155
+ (length), (digest)))
156
+
157
+ struct eax_aes128_ctx EAX_CTX(struct aes128_ctx);
158
+
159
+ void
160
+ eax_aes128_set_key(struct eax_aes128_ctx *ctx, const uint8_t *key);
161
+
162
+ void
163
+ eax_aes128_set_nonce(struct eax_aes128_ctx *ctx,
164
+ size_t length, const uint8_t *iv);
165
+
166
+ void
167
+ eax_aes128_update(struct eax_aes128_ctx *ctx,
168
+ size_t length, const uint8_t *data);
169
+
170
+ void
171
+ eax_aes128_encrypt(struct eax_aes128_ctx *ctx,
172
+ size_t length, uint8_t *dst, const uint8_t *src);
173
+
174
+ void
175
+ eax_aes128_decrypt(struct eax_aes128_ctx *ctx,
176
+ size_t length, uint8_t *dst, const uint8_t *src);
177
+
178
+ void
179
+ eax_aes128_digest(struct eax_aes128_ctx *ctx, size_t length, uint8_t *digest);
180
+
181
+ #ifdef __cplusplus
182
+ }
183
+ #endif
184
+
185
+ #endif /* NETTLE_EAX_H_INCLUDED */
include/nettle/ecc-curve.h ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* ecc-curve.h
2
+
3
+ Copyright (C) 2013 Niels Möller
4
+
5
+ This file is part of GNU Nettle.
6
+
7
+ GNU Nettle is free software: you can redistribute it and/or
8
+ modify it under the terms of either:
9
+
10
+ * the GNU Lesser General Public License as published by the Free
11
+ Software Foundation; either version 3 of the License, or (at your
12
+ option) any later version.
13
+
14
+ or
15
+
16
+ * the GNU General Public License as published by the Free
17
+ Software Foundation; either version 2 of the License, or (at your
18
+ option) any later version.
19
+
20
+ or both in parallel, as here.
21
+
22
+ GNU Nettle is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
+ General Public License for more details.
26
+
27
+ You should have received copies of the GNU General Public License and
28
+ the GNU Lesser General Public License along with this program. If
29
+ not, see http://www.gnu.org/licenses/.
30
+ */
31
+
32
+ /* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
33
+
34
+ #ifndef NETTLE_ECC_CURVE_H_INCLUDED
35
+ #define NETTLE_ECC_CURVE_H_INCLUDED
36
+
37
+ #include "nettle-types.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /* The contents of this struct is internal. */
44
+ struct ecc_curve;
45
+
46
+ const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_gost_gc256b(void);
47
+ const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_gost_gc512a(void);
48
+ const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_secp_192r1(void);
49
+ const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_secp_224r1(void);
50
+ const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_secp_256r1(void);
51
+ const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_secp_384r1(void);
52
+ const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_secp_521r1(void);
53
+
54
+ #ifdef __cplusplus
55
+ }
56
+ #endif
57
+
58
+ #endif /* NETTLE_ECC_CURVE_H_INCLUDED */
include/nettle/ecc.h ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* ecc.h
2
+
3
+ Copyright (C) 2013 Niels Möller
4
+
5
+ This file is part of GNU Nettle.
6
+
7
+ GNU Nettle is free software: you can redistribute it and/or
8
+ modify it under the terms of either:
9
+
10
+ * the GNU Lesser General Public License as published by the Free
11
+ Software Foundation; either version 3 of the License, or (at your
12
+ option) any later version.
13
+
14
+ or
15
+
16
+ * the GNU General Public License as published by the Free
17
+ Software Foundation; either version 2 of the License, or (at your
18
+ option) any later version.
19
+
20
+ or both in parallel, as here.
21
+
22
+ GNU Nettle is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
+ General Public License for more details.
26
+
27
+ You should have received copies of the GNU General Public License and
28
+ the GNU Lesser General Public License along with this program. If
29
+ not, see http://www.gnu.org/licenses/.
30
+ */
31
+
32
+ /* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
33
+
34
+ #ifndef NETTLE_ECC_H_INCLUDED
35
+ #define NETTLE_ECC_H_INCLUDED
36
+
37
+ #include "nettle-types.h"
38
+ #include "bignum.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* Name mangling */
45
+ #define ecc_point_init nettle_ecc_point_init
46
+ #define ecc_point_clear nettle_ecc_point_clear
47
+ #define ecc_point_set nettle_ecc_point_set
48
+ #define ecc_point_get nettle_ecc_point_get
49
+ #define ecc_point_mul nettle_ecc_point_mul
50
+ #define ecc_point_mul_g nettle_ecc_point_mul_g
51
+ #define ecc_scalar_init nettle_ecc_scalar_init
52
+ #define ecc_scalar_clear nettle_ecc_scalar_clear
53
+ #define ecc_scalar_set nettle_ecc_scalar_set
54
+ #define ecc_scalar_get nettle_ecc_scalar_get
55
+ #define ecc_scalar_random nettle_ecc_scalar_random
56
+ #define ecc_point_mul nettle_ecc_point_mul
57
+ #define ecc_bit_size nettle_ecc_bit_size
58
+ #define ecc_size nettle_ecc_size
59
+ #define ecc_size_a nettle_ecc_size_a
60
+ #define ecc_size_j nettle_ecc_size_j
61
+
62
+ struct ecc_curve;
63
+
64
+ /* High level interface, for ECDSA, DH, etc */
65
+
66
+ /* Represents a point on the ECC curve */
67
+ struct ecc_point
68
+ {
69
+ const struct ecc_curve *ecc;
70
+ /* Allocated using the same allocation function as GMP. */
71
+ mp_limb_t *p;
72
+ };
73
+
74
+ /* Represents a non-zero scalar, an element of Z_q^*, where q is the
75
+ group order of the curve. */
76
+ struct ecc_scalar
77
+ {
78
+ const struct ecc_curve *ecc;
79
+ /* Allocated using the same allocation function as GMP. */
80
+ mp_limb_t *p;
81
+ };
82
+
83
+ void
84
+ ecc_point_init (struct ecc_point *p, const struct ecc_curve *ecc);
85
+ void
86
+ ecc_point_clear (struct ecc_point *p);
87
+
88
+ /* Fails and returns zero if the point is not on the curve. */
89
+ int
90
+ ecc_point_set (struct ecc_point *p, const mpz_t x, const mpz_t y);
91
+ void
92
+ ecc_point_get (const struct ecc_point *p, mpz_t x, mpz_t y);
93
+
94
+ void
95
+ ecc_scalar_init (struct ecc_scalar *s, const struct ecc_curve *ecc);
96
+ void
97
+ ecc_scalar_clear (struct ecc_scalar *s);
98
+
99
+ /* Fails and returns zero if the scalar is not in the proper range. */
100
+ int
101
+ ecc_scalar_set (struct ecc_scalar *s, const mpz_t z);
102
+ void
103
+ ecc_scalar_get (const struct ecc_scalar *s, mpz_t z);
104
+ /* Generates a random scalar, suitable as an ECDSA private key or a
105
+ ECDH exponent. */
106
+ void
107
+ ecc_scalar_random (struct ecc_scalar *s,
108
+ void *random_ctx, nettle_random_func *random);
109
+
110
+ /* Computes r = n p */
111
+ void
112
+ ecc_point_mul (struct ecc_point *r, const struct ecc_scalar *n,
113
+ const struct ecc_point *p);
114
+
115
+ /* Computes r = n g */
116
+ void
117
+ ecc_point_mul_g (struct ecc_point *r, const struct ecc_scalar *n);
118
+
119
+
120
+ /* Low-level interface */
121
+
122
+ /* Points on a curve are represented as arrays of mp_limb_t, with
123
+ curve-specific representation. For the secp curves, we use Jacobian
124
+ coordinates (possibly in Montgomery form for mod multiplication).
125
+ For curve25519 we use homogeneous coordinates on an equivalent
126
+ Edwards curve. The suffix "_h" denotes this internal
127
+ representation.
128
+
129
+ Since we use additive notation for the groups, the infinity point
130
+ on the curve is denoted 0. The infinity point can be represented
131
+ with x = y = 0 in affine coordinates, and Z = 0 in Jacobian
132
+ coordinates. However, note that most of the ECC functions do *not*
133
+ support infinity as an input or output.
134
+ */
135
+
136
+ /* Returns the bit size of a single coordinate (and of the prime p). */
137
+ unsigned
138
+ ecc_bit_size (const struct ecc_curve *ecc);
139
+
140
+ /* Returns the size of a single coordinate. */
141
+ mp_size_t
142
+ ecc_size (const struct ecc_curve *ecc);
143
+
144
+ /* Size of a point, using affine coordinates x, y. */
145
+ mp_size_t
146
+ ecc_size_a (const struct ecc_curve *ecc);
147
+
148
+ /* Size of a point, using jacobian coordinates X, Y and Z. */
149
+ mp_size_t
150
+ ecc_size_j (const struct ecc_curve *ecc);
151
+
152
+ /* FIXME: Define a generic ecc_dup, ecc_add, for any type of curve. Do
153
+ they need to handle infinity points? */
154
+
155
+ #ifdef __cplusplus
156
+ }
157
+ #endif
158
+
159
+ #endif /* NETTLE_ECC_H_INCLUDED */
include/nettle/ecdsa.h ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* ecdsa.h
2
+
3
+ Copyright (C) 2013 Niels Möller
4
+
5
+ This file is part of GNU Nettle.
6
+
7
+ GNU Nettle is free software: you can redistribute it and/or
8
+ modify it under the terms of either:
9
+
10
+ * the GNU Lesser General Public License as published by the Free
11
+ Software Foundation; either version 3 of the License, or (at your
12
+ option) any later version.
13
+
14
+ or
15
+
16
+ * the GNU General Public License as published by the Free
17
+ Software Foundation; either version 2 of the License, or (at your
18
+ option) any later version.
19
+
20
+ or both in parallel, as here.
21
+
22
+ GNU Nettle is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
+ General Public License for more details.
26
+
27
+ You should have received copies of the GNU General Public License and
28
+ the GNU Lesser General Public License along with this program. If
29
+ not, see http://www.gnu.org/licenses/.
30
+ */
31
+
32
+ /* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
33
+
34
+ #ifndef NETTLE_ECDSA_H_INCLUDED
35
+ #define NETTLE_ECDSA_H_INCLUDED
36
+
37
+ #include "ecc.h"
38
+ #include "dsa.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* Name mangling */
45
+ #define ecdsa_sign nettle_ecdsa_sign
46
+ #define ecdsa_verify nettle_ecdsa_verify
47
+ #define ecdsa_generate_keypair nettle_ecdsa_generate_keypair
48
+ #define ecc_ecdsa_sign nettle_ecc_ecdsa_sign
49
+ #define ecc_ecdsa_sign_itch nettle_ecc_ecdsa_sign_itch
50
+ #define ecc_ecdsa_verify nettle_ecc_ecdsa_verify
51
+ #define ecc_ecdsa_verify_itch nettle_ecc_ecdsa_verify_itch
52
+
53
+ /* High level ECDSA functions.
54
+ *
55
+ * A public key is represented as a struct ecc_point, and a private
56
+ * key as a struct ecc_scalar. FIXME: Introduce some aliases? */
57
+ void
58
+ ecdsa_sign (const struct ecc_scalar *key,
59
+ void *random_ctx, nettle_random_func *random,
60
+ size_t digest_length,
61
+ const uint8_t *digest,
62
+ struct dsa_signature *signature);
63
+
64
+ int
65
+ ecdsa_verify (const struct ecc_point *pub,
66
+ size_t length, const uint8_t *digest,
67
+ const struct dsa_signature *signature);
68
+
69
+ void
70
+ ecdsa_generate_keypair (struct ecc_point *pub,
71
+ struct ecc_scalar *key,
72
+ void *random_ctx, nettle_random_func *random);
73
+
74
+ /* Low-level ECDSA functions. */
75
+ mp_size_t
76
+ ecc_ecdsa_sign_itch (const struct ecc_curve *ecc);
77
+
78
+ void
79
+ ecc_ecdsa_sign (const struct ecc_curve *ecc,
80
+ const mp_limb_t *zp,
81
+ /* Random nonce, must be invertible mod ecc group
82
+ order. */
83
+ const mp_limb_t *kp,
84
+ size_t length, const uint8_t *digest,
85
+ mp_limb_t *rp, mp_limb_t *sp,
86
+ mp_limb_t *scratch);
87
+
88
+ mp_size_t
89
+ ecc_ecdsa_verify_itch (const struct ecc_curve *ecc);
90
+
91
+ int
92
+ ecc_ecdsa_verify (const struct ecc_curve *ecc,
93
+ const mp_limb_t *pp, /* Public key */
94
+ size_t length, const uint8_t *digest,
95
+ const mp_limb_t *rp, const mp_limb_t *sp,
96
+ mp_limb_t *scratch);
97
+
98
+
99
+ #ifdef __cplusplus
100
+ }
101
+ #endif
102
+
103
+ #endif /* NETTLE_ECDSA_H_INCLUDED */
include/nettle/eddsa.h ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* eddsa.h
2
+
3
+ Copyright (C) 2014 Niels Möller
4
+
5
+ This file is part of GNU Nettle.
6
+
7
+ GNU Nettle is free software: you can redistribute it and/or
8
+ modify it under the terms of either:
9
+
10
+ * the GNU Lesser General Public License as published by the Free
11
+ Software Foundation; either version 3 of the License, or (at your
12
+ option) any later version.
13
+
14
+ or
15
+
16
+ * the GNU General Public License as published by the Free
17
+ Software Foundation; either version 2 of the License, or (at your
18
+ option) any later version.
19
+
20
+ or both in parallel, as here.
21
+
22
+ GNU Nettle is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
+ General Public License for more details.
26
+
27
+ You should have received copies of the GNU General Public License and
28
+ the GNU Lesser General Public License along with this program. If
29
+ not, see http://www.gnu.org/licenses/.
30
+ */
31
+
32
+ #ifndef NETTLE_EDDSA_H
33
+ #define NETTLE_EDDSA_H
34
+
35
+ #include "nettle-types.h"
36
+
37
+ #include "bignum.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /* Name mangling */
44
+ #define ed25519_sha512_set_private_key nettle_ed25519_sha512_set_private_key
45
+ #define ed25519_sha512_public_key nettle_ed25519_sha512_public_key
46
+ #define ed25519_sha512_sign nettle_ed25519_sha512_sign
47
+ #define ed25519_sha512_verify nettle_ed25519_sha512_verify
48
+ #define ed448_shake256_public_key nettle_ed448_shake256_public_key
49
+ #define ed448_shake256_sign nettle_ed448_shake256_sign
50
+ #define ed448_shake256_verify nettle_ed448_shake256_verify
51
+
52
+ #define ED25519_KEY_SIZE 32
53
+ #define ED25519_SIGNATURE_SIZE 64
54
+
55
+ void
56
+ ed25519_sha512_public_key (uint8_t *pub, const uint8_t *priv);
57
+
58
+ void
59
+ ed25519_sha512_sign (const uint8_t *pub,
60
+ const uint8_t *priv,
61
+ size_t length, const uint8_t *msg,
62
+ uint8_t *signature);
63
+
64
+ int
65
+ ed25519_sha512_verify (const uint8_t *pub,
66
+ size_t length, const uint8_t *msg,
67
+ const uint8_t *signature);
68
+
69
+ #define ED448_KEY_SIZE 57
70
+ #define ED448_SIGNATURE_SIZE 114
71
+
72
+ void
73
+ ed448_shake256_public_key (uint8_t *pub, const uint8_t *priv);
74
+
75
+ void
76
+ ed448_shake256_sign (const uint8_t *pub,
77
+ const uint8_t *priv,
78
+ size_t length, const uint8_t *msg,
79
+ uint8_t *signature);
80
+
81
+ int
82
+ ed448_shake256_verify (const uint8_t *pub,
83
+ size_t length, const uint8_t *msg,
84
+ const uint8_t *signature);
85
+
86
+ #ifdef __cplusplus
87
+ }
88
+ #endif
89
+
90
+ #endif /* NETTLE_EDDSA_H */
include/nettle/gcm.h ADDED
@@ -0,0 +1,330 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* gcm.h
2
+
3
+ Galois counter mode, specified by NIST,
4
+ http://csrc.nist.gov/publications/nistpubs/800-38D/SP-800-38D.pdf
5
+
6
+ Copyright (C) 2011 Katholieke Universiteit Leuven
7
+ Copyright (C) 2011, 2014 Niels Möller
8
+
9
+ Contributed by Nikos Mavrogiannopoulos
10
+
11
+ This file is part of GNU Nettle.
12
+
13
+ GNU Nettle is free software: you can redistribute it and/or
14
+ modify it under the terms of either:
15
+
16
+ * the GNU Lesser General Public License as published by the Free
17
+ Software Foundation; either version 3 of the License, or (at your
18
+ option) any later version.
19
+
20
+ or
21
+
22
+ * the GNU General Public License as published by the Free
23
+ Software Foundation; either version 2 of the License, or (at your
24
+ option) any later version.
25
+
26
+ or both in parallel, as here.
27
+
28
+ GNU Nettle is distributed in the hope that it will be useful,
29
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
30
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31
+ General Public License for more details.
32
+
33
+ You should have received copies of the GNU General Public License and
34
+ the GNU Lesser General Public License along with this program. If
35
+ not, see http://www.gnu.org/licenses/.
36
+ */
37
+
38
+ #ifndef NETTLE_GCM_H_INCLUDED
39
+ #define NETTLE_GCM_H_INCLUDED
40
+
41
+ #include "aes.h"
42
+ #include "camellia.h"
43
+
44
+ #ifdef __cplusplus
45
+ extern "C" {
46
+ #endif
47
+
48
+ /* Name mangling */
49
+ #define gcm_set_key nettle_gcm_set_key
50
+ #define gcm_set_iv nettle_gcm_set_iv
51
+ #define gcm_update nettle_gcm_update
52
+ #define gcm_encrypt nettle_gcm_encrypt
53
+ #define gcm_decrypt nettle_gcm_decrypt
54
+ #define gcm_digest nettle_gcm_digest
55
+
56
+ #define gcm_aes128_set_key nettle_gcm_aes128_set_key
57
+ #define gcm_aes128_set_iv nettle_gcm_aes128_set_iv
58
+ #define gcm_aes128_update nettle_gcm_aes128_update
59
+ #define gcm_aes128_encrypt nettle_gcm_aes128_encrypt
60
+ #define gcm_aes128_decrypt nettle_gcm_aes128_decrypt
61
+ #define gcm_aes128_digest nettle_gcm_aes128_digest
62
+
63
+ #define gcm_aes192_set_key nettle_gcm_aes192_set_key
64
+ #define gcm_aes192_set_iv nettle_gcm_aes192_set_iv
65
+ #define gcm_aes192_update nettle_gcm_aes192_update
66
+ #define gcm_aes192_encrypt nettle_gcm_aes192_encrypt
67
+ #define gcm_aes192_decrypt nettle_gcm_aes192_decrypt
68
+ #define gcm_aes192_digest nettle_gcm_aes192_digest
69
+
70
+ #define gcm_aes256_set_key nettle_gcm_aes256_set_key
71
+ #define gcm_aes256_set_iv nettle_gcm_aes256_set_iv
72
+ #define gcm_aes256_update nettle_gcm_aes256_update
73
+ #define gcm_aes256_encrypt nettle_gcm_aes256_encrypt
74
+ #define gcm_aes256_decrypt nettle_gcm_aes256_decrypt
75
+ #define gcm_aes256_digest nettle_gcm_aes256_digest
76
+
77
+ #define gcm_aes_set_key nettle_gcm_aes_set_key
78
+ #define gcm_aes_set_iv nettle_gcm_aes_set_iv
79
+ #define gcm_aes_update nettle_gcm_aes_update
80
+ #define gcm_aes_encrypt nettle_gcm_aes_encrypt
81
+ #define gcm_aes_decrypt nettle_gcm_aes_decrypt
82
+ #define gcm_aes_digest nettle_gcm_aes_digest
83
+
84
+ #define gcm_camellia128_set_key nettle_gcm_camellia128_set_key
85
+ #define gcm_camellia128_set_iv nettle_gcm_camellia128_set_iv
86
+ #define gcm_camellia128_update nettle_gcm_camellia128_update
87
+ #define gcm_camellia128_encrypt nettle_gcm_camellia128_encrypt
88
+ #define gcm_camellia128_decrypt nettle_gcm_camellia128_decrypt
89
+ #define gcm_camellia128_digest nettle_gcm_camellia128_digest
90
+
91
+ #define gcm_camellia256_set_key nettle_gcm_camellia256_set_key
92
+ #define gcm_camellia256_set_iv nettle_gcm_camellia256_set_iv
93
+ #define gcm_camellia256_update nettle_gcm_camellia256_update
94
+ #define gcm_camellia256_encrypt nettle_gcm_camellia256_encrypt
95
+ #define gcm_camellia256_decrypt nettle_gcm_camellia256_decrypt
96
+ #define gcm_camellia256_digest nettle_gcm_camellia256_digest
97
+
98
+ #define GCM_BLOCK_SIZE 16
99
+ #define GCM_IV_SIZE (GCM_BLOCK_SIZE - 4)
100
+ #define GCM_DIGEST_SIZE 16
101
+ #define GCM_TABLE_BITS 8
102
+
103
+ /* Hashing subkey */
104
+ struct gcm_key
105
+ {
106
+ union nettle_block16 h[1 << GCM_TABLE_BITS];
107
+ };
108
+
109
+ /* Per-message state, depending on the iv */
110
+ struct gcm_ctx {
111
+ /* Original counter block */
112
+ union nettle_block16 iv;
113
+ /* Updated for each block. */
114
+ union nettle_block16 ctr;
115
+ /* Hashing state */
116
+ union nettle_block16 x;
117
+ uint64_t auth_size;
118
+ uint64_t data_size;
119
+ };
120
+
121
+ void
122
+ gcm_set_key(struct gcm_key *key,
123
+ const void *cipher, nettle_cipher_func *f);
124
+
125
+ void
126
+ gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key,
127
+ size_t length, const uint8_t *iv);
128
+
129
+ void
130
+ gcm_update(struct gcm_ctx *ctx, const struct gcm_key *key,
131
+ size_t length, const uint8_t *data);
132
+
133
+ void
134
+ gcm_encrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
135
+ const void *cipher, nettle_cipher_func *f,
136
+ size_t length, uint8_t *dst, const uint8_t *src);
137
+
138
+ void
139
+ gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
140
+ const void *cipher, nettle_cipher_func *f,
141
+ size_t length, uint8_t *dst, const uint8_t *src);
142
+
143
+ void
144
+ gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key,
145
+ const void *cipher, nettle_cipher_func *f,
146
+ size_t length, uint8_t *digest);
147
+
148
+ /* Convenience macrology (not sure how useful it is) */
149
+ /* All-in-one context, with hash subkey, message state, and cipher. */
150
+ #define GCM_CTX(type) \
151
+ { struct gcm_key key; struct gcm_ctx gcm; type cipher; }
152
+
153
+ /* NOTE: Avoid using NULL, as we don't include anything defining it. */
154
+ #define GCM_SET_KEY(ctx, set_key, encrypt, gcm_key) \
155
+ do { \
156
+ (set_key)(&(ctx)->cipher, (gcm_key)); \
157
+ if (0) (encrypt)(&(ctx)->cipher, ~(size_t) 0, \
158
+ (uint8_t *) 0, (const uint8_t *) 0); \
159
+ gcm_set_key(&(ctx)->key, &(ctx)->cipher, \
160
+ (nettle_cipher_func *) (encrypt)); \
161
+ } while (0)
162
+
163
+ #define GCM_SET_IV(ctx, length, data) \
164
+ gcm_set_iv(&(ctx)->gcm, &(ctx)->key, (length), (data))
165
+
166
+ #define GCM_UPDATE(ctx, length, data) \
167
+ gcm_update(&(ctx)->gcm, &(ctx)->key, (length), (data))
168
+
169
+ #define GCM_ENCRYPT(ctx, encrypt, length, dst, src) \
170
+ (0 ? (encrypt)(&(ctx)->cipher, ~(size_t) 0, \
171
+ (uint8_t *) 0, (const uint8_t *) 0) \
172
+ : gcm_encrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
173
+ (nettle_cipher_func *) (encrypt), \
174
+ (length), (dst), (src)))
175
+
176
+ #define GCM_DECRYPT(ctx, encrypt, length, dst, src) \
177
+ (0 ? (encrypt)(&(ctx)->cipher, ~(size_t) 0, \
178
+ (uint8_t *) 0, (const uint8_t *) 0) \
179
+ : gcm_decrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
180
+ (nettle_cipher_func *) (encrypt), \
181
+ (length), (dst), (src)))
182
+
183
+ #define GCM_DIGEST(ctx, encrypt, length, digest) \
184
+ (0 ? (encrypt)(&(ctx)->cipher, ~(size_t) 0, \
185
+ (uint8_t *) 0, (const uint8_t *) 0) \
186
+ : gcm_digest(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
187
+ (nettle_cipher_func *) (encrypt), \
188
+ (length), (digest)))
189
+
190
+ struct gcm_aes128_ctx GCM_CTX(struct aes128_ctx);
191
+
192
+ void
193
+ gcm_aes128_set_key(struct gcm_aes128_ctx *ctx, const uint8_t *key);
194
+
195
+ /* FIXME: Define _update and _set_iv as some kind of aliaes,
196
+ there's nothing aes-specific. */
197
+ void
198
+ gcm_aes128_update (struct gcm_aes128_ctx *ctx,
199
+ size_t length, const uint8_t *data);
200
+ void
201
+ gcm_aes128_set_iv (struct gcm_aes128_ctx *ctx,
202
+ size_t length, const uint8_t *iv);
203
+
204
+ void
205
+ gcm_aes128_encrypt(struct gcm_aes128_ctx *ctx,
206
+ size_t length, uint8_t *dst, const uint8_t *src);
207
+
208
+ void
209
+ gcm_aes128_decrypt(struct gcm_aes128_ctx *ctx,
210
+ size_t length, uint8_t *dst, const uint8_t *src);
211
+
212
+ void
213
+ gcm_aes128_digest(struct gcm_aes128_ctx *ctx,
214
+ size_t length, uint8_t *digest);
215
+
216
+ struct gcm_aes192_ctx GCM_CTX(struct aes192_ctx);
217
+
218
+ void
219
+ gcm_aes192_set_key(struct gcm_aes192_ctx *ctx, const uint8_t *key);
220
+
221
+ void
222
+ gcm_aes192_update (struct gcm_aes192_ctx *ctx,
223
+ size_t length, const uint8_t *data);
224
+ void
225
+ gcm_aes192_set_iv (struct gcm_aes192_ctx *ctx,
226
+ size_t length, const uint8_t *iv);
227
+
228
+ void
229
+ gcm_aes192_encrypt(struct gcm_aes192_ctx *ctx,
230
+ size_t length, uint8_t *dst, const uint8_t *src);
231
+
232
+ void
233
+ gcm_aes192_decrypt(struct gcm_aes192_ctx *ctx,
234
+ size_t length, uint8_t *dst, const uint8_t *src);
235
+
236
+ void
237
+ gcm_aes192_digest(struct gcm_aes192_ctx *ctx,
238
+ size_t length, uint8_t *digest);
239
+
240
+ struct gcm_aes256_ctx GCM_CTX(struct aes256_ctx);
241
+
242
+ void
243
+ gcm_aes256_set_key(struct gcm_aes256_ctx *ctx, const uint8_t *key);
244
+
245
+ void
246
+ gcm_aes256_update (struct gcm_aes256_ctx *ctx,
247
+ size_t length, const uint8_t *data);
248
+ void
249
+ gcm_aes256_set_iv (struct gcm_aes256_ctx *ctx,
250
+ size_t length, const uint8_t *iv);
251
+
252
+ void
253
+ gcm_aes256_encrypt(struct gcm_aes256_ctx *ctx,
254
+ size_t length, uint8_t *dst, const uint8_t *src);
255
+
256
+ void
257
+ gcm_aes256_decrypt(struct gcm_aes256_ctx *ctx,
258
+ size_t length, uint8_t *dst, const uint8_t *src);
259
+
260
+ void
261
+ gcm_aes256_digest(struct gcm_aes256_ctx *ctx,
262
+ size_t length, uint8_t *digest);
263
+
264
+ /* Old deprecated aes interface, for backwards compatibility */
265
+ struct gcm_aes_ctx GCM_CTX(struct aes_ctx);
266
+
267
+ void
268
+ gcm_aes_set_key(struct gcm_aes_ctx *ctx,
269
+ size_t length, const uint8_t *key) _NETTLE_ATTRIBUTE_DEPRECATED;
270
+
271
+ void
272
+ gcm_aes_set_iv(struct gcm_aes_ctx *ctx,
273
+ size_t length, const uint8_t *iv) _NETTLE_ATTRIBUTE_DEPRECATED;
274
+
275
+ void
276
+ gcm_aes_update(struct gcm_aes_ctx *ctx,
277
+ size_t length, const uint8_t *data) _NETTLE_ATTRIBUTE_DEPRECATED;
278
+
279
+ void
280
+ gcm_aes_encrypt(struct gcm_aes_ctx *ctx,
281
+ size_t length, uint8_t *dst, const uint8_t *src)
282
+ _NETTLE_ATTRIBUTE_DEPRECATED;
283
+
284
+ void
285
+ gcm_aes_decrypt(struct gcm_aes_ctx *ctx,
286
+ size_t length, uint8_t *dst, const uint8_t *src)
287
+ _NETTLE_ATTRIBUTE_DEPRECATED;
288
+
289
+ void
290
+ gcm_aes_digest(struct gcm_aes_ctx *ctx, size_t length, uint8_t *digest)
291
+ _NETTLE_ATTRIBUTE_DEPRECATED;
292
+
293
+
294
+ struct gcm_camellia128_ctx GCM_CTX(struct camellia128_ctx);
295
+
296
+ void gcm_camellia128_set_key(struct gcm_camellia128_ctx *ctx,
297
+ const uint8_t *key);
298
+ void gcm_camellia128_set_iv(struct gcm_camellia128_ctx *ctx,
299
+ size_t length, const uint8_t *iv);
300
+ void gcm_camellia128_update(struct gcm_camellia128_ctx *ctx,
301
+ size_t length, const uint8_t *data);
302
+ void gcm_camellia128_encrypt(struct gcm_camellia128_ctx *ctx,
303
+ size_t length, uint8_t *dst, const uint8_t *src);
304
+ void gcm_camellia128_decrypt(struct gcm_camellia128_ctx *ctx,
305
+ size_t length, uint8_t *dst, const uint8_t *src);
306
+ void gcm_camellia128_digest(struct gcm_camellia128_ctx *ctx,
307
+ size_t length, uint8_t *digest);
308
+
309
+
310
+ struct gcm_camellia256_ctx GCM_CTX(struct camellia256_ctx);
311
+
312
+ void gcm_camellia256_set_key(struct gcm_camellia256_ctx *ctx,
313
+ const uint8_t *key);
314
+ void gcm_camellia256_set_iv(struct gcm_camellia256_ctx *ctx,
315
+ size_t length, const uint8_t *iv);
316
+ void gcm_camellia256_update(struct gcm_camellia256_ctx *ctx,
317
+ size_t length, const uint8_t *data);
318
+ void gcm_camellia256_encrypt(struct gcm_camellia256_ctx *ctx,
319
+ size_t length, uint8_t *dst, const uint8_t *src);
320
+ void gcm_camellia256_decrypt(struct gcm_camellia256_ctx *ctx,
321
+ size_t length, uint8_t *dst, const uint8_t *src);
322
+ void gcm_camellia256_digest(struct gcm_camellia256_ctx *ctx,
323
+ size_t length, uint8_t *digest);
324
+
325
+
326
+ #ifdef __cplusplus
327
+ }
328
+ #endif
329
+
330
+ #endif /* NETTLE_GCM_H_INCLUDED */
include/nettle/gostdsa.h ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* gostdsa.h
2
+
3
+ Copyright (C) 2015 Dmity Eremin-Solenikov
4
+ Copyright (C) 2013 Niels Möller
5
+
6
+ This file is part of GNU Nettle.
7
+
8
+ GNU Nettle is free software: you can redistribute it and/or
9
+ modify it under the terms of either:
10
+
11
+ * the GNU Lesser General Public License as published by the Free
12
+ Software Foundation; either version 3 of the License, or (at your
13
+ option) any later version.
14
+
15
+ or
16
+
17
+ * the GNU General Public License as published by the Free
18
+ Software Foundation; either version 2 of the License, or (at your
19
+ option) any later version.
20
+
21
+ or both in parallel, as here.
22
+
23
+ GNU Nettle is distributed in the hope that it will be useful,
24
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26
+ General Public License for more details.
27
+
28
+ You should have received copies of the GNU General Public License and
29
+ the GNU Lesser General Public License along with this program. If
30
+ not, see http://www.gnu.org/licenses/.
31
+ */
32
+
33
+ #ifndef NETTLE_GOSTDSA_H_INCLUDED
34
+ #define NETTLE_GOSTDSA_H_INCLUDED
35
+
36
+ #include "ecc.h"
37
+ #include "dsa.h"
38
+ #include "ecdsa.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* Name mangling */
45
+ #define gostdsa_sign nettle_gostdsa_sign
46
+ #define gostdsa_verify nettle_gostdsa_verify
47
+ #define gostdsa_vko nettle_gostdsa_vko
48
+ #define ecc_gostdsa_sign nettle_ecc_gostdsa_sign
49
+ #define ecc_gostdsa_sign_itch nettle_ecc_gostdsa_sign_itch
50
+ #define ecc_gostdsa_verify nettle_ecc_gostdsa_verify
51
+ #define ecc_gostdsa_verify_itch nettle_ecc_gostdsa_verify_itch
52
+
53
+ /* Just use ECDSA function for key generation */
54
+ #define gostdsa_generate_keypair ecdsa_generate_keypair
55
+
56
+ /* High level GOST DSA functions.
57
+ *
58
+ * A public key is represented as a struct ecc_point, and a private
59
+ * key as a struct ecc_scalar. FIXME: Introduce some aliases? */
60
+ void
61
+ gostdsa_sign (const struct ecc_scalar *key,
62
+ void *random_ctx, nettle_random_func *random,
63
+ size_t digest_length,
64
+ const uint8_t *digest,
65
+ struct dsa_signature *signature);
66
+
67
+ int
68
+ gostdsa_verify (const struct ecc_point *pub,
69
+ size_t length, const uint8_t *digest,
70
+ const struct dsa_signature *signature);
71
+
72
+ void
73
+ gostdsa_vko (const struct ecc_scalar *key,
74
+ const struct ecc_point *pub,
75
+ size_t ukm_length, const uint8_t *ukm,
76
+ uint8_t *out);
77
+
78
+ /* Low-level GOSTDSA functions. */
79
+ mp_size_t
80
+ ecc_gostdsa_sign_itch (const struct ecc_curve *ecc);
81
+
82
+ void
83
+ ecc_gostdsa_sign (const struct ecc_curve *ecc,
84
+ const mp_limb_t *zp,
85
+ /* Random nonce, must be invertible mod ecc group
86
+ order. */
87
+ const mp_limb_t *kp,
88
+ size_t length, const uint8_t *digest,
89
+ mp_limb_t *rp, mp_limb_t *sp,
90
+ mp_limb_t *scratch);
91
+
92
+ mp_size_t
93
+ ecc_gostdsa_verify_itch (const struct ecc_curve *ecc);
94
+
95
+ int
96
+ ecc_gostdsa_verify (const struct ecc_curve *ecc,
97
+ const mp_limb_t *pp, /* Public key */
98
+ size_t length, const uint8_t *digest,
99
+ const mp_limb_t *rp, const mp_limb_t *sp,
100
+ mp_limb_t *scratch);
101
+
102
+
103
+ #ifdef __cplusplus
104
+ }
105
+ #endif
106
+
107
+ #endif /* NETTLE_GOSTDSA_H_INCLUDED */
include/nettle/gosthash94.h ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* gosthash94.h
2
+
3
+ The GOST R 34.11-94 hash function, described in RFC 5831.
4
+
5
+ Copyright (C) 2012 Nikos Mavrogiannopoulos, Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ /* Based on rhash gost.h. */
35
+
36
+ /* Copyright: 2009-2012 Aleksey Kravchenko <rhash.admin@gmail.com>
37
+ *
38
+ * Permission is hereby granted, free of charge, to any person obtaining a
39
+ * copy of this software and associated documentation files (the
40
+ * "Software"), to deal in the Software without restriction, including
41
+ * without limitation the rights to use, copy, modify, merge, publish,
42
+ * distribute, sublicense, and/or sell copies of the Software, and to
43
+ * permit persons to whom the Software is furnished to do so, subject to
44
+ * the following conditions:
45
+ *
46
+ * The above copyright notice and this permission notice shall be included
47
+ * in all copies or substantial portions of the Software.
48
+ *
49
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
50
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
52
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
53
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
54
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
55
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56
+ */
57
+
58
+ /*
59
+ * Ported to nettle by Nikos Mavrogiannopoulos.
60
+ */
61
+
62
+ #ifndef NETTLE_GOSTHASH94_H_INCLUDED
63
+ #define NETTLE_GOSTHASH94_H_INCLUDED
64
+
65
+ #include "nettle-types.h"
66
+
67
+ #ifdef __cplusplus
68
+ extern "C" {
69
+ #endif
70
+
71
+ #define gosthash94_init nettle_gosthash94_init
72
+ #define gosthash94_update nettle_gosthash94_update
73
+ #define gosthash94_digest nettle_gosthash94_digest
74
+
75
+ #define gosthash94cp_update nettle_gosthash94cp_update
76
+ #define gosthash94cp_digest nettle_gosthash94cp_digest
77
+
78
+ #define GOSTHASH94_BLOCK_SIZE 32
79
+ #define GOSTHASH94_DIGEST_SIZE 32
80
+ /* For backwards compatibility */
81
+ #define GOSTHASH94_DATA_SIZE GOSTHASH94_BLOCK_SIZE
82
+
83
+ #define GOSTHASH94CP_BLOCK_SIZE GOSTHASH94_BLOCK_SIZE
84
+ #define GOSTHASH94CP_DIGEST_SIZE GOSTHASH94_DIGEST_SIZE
85
+
86
+ struct gosthash94_ctx
87
+ {
88
+ uint32_t hash[8]; /* algorithm 256-bit state */
89
+ uint32_t sum[8]; /* sum of processed message blocks */
90
+ uint64_t count; /* Block count */
91
+ unsigned index; /* Into buffer */
92
+ uint8_t block[GOSTHASH94_BLOCK_SIZE]; /* 256-bit buffer for leftovers */
93
+ };
94
+ #define gosthash94cp_ctx gosthash94_ctx
95
+
96
+ void gosthash94_init(struct gosthash94_ctx *ctx);
97
+ void gosthash94_update(struct gosthash94_ctx *ctx,
98
+ size_t length, const uint8_t *msg);
99
+ void gosthash94_digest(struct gosthash94_ctx *ctx,
100
+ size_t length, uint8_t *result);
101
+
102
+ #define gosthash94cp_init gosthash94_init
103
+ void gosthash94cp_update(struct gosthash94_ctx *ctx,
104
+ size_t length, const uint8_t *msg);
105
+ void gosthash94cp_digest(struct gosthash94_ctx *ctx,
106
+ size_t length, uint8_t *result);
107
+
108
+ #ifdef __cplusplus
109
+ }
110
+ #endif
111
+
112
+ #endif /* NETTLE_GOSTHASH94_H_INCLUDED */
include/nettle/hkdf.h ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* hkdf.h
2
+
3
+ TLS PRF code (RFC-5246, RFC-2246).
4
+
5
+ Copyright (C) 2017 Red Hat, Inc.
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_HKDF_H_INCLUDED
35
+ #define NETTLE_HKDF_H_INCLUDED
36
+
37
+ #include "nettle-types.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /* Namespace mangling */
44
+ #define hkdf_extract nettle_hkdf_extract
45
+ #define hkdf_expand nettle_hkdf_expand
46
+
47
+ void
48
+ hkdf_extract(void *mac_ctx,
49
+ nettle_hash_update_func *update,
50
+ nettle_hash_digest_func *digest,
51
+ size_t digest_size,
52
+ size_t secret_size, const uint8_t *secret,
53
+ uint8_t *dst);
54
+
55
+ void
56
+ hkdf_expand(void *mac_ctx,
57
+ nettle_hash_update_func *update,
58
+ nettle_hash_digest_func *digest,
59
+ size_t digest_size,
60
+ size_t info_size, const uint8_t *info,
61
+ size_t length, uint8_t *dst);
62
+
63
+ #ifdef __cplusplus
64
+ }
65
+ #endif
66
+
67
+ #endif /* NETTLE_HKDF_H_INCLUDED */
include/nettle/hmac.h ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* hmac.h
2
+
3
+ HMAC message authentication code (RFC-2104).
4
+
5
+ Copyright (C) 2001, 2002 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_HMAC_H_INCLUDED
35
+ #define NETTLE_HMAC_H_INCLUDED
36
+
37
+ #include "nettle-meta.h"
38
+
39
+ #include "gosthash94.h"
40
+ #include "md5.h"
41
+ #include "ripemd160.h"
42
+ #include "sha1.h"
43
+ #include "sha2.h"
44
+ #include "streebog.h"
45
+
46
+ #ifdef __cplusplus
47
+ extern "C" {
48
+ #endif
49
+
50
+ /* Namespace mangling */
51
+ #define hmac_set_key nettle_hmac_set_key
52
+ #define hmac_update nettle_hmac_update
53
+ #define hmac_digest nettle_hmac_digest
54
+ #define hmac_md5_set_key nettle_hmac_md5_set_key
55
+ #define hmac_md5_update nettle_hmac_md5_update
56
+ #define hmac_md5_digest nettle_hmac_md5_digest
57
+ #define hmac_ripemd160_set_key nettle_hmac_ripemd160_set_key
58
+ #define hmac_ripemd160_update nettle_hmac_ripemd160_update
59
+ #define hmac_ripemd160_digest nettle_hmac_ripemd160_digest
60
+ #define hmac_sha1_set_key nettle_hmac_sha1_set_key
61
+ #define hmac_sha1_update nettle_hmac_sha1_update
62
+ #define hmac_sha1_digest nettle_hmac_sha1_digest
63
+ #define hmac_sha224_set_key nettle_hmac_sha224_set_key
64
+ #define hmac_sha224_digest nettle_hmac_sha224_digest
65
+ #define hmac_sha256_set_key nettle_hmac_sha256_set_key
66
+ #define hmac_sha256_update nettle_hmac_sha256_update
67
+ #define hmac_sha256_digest nettle_hmac_sha256_digest
68
+ #define hmac_sha384_set_key nettle_hmac_sha384_set_key
69
+ #define hmac_sha384_digest nettle_hmac_sha384_digest
70
+ #define hmac_sha512_set_key nettle_hmac_sha512_set_key
71
+ #define hmac_sha512_update nettle_hmac_sha512_update
72
+ #define hmac_sha512_digest nettle_hmac_sha512_digest
73
+ #define hmac_gosthash94_set_key nettle_hmac_gosthash94_set_key
74
+ #define hmac_gosthash94_update nettle_hmac_gosthash94_update
75
+ #define hmac_gosthash94_digest nettle_hmac_gosthash94_digest
76
+ #define hmac_gosthash94cp_set_key nettle_hmac_gosthash94cp_set_key
77
+ #define hmac_gosthash94cp_update nettle_hmac_gosthash94cp_update
78
+ #define hmac_gosthash94cp_digest nettle_hmac_gosthash94cp_digest
79
+ #define hmac_streebog256_set_key nettle_hmac_streebog256_set_key
80
+ #define hmac_streebog256_digest nettle_hmac_streebog256_digest
81
+ #define hmac_streebog512_set_key nettle_hmac_streebog512_set_key
82
+ #define hmac_streebog512_update nettle_hmac_streebog512_update
83
+ #define hmac_streebog512_digest nettle_hmac_streebog512_digest
84
+
85
+ void
86
+ hmac_set_key(void *outer, void *inner, void *state,
87
+ const struct nettle_hash *hash,
88
+ size_t length, const uint8_t *key);
89
+
90
+ /* This function is not strictly needed, it's s just the same as the
91
+ * hash update function. */
92
+ void
93
+ hmac_update(void *state,
94
+ const struct nettle_hash *hash,
95
+ size_t length, const uint8_t *data);
96
+
97
+ void
98
+ hmac_digest(const void *outer, const void *inner, void *state,
99
+ const struct nettle_hash *hash,
100
+ size_t length, uint8_t *digest);
101
+
102
+
103
+ #define HMAC_CTX(type) \
104
+ { type outer; type inner; type state; }
105
+
106
+ #define HMAC_SET_KEY(ctx, hash, length, key) \
107
+ hmac_set_key( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
108
+ (hash), (length), (key) )
109
+
110
+ #define HMAC_DIGEST(ctx, hash, length, digest) \
111
+ hmac_digest( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
112
+ (hash), (length), (digest) )
113
+
114
+ /* HMAC using specific hash functions */
115
+
116
+ /* hmac-md5 */
117
+ struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
118
+
119
+ void
120
+ hmac_md5_set_key(struct hmac_md5_ctx *ctx,
121
+ size_t key_length, const uint8_t *key);
122
+
123
+ void
124
+ hmac_md5_update(struct hmac_md5_ctx *ctx,
125
+ size_t length, const uint8_t *data);
126
+
127
+ void
128
+ hmac_md5_digest(struct hmac_md5_ctx *ctx,
129
+ size_t length, uint8_t *digest);
130
+
131
+
132
+ /* hmac-ripemd160 */
133
+ struct hmac_ripemd160_ctx HMAC_CTX(struct ripemd160_ctx);
134
+
135
+ void
136
+ hmac_ripemd160_set_key(struct hmac_ripemd160_ctx *ctx,
137
+ size_t key_length, const uint8_t *key);
138
+
139
+ void
140
+ hmac_ripemd160_update(struct hmac_ripemd160_ctx *ctx,
141
+ size_t length, const uint8_t *data);
142
+
143
+ void
144
+ hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx,
145
+ size_t length, uint8_t *digest);
146
+
147
+
148
+ /* hmac-sha1 */
149
+ struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx);
150
+
151
+ void
152
+ hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
153
+ size_t key_length, const uint8_t *key);
154
+
155
+ void
156
+ hmac_sha1_update(struct hmac_sha1_ctx *ctx,
157
+ size_t length, const uint8_t *data);
158
+
159
+ void
160
+ hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
161
+ size_t length, uint8_t *digest);
162
+
163
+ /* hmac-sha256 */
164
+ struct hmac_sha256_ctx HMAC_CTX(struct sha256_ctx);
165
+
166
+ void
167
+ hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
168
+ size_t key_length, const uint8_t *key);
169
+
170
+ void
171
+ hmac_sha256_update(struct hmac_sha256_ctx *ctx,
172
+ size_t length, const uint8_t *data);
173
+
174
+ void
175
+ hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
176
+ size_t length, uint8_t *digest);
177
+
178
+ /* hmac-sha224 */
179
+ #define hmac_sha224_ctx hmac_sha256_ctx
180
+
181
+ void
182
+ hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
183
+ size_t key_length, const uint8_t *key);
184
+
185
+ #define hmac_sha224_update nettle_hmac_sha256_update
186
+
187
+ void
188
+ hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
189
+ size_t length, uint8_t *digest);
190
+
191
+ /* hmac-sha512 */
192
+ struct hmac_sha512_ctx HMAC_CTX(struct sha512_ctx);
193
+
194
+ void
195
+ hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
196
+ size_t key_length, const uint8_t *key);
197
+
198
+ void
199
+ hmac_sha512_update(struct hmac_sha512_ctx *ctx,
200
+ size_t length, const uint8_t *data);
201
+
202
+ void
203
+ hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
204
+ size_t length, uint8_t *digest);
205
+
206
+ /* hmac-sha384 */
207
+ #define hmac_sha384_ctx hmac_sha512_ctx
208
+
209
+ void
210
+ hmac_sha384_set_key(struct hmac_sha512_ctx *ctx,
211
+ size_t key_length, const uint8_t *key);
212
+
213
+ #define hmac_sha384_update nettle_hmac_sha512_update
214
+
215
+ void
216
+ hmac_sha384_digest(struct hmac_sha512_ctx *ctx,
217
+ size_t length, uint8_t *digest);
218
+
219
+ /* hmac-gosthash94 */
220
+ struct hmac_gosthash94_ctx HMAC_CTX(struct gosthash94_ctx);
221
+
222
+ void
223
+ hmac_gosthash94_set_key(struct hmac_gosthash94_ctx *ctx,
224
+ size_t key_length, const uint8_t *key);
225
+
226
+ void
227
+ hmac_gosthash94_update(struct hmac_gosthash94_ctx *ctx,
228
+ size_t length, const uint8_t *data);
229
+
230
+ void
231
+ hmac_gosthash94_digest(struct hmac_gosthash94_ctx *ctx,
232
+ size_t length, uint8_t *digest);
233
+
234
+ struct hmac_gosthash94cp_ctx HMAC_CTX(struct gosthash94cp_ctx);
235
+
236
+ void
237
+ hmac_gosthash94cp_set_key(struct hmac_gosthash94cp_ctx *ctx,
238
+ size_t key_length, const uint8_t *key);
239
+
240
+ void
241
+ hmac_gosthash94cp_update(struct hmac_gosthash94cp_ctx *ctx,
242
+ size_t length, const uint8_t *data);
243
+
244
+ void
245
+ hmac_gosthash94cp_digest(struct hmac_gosthash94cp_ctx *ctx,
246
+ size_t length, uint8_t *digest);
247
+
248
+
249
+ /* hmac-streebog */
250
+ struct hmac_streebog512_ctx HMAC_CTX(struct streebog512_ctx);
251
+
252
+ void
253
+ hmac_streebog512_set_key(struct hmac_streebog512_ctx *ctx,
254
+ size_t key_length, const uint8_t *key);
255
+
256
+ void
257
+ hmac_streebog512_update(struct hmac_streebog512_ctx *ctx,
258
+ size_t length, const uint8_t *data);
259
+
260
+ void
261
+ hmac_streebog512_digest(struct hmac_streebog512_ctx *ctx,
262
+ size_t length, uint8_t *digest);
263
+
264
+ #define hmac_streebog256_ctx hmac_streebog512_ctx
265
+
266
+ void
267
+ hmac_streebog256_set_key(struct hmac_streebog256_ctx *ctx,
268
+ size_t key_length, const uint8_t *key);
269
+
270
+ #define hmac_streebog256_update hmac_streebog512_update
271
+
272
+ void
273
+ hmac_streebog256_digest(struct hmac_streebog256_ctx *ctx,
274
+ size_t length, uint8_t *digest);
275
+
276
+ #ifdef __cplusplus
277
+ }
278
+ #endif
279
+
280
+ #endif /* NETTLE_HMAC_H_INCLUDED */
include/nettle/knuth-lfib.h ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* knuth-lfib.h
2
+
3
+ The "lagged fibonacci" pseudorandomness generator, described in
4
+ Knuth, TAoCP, 3.6
5
+
6
+ This file is part of GNU Nettle.
7
+
8
+ GNU Nettle is free software: you can redistribute it and/or
9
+ modify it under the terms of either:
10
+
11
+ * the GNU Lesser General Public License as published by the Free
12
+ Software Foundation; either version 3 of the License, or (at your
13
+ option) any later version.
14
+
15
+ or
16
+
17
+ * the GNU General Public License as published by the Free
18
+ Software Foundation; either version 2 of the License, or (at your
19
+ option) any later version.
20
+
21
+ or both in parallel, as here.
22
+
23
+ GNU Nettle is distributed in the hope that it will be useful,
24
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26
+ General Public License for more details.
27
+
28
+ You should have received copies of the GNU General Public License and
29
+ the GNU Lesser General Public License along with this program. If
30
+ not, see http://www.gnu.org/licenses/.
31
+ */
32
+
33
+ /* NOTE: This generator is totally inappropriate for cryptographic
34
+ * applications. It is useful for generating deterministic but
35
+ * random-looking test data, and is used by the Nettle testsuite. */
36
+ #ifndef NETTLE_KNUTH_LFIB_H_INCLUDED
37
+ #define NETTLE_KNUTH_LFIB_H_INCLUDED
38
+
39
+ #include "nettle-types.h"
40
+
41
+ #ifdef __cplusplus
42
+ extern "C" {
43
+ #endif
44
+
45
+ /* Namespace mangling */
46
+ #define knuth_lfib_init nettle_knuth_lfib_init
47
+ #define knuth_lfib_get nettle_knuth_lfib_get
48
+ #define knuth_lfib_get_array nettle_knuth_lfib_get_array
49
+ #define knuth_lfib_random nettle_knuth_lfib_random
50
+
51
+ #define _KNUTH_LFIB_KK 100
52
+
53
+ struct knuth_lfib_ctx
54
+ {
55
+ uint32_t x[_KNUTH_LFIB_KK];
56
+ unsigned index;
57
+ };
58
+
59
+ void
60
+ knuth_lfib_init(struct knuth_lfib_ctx *ctx, uint32_t seed);
61
+
62
+ /* Get's a single number in the range 0 ... 2^30-1 */
63
+ uint32_t
64
+ knuth_lfib_get(struct knuth_lfib_ctx *ctx);
65
+
66
+ /* Get an array of numbers */
67
+ void
68
+ knuth_lfib_get_array(struct knuth_lfib_ctx *ctx,
69
+ size_t n, uint32_t *a);
70
+
71
+ /* Get an array of octets. */
72
+ void
73
+ knuth_lfib_random(struct knuth_lfib_ctx *ctx,
74
+ size_t n, uint8_t *dst);
75
+
76
+ #ifdef __cplusplus
77
+ }
78
+ #endif
79
+
80
+ #endif /* NETTLE_KNUTH_LFIB_H_INCLUDED */
include/nettle/macros.h ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* macros.h
2
+
3
+ Copyright (C) 2001, 2010 Niels Möller
4
+
5
+ This file is part of GNU Nettle.
6
+
7
+ GNU Nettle is free software: you can redistribute it and/or
8
+ modify it under the terms of either:
9
+
10
+ * the GNU Lesser General Public License as published by the Free
11
+ Software Foundation; either version 3 of the License, or (at your
12
+ option) any later version.
13
+
14
+ or
15
+
16
+ * the GNU General Public License as published by the Free
17
+ Software Foundation; either version 2 of the License, or (at your
18
+ option) any later version.
19
+
20
+ or both in parallel, as here.
21
+
22
+ GNU Nettle is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
+ General Public License for more details.
26
+
27
+ You should have received copies of the GNU General Public License and
28
+ the GNU Lesser General Public License along with this program. If
29
+ not, see http://www.gnu.org/licenses/.
30
+ */
31
+
32
+ #ifndef NETTLE_MACROS_H_INCLUDED
33
+ #define NETTLE_MACROS_H_INCLUDED
34
+
35
+ /* Reads a 64-bit integer, in network, big-endian, byte order */
36
+ #define READ_UINT64(p) \
37
+ ( (((uint64_t) (p)[0]) << 56) \
38
+ | (((uint64_t) (p)[1]) << 48) \
39
+ | (((uint64_t) (p)[2]) << 40) \
40
+ | (((uint64_t) (p)[3]) << 32) \
41
+ | (((uint64_t) (p)[4]) << 24) \
42
+ | (((uint64_t) (p)[5]) << 16) \
43
+ | (((uint64_t) (p)[6]) << 8) \
44
+ | ((uint64_t) (p)[7]))
45
+
46
+ #define WRITE_UINT64(p, i) \
47
+ do { \
48
+ (p)[0] = ((i) >> 56) & 0xff; \
49
+ (p)[1] = ((i) >> 48) & 0xff; \
50
+ (p)[2] = ((i) >> 40) & 0xff; \
51
+ (p)[3] = ((i) >> 32) & 0xff; \
52
+ (p)[4] = ((i) >> 24) & 0xff; \
53
+ (p)[5] = ((i) >> 16) & 0xff; \
54
+ (p)[6] = ((i) >> 8) & 0xff; \
55
+ (p)[7] = (i) & 0xff; \
56
+ } while(0)
57
+
58
+ /* Reads a 32-bit integer, in network, big-endian, byte order */
59
+ #define READ_UINT32(p) \
60
+ ( (((uint32_t) (p)[0]) << 24) \
61
+ | (((uint32_t) (p)[1]) << 16) \
62
+ | (((uint32_t) (p)[2]) << 8) \
63
+ | ((uint32_t) (p)[3]))
64
+
65
+ #define WRITE_UINT32(p, i) \
66
+ do { \
67
+ (p)[0] = ((i) >> 24) & 0xff; \
68
+ (p)[1] = ((i) >> 16) & 0xff; \
69
+ (p)[2] = ((i) >> 8) & 0xff; \
70
+ (p)[3] = (i) & 0xff; \
71
+ } while(0)
72
+
73
+ /* Analogous macros, for 24 and 16 bit numbers */
74
+ #define READ_UINT24(p) \
75
+ ( (((uint32_t) (p)[0]) << 16) \
76
+ | (((uint32_t) (p)[1]) << 8) \
77
+ | ((uint32_t) (p)[2]))
78
+
79
+ #define WRITE_UINT24(p, i) \
80
+ do { \
81
+ (p)[0] = ((i) >> 16) & 0xff; \
82
+ (p)[1] = ((i) >> 8) & 0xff; \
83
+ (p)[2] = (i) & 0xff; \
84
+ } while(0)
85
+
86
+ #define READ_UINT16(p) \
87
+ ( (((uint32_t) (p)[0]) << 8) \
88
+ | ((uint32_t) (p)[1]))
89
+
90
+ #define WRITE_UINT16(p, i) \
91
+ do { \
92
+ (p)[0] = ((i) >> 8) & 0xff; \
93
+ (p)[1] = (i) & 0xff; \
94
+ } while(0)
95
+
96
+ /* And the other, little-endian, byteorder */
97
+ #define LE_READ_UINT64(p) \
98
+ ( (((uint64_t) (p)[7]) << 56) \
99
+ | (((uint64_t) (p)[6]) << 48) \
100
+ | (((uint64_t) (p)[5]) << 40) \
101
+ | (((uint64_t) (p)[4]) << 32) \
102
+ | (((uint64_t) (p)[3]) << 24) \
103
+ | (((uint64_t) (p)[2]) << 16) \
104
+ | (((uint64_t) (p)[1]) << 8) \
105
+ | ((uint64_t) (p)[0]))
106
+
107
+ #define LE_WRITE_UINT64(p, i) \
108
+ do { \
109
+ (p)[7] = ((i) >> 56) & 0xff; \
110
+ (p)[6] = ((i) >> 48) & 0xff; \
111
+ (p)[5] = ((i) >> 40) & 0xff; \
112
+ (p)[4] = ((i) >> 32) & 0xff; \
113
+ (p)[3] = ((i) >> 24) & 0xff; \
114
+ (p)[2] = ((i) >> 16) & 0xff; \
115
+ (p)[1] = ((i) >> 8) & 0xff; \
116
+ (p)[0] = (i) & 0xff; \
117
+ } while (0)
118
+
119
+ #define LE_READ_UINT32(p) \
120
+ ( (((uint32_t) (p)[3]) << 24) \
121
+ | (((uint32_t) (p)[2]) << 16) \
122
+ | (((uint32_t) (p)[1]) << 8) \
123
+ | ((uint32_t) (p)[0]))
124
+
125
+ #define LE_WRITE_UINT32(p, i) \
126
+ do { \
127
+ (p)[3] = ((i) >> 24) & 0xff; \
128
+ (p)[2] = ((i) >> 16) & 0xff; \
129
+ (p)[1] = ((i) >> 8) & 0xff; \
130
+ (p)[0] = (i) & 0xff; \
131
+ } while(0)
132
+
133
+ /* Analogous macros, for 16 bit numbers */
134
+ #define LE_READ_UINT16(p) \
135
+ ( (((uint32_t) (p)[1]) << 8) \
136
+ | ((uint32_t) (p)[0]))
137
+
138
+ #define LE_WRITE_UINT16(p, i) \
139
+ do { \
140
+ (p)[1] = ((i) >> 8) & 0xff; \
141
+ (p)[0] = (i) & 0xff; \
142
+ } while(0)
143
+
144
+ /* Macro to make it easier to loop over several blocks. */
145
+ #define FOR_BLOCKS(length, dst, src, blocksize) \
146
+ assert( !((length) % (blocksize))); \
147
+ for (; (length); ((length) -= (blocksize), \
148
+ (dst) += (blocksize), \
149
+ (src) += (blocksize)) )
150
+
151
+ /* The masking of the right shift is needed to allow n == 0 (using
152
+ just 32 - n and 64 - n results in undefined behaviour). Most uses
153
+ of these macros use a constant and non-zero rotation count. */
154
+ #define ROTL32(n,x) (((x)<<(n)) | ((x)>>((-(n)&31))))
155
+
156
+ #define ROTL64(n,x) (((x)<<(n)) | ((x)>>((-(n))&63)))
157
+
158
+ /* Requires that size > 0 */
159
+ #define INCREMENT(size, ctr) \
160
+ do { \
161
+ unsigned increment_i = (size) - 1; \
162
+ if (++(ctr)[increment_i] == 0) \
163
+ while (increment_i > 0 \
164
+ && ++(ctr)[--increment_i] == 0 ) \
165
+ ; \
166
+ } while (0)
167
+
168
+
169
+ /* Helper macro for Merkle-Damgård hash functions. Assumes the context
170
+ structs includes the following fields:
171
+
172
+ uint8_t block[...]; // Buffer holding one block
173
+ unsigned int index; // Index into block
174
+ */
175
+
176
+ /* Currently used by sha512 (and sha384) only. */
177
+ #define MD_INCR(ctx) ((ctx)->count_high += !++(ctx)->count_low)
178
+
179
+ /* Takes the compression function f as argument. NOTE: also clobbers
180
+ length and data. */
181
+ #define MD_UPDATE(ctx, length, data, f, incr) \
182
+ do { \
183
+ if ((ctx)->index) \
184
+ { \
185
+ /* Try to fill partial block */ \
186
+ unsigned __md_left = sizeof((ctx)->block) - (ctx)->index; \
187
+ if ((length) < __md_left) \
188
+ { \
189
+ memcpy((ctx)->block + (ctx)->index, (data), (length)); \
190
+ (ctx)->index += (length); \
191
+ goto __md_done; /* Finished */ \
192
+ } \
193
+ else \
194
+ { \
195
+ memcpy((ctx)->block + (ctx)->index, (data), __md_left); \
196
+ \
197
+ f((ctx), (ctx)->block); \
198
+ (incr); \
199
+ \
200
+ (data) += __md_left; \
201
+ (length) -= __md_left; \
202
+ } \
203
+ } \
204
+ while ((length) >= sizeof((ctx)->block)) \
205
+ { \
206
+ f((ctx), (data)); \
207
+ (incr); \
208
+ \
209
+ (data) += sizeof((ctx)->block); \
210
+ (length) -= sizeof((ctx)->block); \
211
+ } \
212
+ memcpy ((ctx)->block, (data), (length)); \
213
+ (ctx)->index = (length); \
214
+ __md_done: \
215
+ ; \
216
+ } while (0)
217
+
218
+ /* Pads the block to a block boundary with the bit pattern 1 0*,
219
+ leaving size octets for the length field at the end. If needed,
220
+ compresses the block and starts a new one. */
221
+ #define MD_PAD(ctx, size, f) \
222
+ do { \
223
+ unsigned __md_i; \
224
+ __md_i = (ctx)->index; \
225
+ \
226
+ /* Set the first char of padding to 0x80. This is safe since there \
227
+ is always at least one byte free */ \
228
+ \
229
+ assert(__md_i < sizeof((ctx)->block)); \
230
+ (ctx)->block[__md_i++] = 0x80; \
231
+ \
232
+ if (__md_i > (sizeof((ctx)->block) - (size))) \
233
+ { /* No room for length in this block. Process it and \
234
+ pad with another one */ \
235
+ memset((ctx)->block + __md_i, 0, sizeof((ctx)->block) - __md_i); \
236
+ \
237
+ f((ctx), (ctx)->block); \
238
+ __md_i = 0; \
239
+ } \
240
+ memset((ctx)->block + __md_i, 0, \
241
+ sizeof((ctx)->block) - (size) - __md_i); \
242
+ \
243
+ } while (0)
244
+
245
+ #endif /* NETTLE_MACROS_H_INCLUDED */
include/nettle/memxor.h ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* memxor.h
2
+ *
3
+ */
4
+
5
+ #ifndef NETTLE_MEMXOR_H_INCLUDED
6
+ #define NETTLE_MEMXOR_H_INCLUDED
7
+
8
+ #include <stdlib.h>
9
+
10
+ #ifdef __cplusplus
11
+ extern "C" {
12
+ #endif
13
+
14
+ /* Name mangling */
15
+ #define memxor nettle_memxor
16
+ #define memxor3 nettle_memxor3
17
+
18
+ void *memxor(void *dst, const void *src, size_t n);
19
+ void *memxor3(void *dst, const void *a, const void *b, size_t n);
20
+
21
+ #ifdef __cplusplus
22
+ }
23
+ #endif
24
+
25
+ #endif /* NETTLE_MEMXOR_H_INCLUDED */
include/nettle/nettle-meta.h ADDED
@@ -0,0 +1,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* nettle-meta.h
2
+
3
+ Information about algorithms.
4
+
5
+ Copyright (C) 2002, 2014, 2020 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_META_H_INCLUDED
35
+ #define NETTLE_META_H_INCLUDED
36
+
37
+ #include "nettle-types.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+
44
+ struct nettle_cipher
45
+ {
46
+ const char *name;
47
+
48
+ unsigned context_size;
49
+
50
+ /* Zero for stream ciphers */
51
+ unsigned block_size;
52
+
53
+ /* Suggested key size; other sizes are sometimes possible. */
54
+ unsigned key_size;
55
+
56
+ nettle_set_key_func *set_encrypt_key;
57
+ nettle_set_key_func *set_decrypt_key;
58
+
59
+ nettle_cipher_func *encrypt;
60
+ nettle_cipher_func *decrypt;
61
+ };
62
+
63
+ /* null-terminated list of ciphers implemented by this version of nettle */
64
+ const struct nettle_cipher * const * _NETTLE_ATTRIBUTE_PURE
65
+ nettle_get_ciphers (void);
66
+
67
+ #define nettle_ciphers (nettle_get_ciphers())
68
+
69
+ extern const struct nettle_cipher nettle_aes128;
70
+ extern const struct nettle_cipher nettle_aes192;
71
+ extern const struct nettle_cipher nettle_aes256;
72
+
73
+ extern const struct nettle_cipher nettle_camellia128;
74
+ extern const struct nettle_cipher nettle_camellia192;
75
+ extern const struct nettle_cipher nettle_camellia256;
76
+
77
+ extern const struct nettle_cipher nettle_cast128;
78
+
79
+ extern const struct nettle_cipher nettle_serpent128;
80
+ extern const struct nettle_cipher nettle_serpent192;
81
+ extern const struct nettle_cipher nettle_serpent256;
82
+
83
+ extern const struct nettle_cipher nettle_twofish128;
84
+ extern const struct nettle_cipher nettle_twofish192;
85
+ extern const struct nettle_cipher nettle_twofish256;
86
+
87
+ extern const struct nettle_cipher nettle_arctwo40;
88
+ extern const struct nettle_cipher nettle_arctwo64;
89
+ extern const struct nettle_cipher nettle_arctwo128;
90
+ extern const struct nettle_cipher nettle_arctwo_gutmann128;
91
+
92
+ struct nettle_hash
93
+ {
94
+ const char *name;
95
+
96
+ /* Size of the context struct */
97
+ unsigned context_size;
98
+
99
+ /* Size of digests */
100
+ unsigned digest_size;
101
+
102
+ /* Internal block size */
103
+ unsigned block_size;
104
+
105
+ nettle_hash_init_func *init;
106
+ nettle_hash_update_func *update;
107
+ nettle_hash_digest_func *digest;
108
+ };
109
+
110
+ #define _NETTLE_HASH(name, NAME) { \
111
+ #name, \
112
+ sizeof(struct name##_ctx), \
113
+ NAME##_DIGEST_SIZE, \
114
+ NAME##_BLOCK_SIZE, \
115
+ (nettle_hash_init_func *) name##_init, \
116
+ (nettle_hash_update_func *) name##_update, \
117
+ (nettle_hash_digest_func *) name##_digest \
118
+ }
119
+
120
+ /* null-terminated list of digests implemented by this version of nettle */
121
+ const struct nettle_hash * const * _NETTLE_ATTRIBUTE_PURE
122
+ nettle_get_hashes (void);
123
+
124
+ #define nettle_hashes (nettle_get_hashes())
125
+
126
+ const struct nettle_hash *
127
+ nettle_lookup_hash (const char *name);
128
+
129
+ extern const struct nettle_hash nettle_md2;
130
+ extern const struct nettle_hash nettle_md4;
131
+ extern const struct nettle_hash nettle_md5;
132
+ extern const struct nettle_hash nettle_gosthash94;
133
+ extern const struct nettle_hash nettle_gosthash94cp;
134
+ extern const struct nettle_hash nettle_ripemd160;
135
+ extern const struct nettle_hash nettle_sha1;
136
+ extern const struct nettle_hash nettle_sha224;
137
+ extern const struct nettle_hash nettle_sha256;
138
+ extern const struct nettle_hash nettle_sha384;
139
+ extern const struct nettle_hash nettle_sha512;
140
+ extern const struct nettle_hash nettle_sha512_224;
141
+ extern const struct nettle_hash nettle_sha512_256;
142
+ extern const struct nettle_hash nettle_sha3_224;
143
+ extern const struct nettle_hash nettle_sha3_256;
144
+ extern const struct nettle_hash nettle_sha3_384;
145
+ extern const struct nettle_hash nettle_sha3_512;
146
+ extern const struct nettle_hash nettle_streebog256;
147
+ extern const struct nettle_hash nettle_streebog512;
148
+
149
+ struct nettle_mac
150
+ {
151
+ const char *name;
152
+
153
+ /* Size of the context struct */
154
+ unsigned context_size;
155
+
156
+ /* Size of digests */
157
+ unsigned digest_size;
158
+
159
+ /* Key size */
160
+ unsigned key_size;
161
+
162
+ nettle_set_key_func *set_key;
163
+ nettle_hash_update_func *update;
164
+ nettle_hash_digest_func *digest;
165
+ };
166
+
167
+ struct nettle_aead
168
+ {
169
+ const char *name;
170
+
171
+ unsigned context_size;
172
+ /* Block size for encrypt and decrypt. */
173
+ unsigned block_size;
174
+ unsigned key_size;
175
+ unsigned nonce_size;
176
+ unsigned digest_size;
177
+
178
+ nettle_set_key_func *set_encrypt_key;
179
+ nettle_set_key_func *set_decrypt_key;
180
+ nettle_set_key_func *set_nonce;
181
+ nettle_hash_update_func *update;
182
+ nettle_crypt_func *encrypt;
183
+ nettle_crypt_func *decrypt;
184
+ /* FIXME: Drop length argument? */
185
+ nettle_hash_digest_func *digest;
186
+ };
187
+
188
+ /* null-terminated list of aead constructions implemented by this
189
+ version of nettle */
190
+ const struct nettle_aead * const * _NETTLE_ATTRIBUTE_PURE
191
+ nettle_get_aeads (void);
192
+
193
+ #define nettle_aeads (nettle_get_aeads())
194
+
195
+ extern const struct nettle_aead nettle_gcm_aes128;
196
+ extern const struct nettle_aead nettle_gcm_aes192;
197
+ extern const struct nettle_aead nettle_gcm_aes256;
198
+ extern const struct nettle_aead nettle_gcm_camellia128;
199
+ extern const struct nettle_aead nettle_gcm_camellia256;
200
+ extern const struct nettle_aead nettle_eax_aes128;
201
+ extern const struct nettle_aead nettle_chacha_poly1305;
202
+
203
+ struct nettle_armor
204
+ {
205
+ const char *name;
206
+ unsigned encode_context_size;
207
+ unsigned decode_context_size;
208
+
209
+ unsigned encode_final_length;
210
+
211
+ nettle_armor_init_func *encode_init;
212
+ nettle_armor_length_func *encode_length;
213
+ nettle_armor_encode_update_func *encode_update;
214
+ nettle_armor_encode_final_func *encode_final;
215
+
216
+ nettle_armor_init_func *decode_init;
217
+ nettle_armor_length_func *decode_length;
218
+ nettle_armor_decode_update_func *decode_update;
219
+ nettle_armor_decode_final_func *decode_final;
220
+ };
221
+
222
+ #define _NETTLE_ARMOR(name, NAME) { \
223
+ #name, \
224
+ sizeof(struct name##_encode_ctx), \
225
+ sizeof(struct name##_decode_ctx), \
226
+ NAME##_ENCODE_FINAL_LENGTH, \
227
+ (nettle_armor_init_func *) name##_encode_init, \
228
+ (nettle_armor_length_func *) name##_encode_length, \
229
+ (nettle_armor_encode_update_func *) name##_encode_update, \
230
+ (nettle_armor_encode_final_func *) name##_encode_final, \
231
+ (nettle_armor_init_func *) name##_decode_init, \
232
+ (nettle_armor_length_func *) name##_decode_length, \
233
+ (nettle_armor_decode_update_func *) name##_decode_update, \
234
+ (nettle_armor_decode_final_func *) name##_decode_final, \
235
+ }
236
+
237
+ #define _NETTLE_ARMOR_0(name, NAME) { \
238
+ #name, \
239
+ 0, \
240
+ sizeof(struct name##_decode_ctx), \
241
+ NAME##_ENCODE_FINAL_LENGTH, \
242
+ (nettle_armor_init_func *) name##_encode_init, \
243
+ (nettle_armor_length_func *) name##_encode_length, \
244
+ (nettle_armor_encode_update_func *) name##_encode_update, \
245
+ (nettle_armor_encode_final_func *) name##_encode_final, \
246
+ (nettle_armor_init_func *) name##_decode_init, \
247
+ (nettle_armor_length_func *) name##_decode_length, \
248
+ (nettle_armor_decode_update_func *) name##_decode_update, \
249
+ (nettle_armor_decode_final_func *) name##_decode_final, \
250
+ }
251
+
252
+ /* null-terminated list of armor schemes implemented by this version of nettle */
253
+ const struct nettle_armor * const * _NETTLE_ATTRIBUTE_PURE
254
+ nettle_get_armors (void);
255
+
256
+ #define nettle_armors (nettle_get_armors())
257
+
258
+ extern const struct nettle_armor nettle_base64;
259
+ extern const struct nettle_armor nettle_base64url;
260
+ extern const struct nettle_armor nettle_base16;
261
+
262
+ #define _NETTLE_HMAC(name, HASH) { \
263
+ #name, \
264
+ sizeof(struct name##_ctx), \
265
+ HASH##_DIGEST_SIZE, \
266
+ HASH##_DIGEST_SIZE, \
267
+ name##_set_key_wrapper, \
268
+ (nettle_hash_update_func *) name##_update, \
269
+ (nettle_hash_digest_func *) name##_digest, \
270
+ }
271
+
272
+ /* null-terminated list of macs implemented by this
273
+ version of nettle */
274
+ const struct nettle_mac * const * _NETTLE_ATTRIBUTE_PURE
275
+ nettle_get_macs (void);
276
+
277
+ #define nettle_macs (nettle_get_macs())
278
+
279
+ extern const struct nettle_mac nettle_cmac_aes128;
280
+ extern const struct nettle_mac nettle_cmac_aes256;
281
+ extern const struct nettle_mac nettle_cmac_des3;
282
+
283
+ /* HMAC variants with key size = digest size */
284
+ extern const struct nettle_mac nettle_hmac_md5;
285
+ extern const struct nettle_mac nettle_hmac_ripemd160;
286
+ extern const struct nettle_mac nettle_hmac_sha1;
287
+ extern const struct nettle_mac nettle_hmac_sha224;
288
+ extern const struct nettle_mac nettle_hmac_sha256;
289
+ extern const struct nettle_mac nettle_hmac_sha384;
290
+ extern const struct nettle_mac nettle_hmac_sha512;
291
+ extern const struct nettle_mac nettle_hmac_streebog256;
292
+ extern const struct nettle_mac nettle_hmac_streebog512;
293
+
294
+ #ifdef __cplusplus
295
+ }
296
+ #endif
297
+
298
+ #endif /* NETTLE_META_H_INCLUDED */
include/nettle/nettle-types.h ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* nettle-types.h
2
+
3
+ Copyright (C) 2005, 2014 Niels Möller
4
+
5
+ This file is part of GNU Nettle.
6
+
7
+ GNU Nettle is free software: you can redistribute it and/or
8
+ modify it under the terms of either:
9
+
10
+ * the GNU Lesser General Public License as published by the Free
11
+ Software Foundation; either version 3 of the License, or (at your
12
+ option) any later version.
13
+
14
+ or
15
+
16
+ * the GNU General Public License as published by the Free
17
+ Software Foundation; either version 2 of the License, or (at your
18
+ option) any later version.
19
+
20
+ or both in parallel, as here.
21
+
22
+ GNU Nettle is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
+ General Public License for more details.
26
+
27
+ You should have received copies of the GNU General Public License and
28
+ the GNU Lesser General Public License along with this program. If
29
+ not, see http://www.gnu.org/licenses/.
30
+ */
31
+
32
+ #ifndef NETTLE_TYPES_H
33
+ #define NETTLE_TYPES_H
34
+
35
+ /* For size_t */
36
+ #include <stddef.h>
37
+ #include <stdint.h>
38
+
39
+ /* Attributes we want to use in installed header files, and hence
40
+ can't rely on config.h. */
41
+ #ifdef __GNUC__
42
+
43
+ #define _NETTLE_ATTRIBUTE_PURE __attribute__((pure))
44
+ #ifndef _NETTLE_ATTRIBUTE_DEPRECATED
45
+ /* Variant without message is supported since gcc-3.1 or so. */
46
+ #define _NETTLE_ATTRIBUTE_DEPRECATED __attribute__((deprecated))
47
+ #endif
48
+
49
+ #else /* !__GNUC__ */
50
+
51
+ #define _NETTLE_ATTRIBUTE_PURE
52
+ #define _NETTLE_ATTRIBUTE_DEPRECATED
53
+
54
+ #endif /* !__GNUC__ */
55
+
56
+ #ifdef __cplusplus
57
+ extern "C" {
58
+ #endif
59
+
60
+ /* An aligned 16-byte block. */
61
+ union nettle_block16
62
+ {
63
+ uint8_t b[16];
64
+ unsigned long w[16 / sizeof(unsigned long)] _NETTLE_ATTRIBUTE_DEPRECATED;
65
+ uint64_t u64[2];
66
+ };
67
+
68
+ union nettle_block8
69
+ {
70
+ uint8_t b[8];
71
+ uint64_t u64;
72
+ };
73
+
74
+ /* Randomness. Used by key generation and dsa signature creation. */
75
+ typedef void nettle_random_func(void *ctx,
76
+ size_t length, uint8_t *dst);
77
+
78
+ /* Progress report function, mainly for key generation. */
79
+ typedef void nettle_progress_func(void *ctx, int c);
80
+
81
+ /* Realloc function, used by struct nettle_buffer. */
82
+ typedef void *nettle_realloc_func(void *ctx, void *p, size_t length);
83
+
84
+ /* Ciphers */
85
+ typedef void nettle_set_key_func(void *ctx, const uint8_t *key);
86
+
87
+ /* For block ciphers, const context. */
88
+ typedef void nettle_cipher_func(const void *ctx,
89
+ size_t length, uint8_t *dst,
90
+ const uint8_t *src);
91
+
92
+
93
+ /* Uses a void * for cipher contexts. Used for crypt operations where
94
+ the internal state changes during the encryption. */
95
+ typedef void nettle_crypt_func(void *ctx,
96
+ size_t length, uint8_t *dst,
97
+ const uint8_t *src);
98
+
99
+ /* Hash algorithms */
100
+ typedef void nettle_hash_init_func(void *ctx);
101
+ typedef void nettle_hash_update_func(void *ctx,
102
+ size_t length,
103
+ const uint8_t *src);
104
+ typedef void nettle_hash_digest_func(void *ctx,
105
+ size_t length, uint8_t *dst);
106
+
107
+ /* ASCII armor codecs. NOTE: Experimental and subject to change. */
108
+
109
+ typedef size_t nettle_armor_length_func(size_t length);
110
+ typedef void nettle_armor_init_func(void *ctx);
111
+
112
+ typedef size_t nettle_armor_encode_update_func(void *ctx,
113
+ char *dst,
114
+ size_t src_length,
115
+ const uint8_t *src);
116
+
117
+ typedef size_t nettle_armor_encode_final_func(void *ctx, char *dst);
118
+
119
+ typedef int nettle_armor_decode_update_func(void *ctx,
120
+ size_t *dst_length,
121
+ uint8_t *dst,
122
+ size_t src_length,
123
+ const char *src);
124
+
125
+ typedef int nettle_armor_decode_final_func(void *ctx);
126
+
127
+ #ifdef __cplusplus
128
+ }
129
+ #endif
130
+
131
+ #endif /* NETTLE_TYPES_H */
include/nettle/pbkdf2.h ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* pbkdf2.h
2
+
3
+ PKCS #5 password-based key derivation function PBKDF2, see RFC 2898.
4
+
5
+ Copyright (C) 2012 Simon Josefsson
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_PBKDF2_H_INCLUDED
35
+ #define NETTLE_PBKDF2_H_INCLUDED
36
+
37
+ #include "nettle-meta.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C"
41
+ {
42
+ #endif
43
+
44
+ /* Namespace mangling */
45
+ #define pbkdf2 nettle_pbkdf2
46
+ #define pbkdf2_hmac_sha1 nettle_pbkdf2_hmac_sha1
47
+ #define pbkdf2_hmac_sha256 nettle_pbkdf2_hmac_sha256
48
+ #define pbkdf2_hmac_sha384 nettle_pbkdf2_hmac_sha384
49
+ #define pbkdf2_hmac_sha512 nettle_pbkdf2_hmac_sha512
50
+ #define pbkdf2_hmac_gosthash94cp nettle_pbkdf2_hmac_gosthash94cp
51
+
52
+ void
53
+ pbkdf2 (void *mac_ctx,
54
+ nettle_hash_update_func *update,
55
+ nettle_hash_digest_func *digest,
56
+ size_t digest_size, unsigned iterations,
57
+ size_t salt_length, const uint8_t *salt,
58
+ size_t length, uint8_t *dst);
59
+
60
+ #define PBKDF2(ctx, update, digest, digest_size, \
61
+ iterations, salt_length, salt, length, dst) \
62
+ (0 ? ((update)((ctx), 0, (uint8_t *) 0), \
63
+ (digest)((ctx), 0, (uint8_t *) 0)) \
64
+ : pbkdf2 ((ctx), \
65
+ (nettle_hash_update_func *)(update), \
66
+ (nettle_hash_digest_func *)(digest), \
67
+ (digest_size), (iterations), \
68
+ (salt_length), (salt), (length), (dst)))
69
+
70
+ /* PBKDF2 with specific PRFs. */
71
+
72
+ void
73
+ pbkdf2_hmac_sha1 (size_t key_length, const uint8_t *key,
74
+ unsigned iterations,
75
+ size_t salt_length, const uint8_t *salt,
76
+ size_t length, uint8_t *dst);
77
+
78
+ void
79
+ pbkdf2_hmac_sha256 (size_t key_length, const uint8_t *key,
80
+ unsigned iterations,
81
+ size_t salt_length, const uint8_t *salt,
82
+ size_t length, uint8_t *dst);
83
+
84
+ void
85
+ pbkdf2_hmac_sha384 (size_t key_length, const uint8_t *key,
86
+ unsigned iterations,
87
+ size_t salt_length, const uint8_t *salt,
88
+ size_t length, uint8_t *dst);
89
+
90
+ void
91
+ pbkdf2_hmac_sha512 (size_t key_length, const uint8_t *key,
92
+ unsigned iterations,
93
+ size_t salt_length, const uint8_t *salt,
94
+ size_t length, uint8_t *dst);
95
+
96
+ void
97
+ pbkdf2_hmac_gosthash94cp (size_t key_length, const uint8_t *key,
98
+ unsigned iterations,
99
+ size_t salt_length, const uint8_t *salt,
100
+ size_t length, uint8_t *dst);
101
+
102
+ #ifdef __cplusplus
103
+ }
104
+ #endif
105
+
106
+ #endif /* NETTLE_PBKDF2_H_INCLUDED */
include/nettle/pgp.h ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* pgp.h
2
+
3
+ PGP related functions.
4
+
5
+ Copyright (C) 2001, 2002 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_PGP_H_INCLUDED
35
+ #define NETTLE_PGP_H_INCLUDED
36
+
37
+ #include <time.h>
38
+
39
+ #include "nettle-types.h"
40
+ #include "bignum.h"
41
+
42
+ #ifdef __cplusplus
43
+ extern "C" {
44
+ #endif
45
+
46
+ /* Name mangling */
47
+ #define pgp_put_uint32 nettle_pgp_put_uint32
48
+ #define pgp_put_uint16 nettle_pgp_put_uint16
49
+ #define pgp_put_mpi nettle_pgp_put_mpi
50
+ #define pgp_put_string nettle_pgp_put_string
51
+ #define pgp_put_length nettle_pgp_put_length
52
+ #define pgp_put_header nettle_pgp_put_header
53
+ #define pgp_put_header_length nettle_pgp_put_header_length
54
+ #define pgp_sub_packet_start nettle_pgp_sub_packet_start
55
+ #define pgp_put_sub_packet nettle_pgp_put_sub_packet
56
+ #define pgp_sub_packet_end nettle_pgp_sub_packet_end
57
+ #define pgp_put_public_rsa_key nettle_pgp_put_public_rsa_key
58
+ #define pgp_put_rsa_sha1_signature nettle_pgp_put_rsa_sha1_signature
59
+ #define pgp_put_userid nettle_pgp_put_userid
60
+ #define pgp_crc24 nettle_pgp_crc24
61
+ #define pgp_armor nettle_pgp_armor
62
+
63
+ struct nettle_buffer;
64
+ struct rsa_public_key;
65
+ struct rsa_private_key;
66
+ struct sha1_ctx;
67
+
68
+ int
69
+ pgp_put_uint32(struct nettle_buffer *buffer, uint32_t i);
70
+
71
+ int
72
+ pgp_put_uint16(struct nettle_buffer *buffer, unsigned i);
73
+
74
+ int
75
+ pgp_put_mpi(struct nettle_buffer *buffer, const mpz_t x);
76
+
77
+ int
78
+ pgp_put_string(struct nettle_buffer *buffer,
79
+ unsigned length,
80
+ const uint8_t *s);
81
+
82
+ int
83
+ pgp_put_length(struct nettle_buffer *buffer,
84
+ unsigned length);
85
+
86
+ int
87
+ pgp_put_header(struct nettle_buffer *buffer,
88
+ unsigned tag, unsigned length);
89
+
90
+ void
91
+ pgp_put_header_length(struct nettle_buffer *buffer,
92
+ /* start of the header */
93
+ unsigned start,
94
+ unsigned field_size);
95
+
96
+ unsigned
97
+ pgp_sub_packet_start(struct nettle_buffer *buffer);
98
+
99
+ int
100
+ pgp_put_sub_packet(struct nettle_buffer *buffer,
101
+ unsigned type,
102
+ unsigned length,
103
+ const uint8_t *data);
104
+
105
+ void
106
+ pgp_sub_packet_end(struct nettle_buffer *buffer, unsigned start);
107
+
108
+ int
109
+ pgp_put_public_rsa_key(struct nettle_buffer *,
110
+ const struct rsa_public_key *key,
111
+ time_t timestamp);
112
+
113
+ int
114
+ pgp_put_rsa_sha1_signature(struct nettle_buffer *buffer,
115
+ const struct rsa_private_key *key,
116
+ const uint8_t *keyid,
117
+ unsigned type,
118
+ struct sha1_ctx *hash);
119
+
120
+ int
121
+ pgp_put_userid(struct nettle_buffer *buffer,
122
+ unsigned length,
123
+ const uint8_t *name);
124
+
125
+ uint32_t
126
+ pgp_crc24(unsigned length, const uint8_t *data);
127
+
128
+ int
129
+ pgp_armor(struct nettle_buffer *buffer,
130
+ const char *tag,
131
+ unsigned length,
132
+ const uint8_t *data);
133
+
134
+ /* Values that can be passed to pgp_put_header when the size of the
135
+ * length field, but not the length itself, is known. Also the minimum length
136
+ * for the given field size. */
137
+ enum pgp_lengths
138
+ {
139
+ PGP_LENGTH_ONE_OCTET = 0,
140
+ PGP_LENGTH_TWO_OCTETS = 192,
141
+ PGP_LENGTH_FOUR_OCTETS = 8384,
142
+ };
143
+
144
+ enum pgp_public_key_algorithm
145
+ {
146
+ PGP_RSA = 1,
147
+ PGP_RSA_ENCRYPT = 2,
148
+ PGP_RSA_SIGN = 3,
149
+ PGP_EL_GAMAL_ENCRYPT = 16,
150
+ PGP_DSA = 17,
151
+ PGP_EL_GAMAL = 20,
152
+ };
153
+
154
+ enum pgp_symmetric_algorithm
155
+ {
156
+ PGP_PLAINTEXT = 0,
157
+ PGP_IDEA = 1,
158
+ PGP_3DES = 2,
159
+ PGP_CAST5 = 3,
160
+ PGP_BLOWFISH = 4,
161
+ PGP_SAFER_SK = 5,
162
+ PGP_AES128 = 7,
163
+ PGP_AES192 = 8,
164
+ PGP_AES256 = 9,
165
+ };
166
+
167
+ enum pgp_compression_algorithm
168
+ {
169
+ PGP_UNCOMPRESSED = 0,
170
+ PGP_ZIP = 1,
171
+ PGP_ZLIB = 2,
172
+ };
173
+
174
+ enum pgp_hash_algorithm
175
+ {
176
+ PGP_MD5 = 1,
177
+ PGP_SHA1 = 2,
178
+ PGP_RIPEMD = 3,
179
+ PGP_MD2 = 5,
180
+ PGP_TIGER192 = 6,
181
+ PGP_HAVAL = 7,
182
+ };
183
+
184
+ enum pgp_tag
185
+ {
186
+ PGP_TAG_PUBLIC_SESSION_KEY = 1,
187
+ PGP_TAG_SIGNATURE = 2,
188
+ PGP_TAG_SYMMETRIC_SESSION_KEY = 3,
189
+ PGP_TAG_ONE_PASS_SIGNATURE = 4,
190
+ PGP_TAG_SECRET_KEY = 5,
191
+ PGP_TAG_PUBLIC_KEY = 6,
192
+ PGP_TAG_SECRET_SUBKEY = 7,
193
+ PGP_TAG_COMPRESSED = 8,
194
+ PGP_TAG_ENCRYPTED = 9,
195
+ PGP_TAG_MARKER = 10,
196
+ PGP_TAG_LITERAL = 11,
197
+ PGP_TAG_TRUST = 12,
198
+ PGP_TAG_USERID = 13,
199
+ PGP_TAG_PUBLIC_SUBKEY = 14,
200
+ };
201
+
202
+ enum pgp_signature_type
203
+ {
204
+ PGP_SIGN_BINARY = 0,
205
+ PGP_SIGN_TEXT = 1,
206
+ PGP_SIGN_STANDALONE = 2,
207
+ PGP_SIGN_CERTIFICATION = 0x10,
208
+ PGP_SIGN_CERTIFICATION_PERSONA = 0x11,
209
+ PGP_SIGN_CERTIFICATION_CASUAL = 0x12,
210
+ PGP_SIGN_CERTIFICATION_POSITIVE = 0x13,
211
+ PGP_SIGN_SUBKEY = 0x18,
212
+ PGP_SIGN_KEY = 0x1f,
213
+ PGP_SIGN_REVOCATION = 0x20,
214
+ PGP_SIGN_REVOCATION_SUBKEY = 0x28,
215
+ PGP_SIGN_REVOCATION_CERTIFICATE = 0x30,
216
+ PGP_SIGN_TIMESTAMP = 0x40,
217
+ };
218
+
219
+ enum pgp_subpacket_tag
220
+ {
221
+ PGP_SUBPACKET_CREATION_TIME = 2,
222
+ PGP_SUBPACKET_SIGNATURE_EXPIRATION_TIME = 3,
223
+ PGP_SUBPACKET_EXPORTABLE_CERTIFICATION = 4,
224
+ PGP_SUBPACKET_TRUST_SIGNATURE = 5,
225
+ PGP_SUBPACKET_REGULAR_EXPRESSION = 6,
226
+ PGP_SUBPACKET_REVOCABLE = 7,
227
+ PGP_SUBPACKET_KEY_EXPIRATION_TIME = 9,
228
+ PGP_SUBPACKET_PLACEHOLDER = 10 ,
229
+ PGP_SUBPACKET_PREFERRED_SYMMETRIC_ALGORITHMS = 11,
230
+ PGP_SUBPACKET_REVOCATION_KEY = 12,
231
+ PGP_SUBPACKET_ISSUER_KEY_ID = 16,
232
+ PGP_SUBPACKET_NOTATION_DATA = 20,
233
+ PGP_SUBPACKET_PREFERRED_HASH_ALGORITHMS = 21,
234
+ PGP_SUBPACKET_PREFERRED_COMPRESSION_ALGORITHMS = 22,
235
+ PGP_SUBPACKET_KEY_SERVER_PREFERENCES = 23,
236
+ PGP_SUBPACKET_PREFERRED_KEY_SERVER = 24,
237
+ PGP_SUBPACKET_PRIMARY_USER_ID = 25,
238
+ PGP_SUBPACKET_POLICY_URL = 26,
239
+ PGP_SUBPACKET_KEY_FLAGS = 27,
240
+ PGP_SUBPACKET_SIGNERS_USER_ID = 28,
241
+ PGP_SUBPACKET_REASON_FOR_REVOCATION = 29,
242
+ };
243
+
244
+ #ifdef __cplusplus
245
+ }
246
+ #endif
247
+
248
+ #endif /* NETTLE_PGP_H_INCLUDED */
include/nettle/pkcs1.h ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* pkcs1.h
2
+
3
+ PKCS1 embedding.
4
+
5
+ Copyright (C) 2003 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_PKCS1_H_INCLUDED
35
+ #define NETTLE_PKCS1_H_INCLUDED
36
+
37
+ #include "nettle-types.h"
38
+ #include "bignum.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* Name mangling */
45
+ #define pkcs1_rsa_digest_encode nettle_pkcs1_rsa_digest_encode
46
+ #define pkcs1_rsa_md5_encode nettle_pkcs1_rsa_md5_encode
47
+ #define pkcs1_rsa_md5_encode_digest nettle_pkcs1_rsa_md5_encode_digest
48
+ #define pkcs1_rsa_sha1_encode nettle_pkcs1_rsa_sha1_encode
49
+ #define pkcs1_rsa_sha1_encode_digest nettle_pkcs1_rsa_sha1_encode_digest
50
+ #define pkcs1_rsa_sha256_encode nettle_pkcs1_rsa_sha256_encode
51
+ #define pkcs1_rsa_sha256_encode_digest nettle_pkcs1_rsa_sha256_encode_digest
52
+ #define pkcs1_rsa_sha512_encode nettle_pkcs1_rsa_sha512_encode
53
+ #define pkcs1_rsa_sha512_encode_digest nettle_pkcs1_rsa_sha512_encode_digest
54
+ #define pkcs1_encrypt nettle_pkcs1_encrypt
55
+ #define pkcs1_decrypt nettle_pkcs1_decrypt
56
+
57
+ struct md5_ctx;
58
+ struct sha1_ctx;
59
+ struct sha256_ctx;
60
+ struct sha512_ctx;
61
+
62
+ int
63
+ pkcs1_encrypt (size_t key_size,
64
+ /* For padding */
65
+ void *random_ctx, nettle_random_func *random,
66
+ size_t length, const uint8_t *message,
67
+ mpz_t m);
68
+
69
+ int
70
+ pkcs1_decrypt (size_t key_size,
71
+ const mpz_t m,
72
+ size_t *length, uint8_t *message);
73
+
74
+ int
75
+ pkcs1_rsa_digest_encode(mpz_t m, size_t key_size,
76
+ size_t di_length, const uint8_t *digest_info);
77
+
78
+ int
79
+ pkcs1_rsa_md5_encode(mpz_t m, size_t length, struct md5_ctx *hash);
80
+
81
+ int
82
+ pkcs1_rsa_md5_encode_digest(mpz_t m, size_t length, const uint8_t *digest);
83
+
84
+ int
85
+ pkcs1_rsa_sha1_encode(mpz_t m, size_t length, struct sha1_ctx *hash);
86
+
87
+ int
88
+ pkcs1_rsa_sha1_encode_digest(mpz_t m, size_t length, const uint8_t *digest);
89
+
90
+ int
91
+ pkcs1_rsa_sha256_encode(mpz_t m, size_t length, struct sha256_ctx *hash);
92
+
93
+ int
94
+ pkcs1_rsa_sha256_encode_digest(mpz_t m, size_t length, const uint8_t *digest);
95
+
96
+ int
97
+ pkcs1_rsa_sha512_encode(mpz_t m, size_t length, struct sha512_ctx *hash);
98
+
99
+ int
100
+ pkcs1_rsa_sha512_encode_digest(mpz_t m, size_t length, const uint8_t *digest);
101
+
102
+ #ifdef __cplusplus
103
+ }
104
+ #endif
105
+
106
+ #endif /* NETTLE_PKCS1_H_INCLUDED */
include/nettle/poly1305.h ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* poly1305.h
2
+
3
+ Poly1305 message authentication code.
4
+
5
+ Copyright (C) 2013 Nikos Mavrogiannopoulos
6
+ Copyright (C) 2013, 2014 Niels Möller
7
+
8
+ This file is part of GNU Nettle.
9
+
10
+ GNU Nettle is free software: you can redistribute it and/or
11
+ modify it under the terms of either:
12
+
13
+ * the GNU Lesser General Public License as published by the Free
14
+ Software Foundation; either version 3 of the License, or (at your
15
+ option) any later version.
16
+
17
+ or
18
+
19
+ * the GNU General Public License as published by the Free
20
+ Software Foundation; either version 2 of the License, or (at your
21
+ option) any later version.
22
+
23
+ or both in parallel, as here.
24
+
25
+ GNU Nettle is distributed in the hope that it will be useful,
26
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
+ General Public License for more details.
29
+
30
+ You should have received copies of the GNU General Public License and
31
+ the GNU Lesser General Public License along with this program. If
32
+ not, see http://www.gnu.org/licenses/.
33
+ */
34
+
35
+ #ifndef NETTLE_POLY1305_H_INCLUDED
36
+ #define NETTLE_POLY1305_H_INCLUDED
37
+
38
+ #include "aes.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* Name mangling */
45
+ #define poly1305_aes_set_key nettle_poly1305_aes_set_key
46
+ #define poly1305_aes_set_nonce nettle_poly1305_aes_set_nonce
47
+ #define poly1305_aes_update nettle_poly1305_aes_update
48
+ #define poly1305_aes_digest nettle_poly1305_aes_digest
49
+
50
+ /* Low level functions/macros for the poly1305 construction. */
51
+
52
+ #define POLY1305_BLOCK_SIZE 16
53
+
54
+ struct poly1305_ctx {
55
+ /* Key, 128-bit value and some cached multiples. */
56
+ union
57
+ {
58
+ uint32_t r32[6];
59
+ uint64_t r64[3];
60
+ } r;
61
+ uint32_t s32[3];
62
+ /* State, represented as words of 26, 32 or 64 bits, depending on
63
+ implementation. */
64
+ /* High bits first, to maintain alignment. */
65
+ uint32_t hh;
66
+ union
67
+ {
68
+ uint32_t h32[4];
69
+ uint64_t h64[2];
70
+ } h;
71
+ };
72
+
73
+ /* poly1305-aes */
74
+
75
+ #define POLY1305_AES_KEY_SIZE 32
76
+ #define POLY1305_AES_DIGEST_SIZE 16
77
+ #define POLY1305_AES_NONCE_SIZE 16
78
+
79
+ struct poly1305_aes_ctx
80
+ {
81
+ /* Keep aes context last, to make it possible to use a general
82
+ poly1305_update if other variants are added. */
83
+ struct poly1305_ctx pctx;
84
+ uint8_t block[POLY1305_BLOCK_SIZE];
85
+ unsigned index;
86
+ uint8_t nonce[POLY1305_BLOCK_SIZE];
87
+ struct aes128_ctx aes;
88
+ };
89
+
90
+ /* Also initialize the nonce to zero. */
91
+ void
92
+ poly1305_aes_set_key (struct poly1305_aes_ctx *ctx, const uint8_t *key);
93
+
94
+ /* Optional, if not used, messages get incrementing nonces starting
95
+ from zero. */
96
+ void
97
+ poly1305_aes_set_nonce (struct poly1305_aes_ctx *ctx,
98
+ const uint8_t *nonce);
99
+
100
+ /* Update is not aes-specific, but since this is the only implemented
101
+ variant, we need no more general poly1305_update. */
102
+ void
103
+ poly1305_aes_update (struct poly1305_aes_ctx *ctx, size_t length, const uint8_t *data);
104
+
105
+ /* Also increments the nonce */
106
+ void
107
+ poly1305_aes_digest (struct poly1305_aes_ctx *ctx,
108
+ size_t length, uint8_t *digest);
109
+
110
+ #ifdef __cplusplus
111
+ }
112
+ #endif
113
+
114
+ #endif /* NETTLE_POLY1305_H_INCLUDED */
include/nettle/pss-mgf1.h ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* pss-mgf1.h
2
+
3
+ PKCS#1 mask generation function 1, used in RSA-PSS (RFC-3447).
4
+
5
+ Copyright (C) 2017 Daiki Ueno
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_PSS_MGF1_H_INCLUDED
35
+ #define NETTLE_PSS_MGF1_H_INCLUDED
36
+
37
+ #include "nettle-meta.h"
38
+
39
+ #include "sha1.h"
40
+ #include "sha2.h"
41
+
42
+ #ifdef __cplusplus
43
+ extern "C"
44
+ {
45
+ #endif
46
+
47
+ /* Namespace mangling */
48
+ #define pss_mgf1 nettle_pss_mgf1
49
+
50
+ void
51
+ pss_mgf1(const void *seed, const struct nettle_hash *hash,
52
+ size_t length, uint8_t *mask);
53
+
54
+ #ifdef __cplusplus
55
+ }
56
+ #endif
57
+
58
+ #endif /* NETTLE_PSS_MGF1_H_INCLUDED */
include/nettle/pss.h ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* pss.h
2
+
3
+ PKCS#1 RSA-PSS (RFC-3447).
4
+
5
+ Copyright (C) 2017 Daiki Ueno
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_PSS_H_INCLUDED
35
+ #define NETTLE_PSS_H_INCLUDED
36
+
37
+ #include "nettle-meta.h"
38
+ #include "bignum.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C"
42
+ {
43
+ #endif
44
+
45
+ /* Namespace mangling */
46
+ #define pss_encode_mgf1 nettle_pss_encode_mgf1
47
+ #define pss_verify_mgf1 nettle_pss_verify_mgf1
48
+
49
+ int
50
+ pss_encode_mgf1(mpz_t m, size_t bits,
51
+ const struct nettle_hash *hash,
52
+ size_t salt_length, const uint8_t *salt,
53
+ const uint8_t *digest);
54
+
55
+ int
56
+ pss_verify_mgf1(const mpz_t m, size_t bits,
57
+ const struct nettle_hash *hash,
58
+ size_t salt_length,
59
+ const uint8_t *digest);
60
+
61
+ #ifdef __cplusplus
62
+ }
63
+ #endif
64
+
65
+ #endif /* NETTLE_PSS_H_INCLUDED */
include/nettle/realloc.h ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* realloc.h
2
+
3
+ Copyright (C) 2002 Niels Möller
4
+
5
+ This file is part of GNU Nettle.
6
+
7
+ GNU Nettle is free software: you can redistribute it and/or
8
+ modify it under the terms of either:
9
+
10
+ * the GNU Lesser General Public License as published by the Free
11
+ Software Foundation; either version 3 of the License, or (at your
12
+ option) any later version.
13
+
14
+ or
15
+
16
+ * the GNU General Public License as published by the Free
17
+ Software Foundation; either version 2 of the License, or (at your
18
+ option) any later version.
19
+
20
+ or both in parallel, as here.
21
+
22
+ GNU Nettle is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
+ General Public License for more details.
26
+
27
+ You should have received copies of the GNU General Public License and
28
+ the GNU Lesser General Public License along with this program. If
29
+ not, see http://www.gnu.org/licenses/.
30
+ */
31
+
32
+ #ifndef NETTLE_REALLOC_H_INCLUDED
33
+ #define NETTLE_REALLOC_H_INCLUDED
34
+
35
+ #include "nettle-types.h"
36
+
37
+ #ifdef __cplusplus
38
+ extern "C" {
39
+ #endif
40
+
41
+ nettle_realloc_func nettle_realloc;
42
+ nettle_realloc_func nettle_xrealloc;
43
+
44
+ #ifdef __cplusplus
45
+ }
46
+ #endif
47
+
48
+ #endif /* NETTLE_REALLOC_H_INCLUDED */
include/nettle/ripemd160.h ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* ripemd160.h
2
+
3
+ RIPEMD-160 hash function.
4
+
5
+ Copyright (C) 2011 Andres Mejia
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_RIPEMD160_H_INCLUDED
35
+ #define NETTLE_RIPEMD160_H_INCLUDED
36
+
37
+ #ifdef __cplusplus
38
+ extern "C" {
39
+ #endif
40
+
41
+ #include "nettle-types.h"
42
+
43
+ /* Name mangling */
44
+ #define ripemd160_init nettle_ripemd160_init
45
+ #define ripemd160_update nettle_ripemd160_update
46
+ #define ripemd160_digest nettle_ripemd160_digest
47
+
48
+ /* RIPEMD160 */
49
+
50
+ #define RIPEMD160_DIGEST_SIZE 20
51
+ #define RIPEMD160_BLOCK_SIZE 64
52
+ /* For backwards compatibility */
53
+ #define RIPEMD160_DATA_SIZE RIPEMD160_BLOCK_SIZE
54
+
55
+ /* Digest is kept internally as 5 32-bit words. */
56
+ #define _RIPEMD160_DIGEST_LENGTH 5
57
+
58
+ struct ripemd160_ctx
59
+ {
60
+ uint32_t state[_RIPEMD160_DIGEST_LENGTH];
61
+ uint64_t count; /* 64-bit block count */
62
+ unsigned int index;
63
+ uint8_t block[RIPEMD160_BLOCK_SIZE];
64
+ };
65
+
66
+ void
67
+ ripemd160_init(struct ripemd160_ctx *ctx);
68
+
69
+ void
70
+ ripemd160_update(struct ripemd160_ctx *ctx,
71
+ size_t length,
72
+ const uint8_t *data);
73
+
74
+ void
75
+ ripemd160_digest(struct ripemd160_ctx *ctx,
76
+ size_t length,
77
+ uint8_t *digest);
78
+
79
+ #ifdef __cplusplus
80
+ }
81
+ #endif
82
+
83
+ #endif /* NETTLE_RIPEMD160_H_INCLUDED */
include/nettle/rsa.h ADDED
@@ -0,0 +1,538 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* rsa.h
2
+
3
+ The RSA publickey algorithm.
4
+
5
+ Copyright (C) 2001, 2002 Niels Möller
6
+
7
+ This file is part of GNU Nettle.
8
+
9
+ GNU Nettle is free software: you can redistribute it and/or
10
+ modify it under the terms of either:
11
+
12
+ * the GNU Lesser General Public License as published by the Free
13
+ Software Foundation; either version 3 of the License, or (at your
14
+ option) any later version.
15
+
16
+ or
17
+
18
+ * the GNU General Public License as published by the Free
19
+ Software Foundation; either version 2 of the License, or (at your
20
+ option) any later version.
21
+
22
+ or both in parallel, as here.
23
+
24
+ GNU Nettle is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
+ General Public License for more details.
28
+
29
+ You should have received copies of the GNU General Public License and
30
+ the GNU Lesser General Public License along with this program. If
31
+ not, see http://www.gnu.org/licenses/.
32
+ */
33
+
34
+ #ifndef NETTLE_RSA_H_INCLUDED
35
+ #define NETTLE_RSA_H_INCLUDED
36
+
37
+ #include "nettle-types.h"
38
+ #include "bignum.h"
39
+
40
+ #include "md5.h"
41
+ #include "sha1.h"
42
+ #include "sha2.h"
43
+
44
+ #ifdef __cplusplus
45
+ extern "C" {
46
+ #endif
47
+
48
+ /* Name mangling */
49
+ #define rsa_public_key_init nettle_rsa_public_key_init
50
+ #define rsa_public_key_clear nettle_rsa_public_key_clear
51
+ #define rsa_public_key_prepare nettle_rsa_public_key_prepare
52
+ #define rsa_private_key_init nettle_rsa_private_key_init
53
+ #define rsa_private_key_clear nettle_rsa_private_key_clear
54
+ #define rsa_private_key_prepare nettle_rsa_private_key_prepare
55
+ #define rsa_pkcs1_verify nettle_rsa_pkcs1_verify
56
+ #define rsa_pkcs1_sign nettle_rsa_pkcs1_sign
57
+ #define rsa_pkcs1_sign_tr nettle_rsa_pkcs1_sign_tr
58
+ #define rsa_md5_sign nettle_rsa_md5_sign
59
+ #define rsa_md5_sign_tr nettle_rsa_md5_sign_tr
60
+ #define rsa_md5_verify nettle_rsa_md5_verify
61
+ #define rsa_sha1_sign nettle_rsa_sha1_sign
62
+ #define rsa_sha1_sign_tr nettle_rsa_sha1_sign_tr
63
+ #define rsa_sha1_verify nettle_rsa_sha1_verify
64
+ #define rsa_sha256_sign nettle_rsa_sha256_sign
65
+ #define rsa_sha256_sign_tr nettle_rsa_sha256_sign_tr
66
+ #define rsa_sha256_verify nettle_rsa_sha256_verify
67
+ #define rsa_sha512_sign nettle_rsa_sha512_sign
68
+ #define rsa_sha512_sign_tr nettle_rsa_sha512_sign_tr
69
+ #define rsa_sha512_verify nettle_rsa_sha512_verify
70
+ #define rsa_md5_sign_digest nettle_rsa_md5_sign_digest
71
+ #define rsa_md5_sign_digest_tr nettle_rsa_md5_sign_digest_tr
72
+ #define rsa_md5_verify_digest nettle_rsa_md5_verify_digest
73
+ #define rsa_sha1_sign_digest nettle_rsa_sha1_sign_digest
74
+ #define rsa_sha1_sign_digest_tr nettle_rsa_sha1_sign_digest_tr
75
+ #define rsa_sha1_verify_digest nettle_rsa_sha1_verify_digest
76
+ #define rsa_sha256_sign_digest nettle_rsa_sha256_sign_digest
77
+ #define rsa_sha256_sign_digest_tr nettle_rsa_sha256_sign_digest_tr
78
+ #define rsa_sha256_verify_digest nettle_rsa_sha256_verify_digest
79
+ #define rsa_sha512_sign_digest nettle_rsa_sha512_sign_digest
80
+ #define rsa_sha512_sign_digest_tr nettle_rsa_sha512_sign_digest_tr
81
+ #define rsa_sha512_verify_digest nettle_rsa_sha512_verify_digest
82
+ #define rsa_pss_sha256_sign_digest_tr nettle_rsa_pss_sha256_sign_digest_tr
83
+ #define rsa_pss_sha256_verify_digest nettle_rsa_pss_sha256_verify_digest
84
+ #define rsa_pss_sha384_sign_digest_tr nettle_rsa_pss_sha384_sign_digest_tr
85
+ #define rsa_pss_sha384_verify_digest nettle_rsa_pss_sha384_verify_digest
86
+ #define rsa_pss_sha512_sign_digest_tr nettle_rsa_pss_sha512_sign_digest_tr
87
+ #define rsa_pss_sha512_verify_digest nettle_rsa_pss_sha512_verify_digest
88
+ #define rsa_encrypt nettle_rsa_encrypt
89
+ #define rsa_decrypt nettle_rsa_decrypt
90
+ #define rsa_decrypt_tr nettle_rsa_decrypt_tr
91
+ #define rsa_sec_decrypt nettle_rsa_sec_decrypt
92
+ #define rsa_compute_root nettle_rsa_compute_root
93
+ #define rsa_compute_root_tr nettle_rsa_compute_root_tr
94
+ #define rsa_generate_keypair nettle_rsa_generate_keypair
95
+ #define rsa_keypair_to_sexp nettle_rsa_keypair_to_sexp
96
+ #define rsa_keypair_from_sexp_alist nettle_rsa_keypair_from_sexp_alist
97
+ #define rsa_keypair_from_sexp nettle_rsa_keypair_from_sexp
98
+ #define rsa_public_key_from_der_iterator nettle_rsa_public_key_from_der_iterator
99
+ #define rsa_private_key_from_der_iterator nettle_rsa_private_key_from_der_iterator
100
+ #define rsa_keypair_from_der nettle_rsa_keypair_from_der
101
+ #define rsa_keypair_to_openpgp nettle_rsa_keypair_to_openpgp
102
+
103
+ /* This limit is somewhat arbitrary. Technically, the smallest modulo
104
+ which makes sense at all is 15 = 3*5, phi(15) = 8, size 4 bits. But
105
+ for ridiculously small keys, not all odd e are possible (e.g., for
106
+ 5 bits, the only possible modulo is 3*7 = 21, phi(21) = 12, and e =
107
+ 3 don't work). The smallest size that makes sense with pkcs#1, and
108
+ which allows RSA encryption of one byte messages, is 12 octets, 89
109
+ bits. */
110
+
111
+ #define RSA_MINIMUM_N_OCTETS 12
112
+ #define RSA_MINIMUM_N_BITS (8*RSA_MINIMUM_N_OCTETS - 7)
113
+
114
+ struct rsa_public_key
115
+ {
116
+ /* Size of the modulo, in octets. This is also the size of all
117
+ * signatures that are created or verified with this key. */
118
+ size_t size;
119
+
120
+ /* Modulo */
121
+ mpz_t n;
122
+
123
+ /* Public exponent */
124
+ mpz_t e;
125
+ };
126
+
127
+ struct rsa_private_key
128
+ {
129
+ size_t size;
130
+
131
+ /* d is filled in by the key generation function; otherwise it's
132
+ * completely unused. */
133
+ mpz_t d;
134
+
135
+ /* The two factors */
136
+ mpz_t p; mpz_t q;
137
+
138
+ /* d % (p-1), i.e. a e = 1 (mod (p-1)) */
139
+ mpz_t a;
140
+
141
+ /* d % (q-1), i.e. b e = 1 (mod (q-1)) */
142
+ mpz_t b;
143
+
144
+ /* modular inverse of q , i.e. c q = 1 (mod p) */
145
+ mpz_t c;
146
+ };
147
+
148
+ /* Signing a message works as follows:
149
+ *
150
+ * Store the private key in a rsa_private_key struct.
151
+ *
152
+ * Call rsa_private_key_prepare. This initializes the size attribute
153
+ * to the length of a signature.
154
+ *
155
+ * Initialize a hashing context, by callling
156
+ * md5_init
157
+ *
158
+ * Hash the message by calling
159
+ * md5_update
160
+ *
161
+ * Create the signature by calling
162
+ * rsa_md5_sign
163
+ *
164
+ * The signature is represented as a mpz_t bignum. This call also
165
+ * resets the hashing context.
166
+ *
167
+ * When done with the key and signature, don't forget to call
168
+ * mpz_clear.
169
+ */
170
+
171
+ /* Calls mpz_init to initialize bignum storage. */
172
+ void
173
+ rsa_public_key_init(struct rsa_public_key *key);
174
+
175
+ /* Calls mpz_clear to deallocate bignum storage. */
176
+ void
177
+ rsa_public_key_clear(struct rsa_public_key *key);
178
+
179
+ int
180
+ rsa_public_key_prepare(struct rsa_public_key *key);
181
+
182
+ /* Calls mpz_init to initialize bignum storage. */
183
+ void
184
+ rsa_private_key_init(struct rsa_private_key *key);
185
+
186
+ /* Calls mpz_clear to deallocate bignum storage. */
187
+ void
188
+ rsa_private_key_clear(struct rsa_private_key *key);
189
+
190
+ int
191
+ rsa_private_key_prepare(struct rsa_private_key *key);
192
+
193
+
194
+ /* PKCS#1 style signatures */
195
+ int
196
+ rsa_pkcs1_sign(const struct rsa_private_key *key,
197
+ size_t length, const uint8_t *digest_info,
198
+ mpz_t s);
199
+
200
+ int
201
+ rsa_pkcs1_sign_tr(const struct rsa_public_key *pub,
202
+ const struct rsa_private_key *key,
203
+ void *random_ctx, nettle_random_func *random,
204
+ size_t length, const uint8_t *digest_info,
205
+ mpz_t s);
206
+ int
207
+ rsa_pkcs1_verify(const struct rsa_public_key *key,
208
+ size_t length, const uint8_t *digest_info,
209
+ const mpz_t signature);
210
+
211
+ int
212
+ rsa_md5_sign(const struct rsa_private_key *key,
213
+ struct md5_ctx *hash,
214
+ mpz_t signature);
215
+
216
+ int
217
+ rsa_md5_sign_tr(const struct rsa_public_key *pub,
218
+ const struct rsa_private_key *key,
219
+ void *random_ctx, nettle_random_func *random,
220
+ struct md5_ctx *hash, mpz_t s);
221
+
222
+
223
+ int
224
+ rsa_md5_verify(const struct rsa_public_key *key,
225
+ struct md5_ctx *hash,
226
+ const mpz_t signature);
227
+
228
+ int
229
+ rsa_sha1_sign(const struct rsa_private_key *key,
230
+ struct sha1_ctx *hash,
231
+ mpz_t signature);
232
+
233
+ int
234
+ rsa_sha1_sign_tr(const struct rsa_public_key *pub,
235
+ const struct rsa_private_key *key,
236
+ void *random_ctx, nettle_random_func *random,
237
+ struct sha1_ctx *hash,
238
+ mpz_t s);
239
+
240
+ int
241
+ rsa_sha1_verify(const struct rsa_public_key *key,
242
+ struct sha1_ctx *hash,
243
+ const mpz_t signature);
244
+
245
+ int
246
+ rsa_sha256_sign(const struct rsa_private_key *key,
247
+ struct sha256_ctx *hash,
248
+ mpz_t signature);
249
+
250
+ int
251
+ rsa_sha256_sign_tr(const struct rsa_public_key *pub,
252
+ const struct rsa_private_key *key,
253
+ void *random_ctx, nettle_random_func *random,
254
+ struct sha256_ctx *hash,
255
+ mpz_t s);
256
+
257
+ int
258
+ rsa_sha256_verify(const struct rsa_public_key *key,
259
+ struct sha256_ctx *hash,
260
+ const mpz_t signature);
261
+
262
+ int
263
+ rsa_sha512_sign(const struct rsa_private_key *key,
264
+ struct sha512_ctx *hash,
265
+ mpz_t signature);
266
+
267
+ int
268
+ rsa_sha512_sign_tr(const struct rsa_public_key *pub,
269
+ const struct rsa_private_key *key,
270
+ void *random_ctx, nettle_random_func *random,
271
+ struct sha512_ctx *hash,
272
+ mpz_t s);
273
+
274
+ int
275
+ rsa_sha512_verify(const struct rsa_public_key *key,
276
+ struct sha512_ctx *hash,
277
+ const mpz_t signature);
278
+
279
+ /* Variants taking the digest as argument. */
280
+ int
281
+ rsa_md5_sign_digest(const struct rsa_private_key *key,
282
+ const uint8_t *digest,
283
+ mpz_t s);
284
+
285
+ int
286
+ rsa_md5_sign_digest_tr(const struct rsa_public_key *pub,
287
+ const struct rsa_private_key *key,
288
+ void *random_ctx, nettle_random_func *random,
289
+ const uint8_t *digest, mpz_t s);
290
+
291
+ int
292
+ rsa_md5_verify_digest(const struct rsa_public_key *key,
293
+ const uint8_t *digest,
294
+ const mpz_t signature);
295
+
296
+ int
297
+ rsa_sha1_sign_digest(const struct rsa_private_key *key,
298
+ const uint8_t *digest,
299
+ mpz_t s);
300
+
301
+ int
302
+ rsa_sha1_sign_digest_tr(const struct rsa_public_key *pub,
303
+ const struct rsa_private_key *key,
304
+ void *random_ctx, nettle_random_func *random,
305
+ const uint8_t *digest,
306
+ mpz_t s);
307
+
308
+ int
309
+ rsa_sha1_verify_digest(const struct rsa_public_key *key,
310
+ const uint8_t *digest,
311
+ const mpz_t signature);
312
+
313
+ int
314
+ rsa_sha256_sign_digest(const struct rsa_private_key *key,
315
+ const uint8_t *digest,
316
+ mpz_t s);
317
+
318
+ int
319
+ rsa_sha256_sign_digest_tr(const struct rsa_public_key *pub,
320
+ const struct rsa_private_key *key,
321
+ void *random_ctx, nettle_random_func *random,
322
+ const uint8_t *digest,
323
+ mpz_t s);
324
+
325
+ int
326
+ rsa_sha256_verify_digest(const struct rsa_public_key *key,
327
+ const uint8_t *digest,
328
+ const mpz_t signature);
329
+
330
+ int
331
+ rsa_sha512_sign_digest(const struct rsa_private_key *key,
332
+ const uint8_t *digest,
333
+ mpz_t s);
334
+
335
+ int
336
+ rsa_sha512_sign_digest_tr(const struct rsa_public_key *pub,
337
+ const struct rsa_private_key *key,
338
+ void *random_ctx, nettle_random_func *random,
339
+ const uint8_t *digest,
340
+ mpz_t s);
341
+
342
+ int
343
+ rsa_sha512_verify_digest(const struct rsa_public_key *key,
344
+ const uint8_t *digest,
345
+ const mpz_t signature);
346
+
347
+ /* PSS style signatures */
348
+ int
349
+ rsa_pss_sha256_sign_digest_tr(const struct rsa_public_key *pub,
350
+ const struct rsa_private_key *key,
351
+ void *random_ctx, nettle_random_func *random,
352
+ size_t salt_length, const uint8_t *salt,
353
+ const uint8_t *digest,
354
+ mpz_t s);
355
+
356
+ int
357
+ rsa_pss_sha256_verify_digest(const struct rsa_public_key *key,
358
+ size_t salt_length,
359
+ const uint8_t *digest,
360
+ const mpz_t signature);
361
+
362
+ int
363
+ rsa_pss_sha384_sign_digest_tr(const struct rsa_public_key *pub,
364
+ const struct rsa_private_key *key,
365
+ void *random_ctx, nettle_random_func *random,
366
+ size_t salt_length, const uint8_t *salt,
367
+ const uint8_t *digest,
368
+ mpz_t s);
369
+
370
+ int
371
+ rsa_pss_sha384_verify_digest(const struct rsa_public_key *key,
372
+ size_t salt_length,
373
+ const uint8_t *digest,
374
+ const mpz_t signature);
375
+
376
+ int
377
+ rsa_pss_sha512_sign_digest_tr(const struct rsa_public_key *pub,
378
+ const struct rsa_private_key *key,
379
+ void *random_ctx, nettle_random_func *random,
380
+ size_t salt_length, const uint8_t *salt,
381
+ const uint8_t *digest,
382
+ mpz_t s);
383
+
384
+ int
385
+ rsa_pss_sha512_verify_digest(const struct rsa_public_key *key,
386
+ size_t salt_length,
387
+ const uint8_t *digest,
388
+ const mpz_t signature);
389
+
390
+
391
+ /* RSA encryption, using PKCS#1 */
392
+ /* These functions uses the v1.5 padding. What should the v2 (OAEP)
393
+ * functions be called? */
394
+
395
+ /* Returns 1 on success, 0 on failure, which happens if the
396
+ * message is too long for the key. */
397
+ int
398
+ rsa_encrypt(const struct rsa_public_key *key,
399
+ /* For padding */
400
+ void *random_ctx, nettle_random_func *random,
401
+ size_t length, const uint8_t *cleartext,
402
+ mpz_t cipher);
403
+
404
+ /* Message must point to a buffer of size *LENGTH. KEY->size is enough
405
+ * for all valid messages. On success, *LENGTH is updated to reflect
406
+ * the actual length of the message. Returns 1 on success, 0 on
407
+ * failure, which happens if decryption failed or if the message
408
+ * didn't fit. */
409
+ int
410
+ rsa_decrypt(const struct rsa_private_key *key,
411
+ size_t *length, uint8_t *cleartext,
412
+ const mpz_t ciphertext);
413
+
414
+ /* Timing-resistant version, using randomized RSA blinding. */
415
+ int
416
+ rsa_decrypt_tr(const struct rsa_public_key *pub,
417
+ const struct rsa_private_key *key,
418
+ void *random_ctx, nettle_random_func *random,
419
+ size_t *length, uint8_t *message,
420
+ const mpz_t gibberish);
421
+
422
+ /* like rsa_decrypt_tr but with additional side-channel resistance.
423
+ * NOTE: the length of the final message must be known in advance. */
424
+ int
425
+ rsa_sec_decrypt(const struct rsa_public_key *pub,
426
+ const struct rsa_private_key *key,
427
+ void *random_ctx, nettle_random_func *random,
428
+ size_t length, uint8_t *message,
429
+ const mpz_t gibberish);
430
+
431
+ /* Compute x, the e:th root of m. Calling it with x == m is allowed.
432
+ It is required that 0 <= m < n. */
433
+ void
434
+ rsa_compute_root(const struct rsa_private_key *key,
435
+ mpz_t x, const mpz_t m);
436
+
437
+ /* Safer variant, using RSA blinding, and checking the result after
438
+ CRT. It is required that 0 <= m < n. */
439
+ int
440
+ rsa_compute_root_tr(const struct rsa_public_key *pub,
441
+ const struct rsa_private_key *key,
442
+ void *random_ctx, nettle_random_func *random,
443
+ mpz_t x, const mpz_t m);
444
+
445
+ /* Key generation */
446
+
447
+ /* Note that the key structs must be initialized first. */
448
+ int
449
+ rsa_generate_keypair(struct rsa_public_key *pub,
450
+ struct rsa_private_key *key,
451
+
452
+ void *random_ctx, nettle_random_func *random,
453
+ void *progress_ctx, nettle_progress_func *progress,
454
+
455
+ /* Desired size of modulo, in bits */
456
+ unsigned n_size,
457
+
458
+ /* Desired size of public exponent, in bits. If
459
+ * zero, the passed in value pub->e is used. */
460
+ unsigned e_size);
461
+
462
+
463
+ #define RSA_SIGN(key, algorithm, ctx, length, data, signature) ( \
464
+ algorithm##_update(ctx, length, data), \
465
+ rsa_##algorithm##_sign(key, ctx, signature) \
466
+ )
467
+
468
+ #define RSA_VERIFY(key, algorithm, ctx, length, data, signature) ( \
469
+ algorithm##_update(ctx, length, data), \
470
+ rsa_##algorithm##_verify(key, ctx, signature) \
471
+ )
472
+
473
+
474
+ /* Keys in sexp form. */
475
+
476
+ struct nettle_buffer;
477
+
478
+ /* Generates a public-key expression if PRIV is NULL .*/
479
+ int
480
+ rsa_keypair_to_sexp(struct nettle_buffer *buffer,
481
+ const char *algorithm_name, /* NULL means "rsa" */
482
+ const struct rsa_public_key *pub,
483
+ const struct rsa_private_key *priv);
484
+
485
+ struct sexp_iterator;
486
+
487
+ int
488
+ rsa_keypair_from_sexp_alist(struct rsa_public_key *pub,
489
+ struct rsa_private_key *priv,
490
+ unsigned limit,
491
+ struct sexp_iterator *i);
492
+
493
+ /* If PRIV is NULL, expect a public-key expression. If PUB is NULL,
494
+ * expect a private key expression and ignore the parts not needed for
495
+ * the public key. */
496
+ /* Keys must be initialized before calling this function, as usual. */
497
+ int
498
+ rsa_keypair_from_sexp(struct rsa_public_key *pub,
499
+ struct rsa_private_key *priv,
500
+ unsigned limit,
501
+ size_t length, const uint8_t *expr);
502
+
503
+
504
+ /* Keys in PKCS#1 format. */
505
+ struct asn1_der_iterator;
506
+
507
+ int
508
+ rsa_public_key_from_der_iterator(struct rsa_public_key *pub,
509
+ unsigned limit,
510
+ struct asn1_der_iterator *i);
511
+
512
+ int
513
+ rsa_private_key_from_der_iterator(struct rsa_public_key *pub,
514
+ struct rsa_private_key *priv,
515
+ unsigned limit,
516
+ struct asn1_der_iterator *i);
517
+
518
+ /* For public keys, use PRIV == NULL */
519
+ int
520
+ rsa_keypair_from_der(struct rsa_public_key *pub,
521
+ struct rsa_private_key *priv,
522
+ unsigned limit,
523
+ size_t length, const uint8_t *data);
524
+
525
+ /* OpenPGP format. Experimental interface, subject to change. */
526
+ int
527
+ rsa_keypair_to_openpgp(struct nettle_buffer *buffer,
528
+ const struct rsa_public_key *pub,
529
+ const struct rsa_private_key *priv,
530
+ /* A single user id. NUL-terminated utf8. */
531
+ const char *userid);
532
+
533
+
534
+ #ifdef __cplusplus
535
+ }
536
+ #endif
537
+
538
+ #endif /* NETTLE_RSA_H_INCLUDED */