@@ -50,10 +50,12 @@ static int decode_base64(u_int8_t *, size_t, const char *);
5050 * the core bcrypt function
5151 */
5252int
53- vapor_auth_bcrypt_hashpass (
54- const char * key ,
55- const char * salt ,
56- char * __counted_by (encryptedlen ) encrypted __noescape ,
53+ vapor_auth_bcrypt_hashpass (const char * _Nonnull __counted_by (keysize ) key __noescape ,
54+ const char * _Nonnull __counted_by (saltsize ) salt __noescape ,
55+ char * _Nonnull __counted_by (encryptedlen )
56+ encrypted __noescape ,
57+ size_t keysize ,
58+ size_t saltsize ,
5759 size_t encryptedlen )
5860{
5961 blf_ctx state ;
@@ -76,6 +78,10 @@ vapor_auth_bcrypt_hashpass(
7678 if (salt [0 ] != BCRYPT_VERSION )
7779 goto inval ;
7880
81+ /* keysize is the size of the key including a null terminator */
82+ if ((strlen (key ) + 1 ) != keysize )
83+ goto inval ;
84+
7985 /* Check for minor versions */
8086 switch ((minor = salt [1 ])) {
8187 case 'a' :
@@ -149,8 +155,8 @@ vapor_auth_bcrypt_hashpass(
149155
150156
151157 snprintf (encrypted , 8 , "$2%c$%2.2u$" , minor , logr );
152- vapor_auth_encode_base64 (encrypted + 7 , csalt , BCRYPT_MAXSALT );
153- vapor_auth_encode_base64 (encrypted + 7 + 22 , ciphertext , 4 * BCRYPT_WORDS - 1 );
158+ vapor_auth_encode_base64 (encrypted + 7 , csalt , encryptedlen , BCRYPT_MAXSALT );
159+ vapor_auth_encode_base64 (encrypted + 7 + 22 , ciphertext , encryptedlen , 4 * BCRYPT_WORDS - 1 );
154160 explicit_bzero (& state , sizeof (state ));
155161 explicit_bzero (ciphertext , sizeof (ciphertext ));
156162 explicit_bzero (csalt , sizeof (csalt ));
@@ -232,7 +238,10 @@ decode_base64(u_int8_t *buffer, size_t len, const char *b64data)
232238 * This works without = padding.
233239 */
234240int
235- vapor_auth_encode_base64 (char * b64buffer , const u_int8_t * __counted_by (len )data __noescape , size_t len )
241+ vapor_auth_encode_base64 (char * _Nonnull __counted_by (bufferlen ) b64buffer __noescape ,
242+ const u_int8_t * _Nonnull __counted_by (len ) data __noescape ,
243+ size_t bufferlen ,
244+ size_t len )
236245{
237246 u_int8_t * bp = (u_int8_t * )b64buffer ;
238247 const u_int8_t * p = data ;
0 commit comments