@@ -90,7 +90,7 @@ xmlSecOpenSSLEvpBlockCipherCtxInit(xmlSecOpenSSLEvpBlockCipherCtxPtr ctx,
90
90
int encrypt ,
91
91
const xmlChar * cipherName ,
92
92
xmlSecTransformCtxPtr transformCtx ) {
93
- int ivLen ;
93
+ xmlSecOpenSSLUInt ivLen ;
94
94
xmlSecSize ivSize ;
95
95
int ret ;
96
96
@@ -110,21 +110,21 @@ xmlSecOpenSSLEvpBlockCipherCtxInit(xmlSecOpenSSLEvpBlockCipherCtxPtr ctx,
110
110
ivLen = XMLSEC_OPENSSL_AES_GCM_NONCE_SIZE ;
111
111
}
112
112
xmlSecAssert2 (ivLen > 0 , -1 );
113
- XMLSEC_SAFE_CAST_INT_TO_SIZE (ivLen , ivSize , return (-1 ), NULL );
113
+ XMLSEC_OPENSSL_SAFE_CAST_UINT_TO_SIZE (ivLen , ivSize , return (-1 ), NULL );
114
114
115
115
xmlSecAssert2 (ivSize <= sizeof (ctx -> iv ), -1 );
116
116
if (encrypt ) {
117
117
/* generate random iv */
118
118
ret = RAND_priv_bytes_ex (xmlSecOpenSSLGetLibCtx (), ctx -> iv , ivSize , XMLSEEC_OPENSSL_RAND_BYTES_STRENGTH );
119
119
if (ret != 1 ) {
120
- xmlSecOpenSSLError2 ("RAND_priv_bytes_ex" , cipherName , "size=%d" , ivLen );
120
+ xmlSecOpenSSLError2 ("RAND_priv_bytes_ex" , cipherName , "size=" XMLSEC_SIZE_FMT , ivSize );
121
121
return (-1 );
122
122
}
123
123
124
124
/* write iv to the output */
125
125
ret = xmlSecBufferAppend (out , ctx -> iv , ivSize );
126
126
if (ret < 0 ) {
127
- xmlSecInternalError2 ("xmlSecBufferAppend" , cipherName , "size=%d" , ivLen );
127
+ xmlSecInternalError2 ("xmlSecBufferAppend" , cipherName , "size=" XMLSEC_SIZE_FMT , ivSize );
128
128
return (-1 );
129
129
}
130
130
} else {
@@ -141,7 +141,7 @@ xmlSecOpenSSLEvpBlockCipherCtxInit(xmlSecOpenSSLEvpBlockCipherCtxPtr ctx,
141
141
/* and remove from input */
142
142
ret = xmlSecBufferRemoveHead (in , ivSize );
143
143
if (ret < 0 ) {
144
- xmlSecInternalError2 ("xmlSecBufferRemoveHead" , cipherName , "size=%d" , ivLen );
144
+ xmlSecInternalError2 ("xmlSecBufferRemoveHead" , cipherName , "size=" XMLSEC_SIZE_FMT , ivSize );
145
145
return (-1 );
146
146
}
147
147
}
@@ -179,7 +179,7 @@ xmlSecOpenSSLEvpBlockCipherCtxUpdateBlock(xmlSecOpenSSLEvpBlockCipherCtxPtr ctx,
179
179
xmlSecByte * tagData ) {
180
180
xmlSecByte * outBuf ;
181
181
xmlSecSize outSize , outSize2 , blockSize ;
182
- int blockLen ;
182
+ xmlSecOpenSSLUInt blockLen ;
183
183
int inLen ;
184
184
int outLen = 0 ;
185
185
int ret ;
@@ -206,7 +206,7 @@ xmlSecOpenSSLEvpBlockCipherCtxUpdateBlock(xmlSecOpenSSLEvpBlockCipherCtxPtr ctx,
206
206
blockLen = EVP_CIPHER_block_size (ctx -> cipher );
207
207
xmlSecAssert2 (blockLen > 0 , -1 );
208
208
209
- XMLSEC_SAFE_CAST_INT_TO_SIZE (blockLen , blockSize , return (-1 ), NULL );
209
+ XMLSEC_OPENSSL_SAFE_CAST_UINT_TO_SIZE (blockLen , blockSize , return (-1 ), NULL );
210
210
xmlSecAssert2 ((inSize % blockSize ) == 0 , -1 );
211
211
212
212
outSize = xmlSecBufferGetSize (out );
@@ -298,7 +298,7 @@ xmlSecOpenSSLEvpBlockCipherCtxUpdate(xmlSecOpenSSLEvpBlockCipherCtxPtr ctx,
298
298
const xmlChar * cipherName ,
299
299
xmlSecTransformCtxPtr transformCtx ) {
300
300
xmlSecSize inSize , blockSize , inBlocksSize ;
301
- int blockLen ;
301
+ xmlSecOpenSSLUInt blockLen ;
302
302
xmlSecByte * inBuf ;
303
303
int ret ;
304
304
@@ -312,7 +312,7 @@ xmlSecOpenSSLEvpBlockCipherCtxUpdate(xmlSecOpenSSLEvpBlockCipherCtxPtr ctx,
312
312
313
313
blockLen = EVP_CIPHER_block_size (ctx -> cipher );
314
314
xmlSecAssert2 (blockLen > 0 , -1 );
315
- XMLSEC_SAFE_CAST_INT_TO_SIZE (blockLen , blockSize , return (-1 ), NULL );
315
+ XMLSEC_OPENSSL_SAFE_CAST_UINT_TO_SIZE (blockLen , blockSize , return (-1 ), NULL );
316
316
317
317
inSize = xmlSecBufferGetSize (in );
318
318
if (ctx -> cbcMode ) {
@@ -390,7 +390,7 @@ xmlSecOpenSSLEvpBlockCipherCBCCtxFinal(xmlSecOpenSSLEvpBlockCipherCtxPtr ctx,
390
390
xmlSecTransformCtxPtr transformCtx ATTRIBUTE_UNUSED )
391
391
{
392
392
xmlSecSize size , inSize , outSize ;
393
- int inLen , outLen , padLen , blockLen ;
393
+ xmlSecOpenSSLUInt inLen , outLen , padLen , blockLen ;
394
394
xmlSecByte * inBuf ;
395
395
xmlSecByte * outBuf ;
396
396
int ret ;
@@ -411,7 +411,7 @@ xmlSecOpenSSLEvpBlockCipherCBCCtxFinal(xmlSecOpenSSLEvpBlockCipherCtxPtr ctx,
411
411
/* not more than one block left */
412
412
inSize = xmlSecBufferGetSize (in );
413
413
inBuf = xmlSecBufferGetData (in );
414
- XMLSEC_SAFE_CAST_SIZE_TO_INT (inSize , inLen , return (-1 ), NULL );
414
+ XMLSEC_OPENSSL_SAFE_CAST_SIZE_TO_UINT (inSize , inLen , return (-1 ), NULL );
415
415
xmlSecAssert2 (inLen <= blockLen , -1 );
416
416
417
417
/*
@@ -432,13 +432,13 @@ xmlSecOpenSSLEvpBlockCipherCBCCtxFinal(xmlSecOpenSSLEvpBlockCipherCtxPtr ctx,
432
432
433
433
/* we can have inLen == 0 if there were no data at all, otherwise -- copy the data */
434
434
if (inLen > 0 ) {
435
- XMLSEC_SAFE_CAST_INT_TO_SIZE (inLen , size , return (-1 ), NULL );
435
+ XMLSEC_OPENSSL_SAFE_CAST_UINT_TO_SIZE (inLen , size , return (-1 ), NULL );
436
436
memcpy (ctx -> pad , inBuf , size );
437
437
}
438
438
439
439
/* generate random padding */
440
440
if (padLen > 1 ) {
441
- XMLSEC_SAFE_CAST_INT_TO_SIZE (padLen , size , return (-1 ), NULL );
441
+ XMLSEC_OPENSSL_SAFE_CAST_UINT_TO_SIZE (padLen , size , return (-1 ), NULL );
442
442
ret = RAND_priv_bytes_ex (xmlSecOpenSSLGetLibCtx (), ctx -> pad + inLen , size - 1 ,
443
443
XMLSEEC_OPENSSL_RAND_BYTES_STRENGTH );
444
444
if (ret != 1 ) {
@@ -449,10 +449,10 @@ xmlSecOpenSSLEvpBlockCipherCBCCtxFinal(xmlSecOpenSSLEvpBlockCipherCtxPtr ctx,
449
449
450
450
/* set the last byte to the pad length */
451
451
outLen = inLen + padLen ;
452
- XMLSEC_SAFE_CAST_INT_TO_BYTE (padLen , ctx -> pad [outLen - 1 ], return (-1 ), cipherName );
452
+ XMLSEC_OPENSSL_SAFE_CAST_UINT_TO_BYTE (padLen , ctx -> pad [outLen - 1 ], return (-1 ), cipherName );
453
453
454
454
/* update the last 1 or 2 blocks with padding */
455
- XMLSEC_SAFE_CAST_INT_TO_SIZE (outLen , outSize , return (-1 ), NULL );
455
+ XMLSEC_OPENSSL_SAFE_CAST_UINT_TO_SIZE (outLen , outSize , return (-1 ), NULL );
456
456
ret = xmlSecOpenSSLEvpBlockCipherCtxUpdateBlock (ctx , ctx -> pad , outSize , out , cipherName , 1 , NULL ); /* final */
457
457
if (ret < 0 ) {
458
458
xmlSecInternalError ("xmlSecOpenSSLEvpBlockCipherCtxUpdateBlock" , cipherName );
@@ -471,35 +471,33 @@ xmlSecOpenSSLEvpBlockCipherCBCCtxFinal(xmlSecOpenSSLEvpBlockCipherCtxPtr ctx,
471
471
/* we expect at least one block in the output -- the one we just decrypted */
472
472
outBuf = xmlSecBufferGetData (out );
473
473
outSize = xmlSecBufferGetSize (out );
474
- XMLSEC_SAFE_CAST_SIZE_TO_INT (outSize , outLen , return (-1 ), NULL );
474
+ XMLSEC_OPENSSL_SAFE_CAST_SIZE_TO_UINT (outSize , outLen , return (-1 ), NULL );
475
475
if (outLen < blockLen ) {
476
- xmlSecInvalidIntegerDataError2 ("outLen" , outLen , "blockLen" , blockLen ,
477
- "outLen >= blockLen" , cipherName );
476
+ xmlSecInvalidDataError ("data length is less than block size for cipher" , cipherName );
478
477
return (-1 );
479
478
}
480
479
481
480
/* get the pad length from the last byte */
482
481
padLen = outBuf [outLen - 1 ];
483
482
if (padLen > blockLen ) {
484
- xmlSecInvalidIntegerDataError2 ("padLen" , padLen , "blockLen" , blockLen ,
485
- "padLen <= blockLen" , cipherName );
483
+ xmlSecInvalidDataError ("padding length is greater than block size for cipher" , cipherName );
486
484
return (-1 );
487
485
}
488
486
xmlSecAssert2 (padLen <= outLen , -1 );
489
487
490
488
/* remove the padding */
491
- XMLSEC_SAFE_CAST_INT_TO_SIZE (padLen , padSize , return (-1 ), NULL );
489
+ XMLSEC_OPENSSL_SAFE_CAST_UINT_TO_SIZE (padLen , padSize , return (-1 ), NULL );
492
490
ret = xmlSecBufferRemoveTail (out , padSize );
493
491
if (ret < 0 ) {
494
- xmlSecInternalError2 ("xmlSecBufferRemoveTail" , cipherName , "size=%d" , padLen );
492
+ xmlSecInternalError ("xmlSecBufferRemoveTail" , cipherName );
495
493
return (-1 );
496
494
}
497
495
}
498
496
499
497
/* remove the processed block from input */
500
498
ret = xmlSecBufferRemoveHead (in , inSize );
501
499
if (ret < 0 ) {
502
- xmlSecInternalError2 ("xmlSecBufferRemoveHead" , cipherName , "size=%d" , inLen );
500
+ xmlSecInternalError ("xmlSecBufferRemoveHead" , cipherName );
503
501
return (-1 );
504
502
}
505
503
@@ -764,7 +762,7 @@ xmlSecOpenSSLEvpBlockCipherFinalize(xmlSecTransformPtr transform) {
764
762
static int
765
763
xmlSecOpenSSLEvpBlockCipherSetKeyReq (xmlSecTransformPtr transform , xmlSecKeyReqPtr keyReq ) {
766
764
xmlSecOpenSSLEvpBlockCipherCtxPtr ctx ;
767
- int cipherKeyLen , keyBitsLen ;
765
+ xmlSecOpenSSLUInt cipherKeyLen , keyBitsLen ;
768
766
769
767
xmlSecAssert2 (xmlSecOpenSSLEvpBlockCipherCheckId (transform ), -1 );
770
768
xmlSecAssert2 ((transform -> operation == xmlSecTransformOperationEncrypt ) || (transform -> operation == xmlSecTransformOperationDecrypt ), -1 );
@@ -788,7 +786,7 @@ xmlSecOpenSSLEvpBlockCipherSetKeyReq(xmlSecTransformPtr transform, xmlSecKeyReq
788
786
xmlSecAssert2 (cipherKeyLen > 0 , -1 );
789
787
790
788
keyBitsLen = 8 * cipherKeyLen ;
791
- XMLSEC_SAFE_CAST_INT_TO_SIZE (keyBitsLen , keyReq -> keyBitsSize , return (-1 ), xmlSecTransformGetName (transform ));
789
+ XMLSEC_OPENSSL_SAFE_CAST_UINT_TO_SIZE (keyBitsLen , keyReq -> keyBitsSize , return (-1 ), xmlSecTransformGetName (transform ));
792
790
return (0 );
793
791
}
794
792
@@ -797,7 +795,7 @@ xmlSecOpenSSLEvpBlockCipherSetKey(xmlSecTransformPtr transform, xmlSecKeyPtr key
797
795
xmlSecOpenSSLEvpBlockCipherCtxPtr ctx ;
798
796
xmlSecBufferPtr buffer ;
799
797
xmlSecSize cipherKeySize ;
800
- int cipherKeyLen ;
798
+ xmlSecOpenSSLUInt cipherKeyLen ;
801
799
802
800
xmlSecAssert2 (xmlSecOpenSSLEvpBlockCipherCheckId (transform ), -1 );
803
801
xmlSecAssert2 ((transform -> operation == xmlSecTransformOperationEncrypt ) || (transform -> operation == xmlSecTransformOperationDecrypt ), -1 );
@@ -813,7 +811,7 @@ xmlSecOpenSSLEvpBlockCipherSetKey(xmlSecTransformPtr transform, xmlSecKeyPtr key
813
811
814
812
cipherKeyLen = EVP_CIPHER_key_length (ctx -> cipher );
815
813
xmlSecAssert2 (cipherKeyLen > 0 , -1 );
816
- XMLSEC_SAFE_CAST_INT_TO_SIZE (cipherKeyLen , cipherKeySize , return (-1 ), xmlSecTransformGetName (transform ));
814
+ XMLSEC_OPENSSL_SAFE_CAST_UINT_TO_SIZE (cipherKeyLen , cipherKeySize , return (-1 ), xmlSecTransformGetName (transform ));
817
815
xmlSecAssert2 (cipherKeySize <= sizeof (ctx -> key ), -1 );
818
816
819
817
buffer = xmlSecKeyDataBinaryValueGetBuffer (xmlSecKeyGetValue (key ));
0 commit comments