Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(247831)

Delta Between Two Patch Sets: Modules/_blake2/impl/blake2s-ref.c

Issue 26798: add BLAKE2 to hashlib
Left Patch Set: Created 3 years, 2 months ago
Right Patch Set: Created 2 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Modules/_blake2/impl/blake2s-load-xop.h ('k') | Modules/_blake2/impl/blake2s-round.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 BLAKE2 reference source code package - reference C implementations 2 BLAKE2 reference source code package - reference C implementations
3 3
4 Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the 4 Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
5 terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at 5 terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
6 your option. The terms of these licenses can be found at: 6 your option. The terms of these licenses can be found at:
7 7
8 - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 8 - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
9 - OpenSSL license : https://www.openssl.org/source/license.html 9 - OpenSSL license : https://www.openssl.org/source/license.html
10 - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 10 - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
(...skipping 22 matching lines...) Expand all
33 { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } , 33 { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
34 { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } , 34 { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
35 { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } , 35 { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
36 { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } , 36 { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
37 { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } , 37 { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
38 { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } , 38 { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
39 { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } , 39 { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
40 { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } , 40 { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
41 }; 41 };
42 42
43 Py_LOCAL_INLINE(int) blake2s_set_lastnode( blake2s_state *S ) 43 BLAKE2_LOCAL_INLINE(int) blake2s_set_lastnode( blake2s_state *S )
44 { 44 {
45 S->f[1] = -1; 45 S->f[1] = -1;
46 return 0; 46 return 0;
47 } 47 }
48 48
49 Py_LOCAL_INLINE(int) blake2s_clear_lastnode( blake2s_state *S ) 49 BLAKE2_LOCAL_INLINE(int) blake2s_clear_lastnode( blake2s_state *S )
50 { 50 {
51 S->f[1] = 0; 51 S->f[1] = 0;
52 return 0; 52 return 0;
53 } 53 }
54 54
55 /* Some helper functions, not necessarily useful */ 55 /* Some helper functions, not necessarily useful */
56 Py_LOCAL_INLINE(int) blake2s_is_lastblock( const blake2s_state *S ) 56 BLAKE2_LOCAL_INLINE(int) blake2s_is_lastblock( const blake2s_state *S )
57 { 57 {
58 return S->f[0] != 0; 58 return S->f[0] != 0;
59 } 59 }
60 60
61 Py_LOCAL_INLINE(int) blake2s_set_lastblock( blake2s_state *S ) 61 BLAKE2_LOCAL_INLINE(int) blake2s_set_lastblock( blake2s_state *S )
62 { 62 {
63 if( S->last_node ) blake2s_set_lastnode( S ); 63 if( S->last_node ) blake2s_set_lastnode( S );
64 64
65 S->f[0] = -1; 65 S->f[0] = -1;
66 return 0; 66 return 0;
67 } 67 }
68 68
69 Py_LOCAL_INLINE(int) blake2s_clear_lastblock( blake2s_state *S ) 69 BLAKE2_LOCAL_INLINE(int) blake2s_clear_lastblock( blake2s_state *S )
70 { 70 {
71 if( S->last_node ) blake2s_clear_lastnode( S ); 71 if( S->last_node ) blake2s_clear_lastnode( S );
72 72
73 S->f[0] = 0; 73 S->f[0] = 0;
74 return 0; 74 return 0;
75 } 75 }
76 76
77 Py_LOCAL_INLINE(int) blake2s_increment_counter( blake2s_state *S, const uint32_t inc ) 77 BLAKE2_LOCAL_INLINE(int) blake2s_increment_counter( blake2s_state *S, const uint 32_t inc )
78 { 78 {
79 S->t[0] += inc; 79 S->t[0] += inc;
80 S->t[1] += ( S->t[0] < inc ); 80 S->t[1] += ( S->t[0] < inc );
81 return 0; 81 return 0;
82 } 82 }
83 83
84 /* Parameter-related functions */ 84 /* Parameter-related functions */
85 Py_LOCAL_INLINE(int) blake2s_param_set_digest_length( blake2s_param *P, const ui nt8_t digest_length ) 85 BLAKE2_LOCAL_INLINE(int) blake2s_param_set_digest_length( blake2s_param *P, cons t uint8_t digest_length )
86 { 86 {
87 P->digest_length = digest_length; 87 P->digest_length = digest_length;
88 return 0; 88 return 0;
89 } 89 }
90 90
91 Py_LOCAL_INLINE(int) blake2s_param_set_fanout( blake2s_param *P, const uint8_t f anout ) 91 BLAKE2_LOCAL_INLINE(int) blake2s_param_set_fanout( blake2s_param *P, const uint8 _t fanout )
92 { 92 {
93 P->fanout = fanout; 93 P->fanout = fanout;
94 return 0; 94 return 0;
95 } 95 }
96 96
97 Py_LOCAL_INLINE(int) blake2s_param_set_max_depth( blake2s_param *P, const uint8_ t depth ) 97 BLAKE2_LOCAL_INLINE(int) blake2s_param_set_max_depth( blake2s_param *P, const ui nt8_t depth )
98 { 98 {
99 P->depth = depth; 99 P->depth = depth;
100 return 0; 100 return 0;
101 } 101 }
102 102
103 Py_LOCAL_INLINE(int) blake2s_param_set_leaf_length( blake2s_param *P, const uint 32_t leaf_length ) 103 BLAKE2_LOCAL_INLINE(int) blake2s_param_set_leaf_length( blake2s_param *P, const uint32_t leaf_length )
104 { 104 {
105 store32( &P->leaf_length, leaf_length ); 105 store32( &P->leaf_length, leaf_length );
106 return 0; 106 return 0;
107 } 107 }
108 108
109 Py_LOCAL_INLINE(int) blake2s_param_set_node_offset( blake2s_param *P, const uint 64_t node_offset ) 109 BLAKE2_LOCAL_INLINE(int) blake2s_param_set_node_offset( blake2s_param *P, const uint64_t node_offset )
110 { 110 {
111 store48( P->node_offset, node_offset ); 111 store48( P->node_offset, node_offset );
112 return 0; 112 return 0;
113 } 113 }
114 114
115 Py_LOCAL_INLINE(int) blake2s_param_set_node_depth( blake2s_param *P, const uint8 _t node_depth ) 115 BLAKE2_LOCAL_INLINE(int) blake2s_param_set_node_depth( blake2s_param *P, const u int8_t node_depth )
116 { 116 {
117 P->node_depth = node_depth; 117 P->node_depth = node_depth;
118 return 0; 118 return 0;
119 } 119 }
120 120
121 Py_LOCAL_INLINE(int) blake2s_param_set_inner_length( blake2s_param *P, const uin t8_t inner_length ) 121 BLAKE2_LOCAL_INLINE(int) blake2s_param_set_inner_length( blake2s_param *P, const uint8_t inner_length )
122 { 122 {
123 P->inner_length = inner_length; 123 P->inner_length = inner_length;
124 return 0; 124 return 0;
125 } 125 }
126 126
127 Py_LOCAL_INLINE(int) blake2s_param_set_salt( blake2s_param *P, const uint8_t sal t[BLAKE2S_SALTBYTES] ) 127 BLAKE2_LOCAL_INLINE(int) blake2s_param_set_salt( blake2s_param *P, const uint8_t salt[BLAKE2S_SALTBYTES] )
128 { 128 {
129 memcpy( P->salt, salt, BLAKE2S_SALTBYTES ); 129 memcpy( P->salt, salt, BLAKE2S_SALTBYTES );
130 return 0; 130 return 0;
131 } 131 }
132 132
133 Py_LOCAL_INLINE(int) blake2s_param_set_personal( blake2s_param *P, const uint8_t personal[BLAKE2S_PERSONALBYTES] ) 133 BLAKE2_LOCAL_INLINE(int) blake2s_param_set_personal( blake2s_param *P, const uin t8_t personal[BLAKE2S_PERSONALBYTES] )
134 { 134 {
135 memcpy( P->personal, personal, BLAKE2S_PERSONALBYTES ); 135 memcpy( P->personal, personal, BLAKE2S_PERSONALBYTES );
136 return 0; 136 return 0;
137 } 137 }
138 138
139 Py_LOCAL_INLINE(int) blake2s_init0( blake2s_state *S ) 139 BLAKE2_LOCAL_INLINE(int) blake2s_init0( blake2s_state *S )
140 { 140 {
141 memset( S, 0, sizeof( blake2s_state ) ); 141 memset( S, 0, sizeof( blake2s_state ) );
142 142
143 for( int i = 0; i < 8; ++i ) S->h[i] = blake2s_IV[i]; 143 for( int i = 0; i < 8; ++i ) S->h[i] = blake2s_IV[i];
144 144
145 return 0; 145 return 0;
146 } 146 }
147 147
148 /* init2 xors IV with input parameter block */ 148 /* init2 xors IV with input parameter block */
149 int blake2s_init_param( blake2s_state *S, const blake2s_param *P ) 149 int blake2s_init_param( blake2s_state *S, const blake2s_param *P )
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 return -1; 397 return -1;
398 } 398 }
399 } 399 }
400 400
401 puts( "ok" ); 401 puts( "ok" );
402 return 0; 402 return 0;
403 } 403 }
404 #endif 404 #endif
405 405
406 406
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+