mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-04 04:32:24 -05:00 
			
		
		
		
	Fix errors returned by CCM functions.
Add new error code for calling functions in wrong order. Signed-off-by: Mateusz Starzyk <mateusz.starzyk@mobica.com>
This commit is contained in:
		
							parent
							
								
									f337850738
								
							
						
					
					
						commit
						4f2dd8aada
					
				@ -61,6 +61,8 @@
 | 
				
			|||||||
#define MBEDTLS_ERR_CCM_BAD_INPUT       -0x000D
 | 
					#define MBEDTLS_ERR_CCM_BAD_INPUT       -0x000D
 | 
				
			||||||
/** Authenticated decryption failed. */
 | 
					/** Authenticated decryption failed. */
 | 
				
			||||||
#define MBEDTLS_ERR_CCM_AUTH_FAILED     -0x000F
 | 
					#define MBEDTLS_ERR_CCM_AUTH_FAILED     -0x000F
 | 
				
			||||||
 | 
					/** CCM functions called in the wrong sequence. */
 | 
				
			||||||
 | 
					#define MBEDTLS_ERR_CCM_BAD_SEQUENCE    -0x0011
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
extern "C" {
 | 
					extern "C" {
 | 
				
			||||||
 | 
				
			|||||||
@ -269,7 +269,7 @@ int mbedtls_ccm_update_ad( mbedtls_ccm_context *ctx,
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        if( ctx->state & CCM_STATE__AUTH_DATA_FINISHED )
 | 
					        if( ctx->state & CCM_STATE__AUTH_DATA_FINISHED )
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            return ret;
 | 
					            return MBEDTLS_ERR_CCM_BAD_SEQUENCE;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if( ctx->processed == 0 )
 | 
					        if( ctx->processed == 0 )
 | 
				
			||||||
@ -430,22 +430,22 @@ exit:
 | 
				
			|||||||
int mbedtls_ccm_finish( mbedtls_ccm_context *ctx,
 | 
					int mbedtls_ccm_finish( mbedtls_ccm_context *ctx,
 | 
				
			||||||
                        unsigned char *tag, size_t tag_len )
 | 
					                        unsigned char *tag, size_t tag_len )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
 | 
					    int ret;
 | 
				
			||||||
    unsigned char i;
 | 
					    unsigned char i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ctx->state & CCM_STATE__ERROR )
 | 
					    if( ctx->state & CCM_STATE__ERROR )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return ret;
 | 
					        return MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ctx->add_len > 0 && !( ctx->state & CCM_STATE__AUTH_DATA_FINISHED ) )
 | 
					    if( ctx->add_len > 0 && !( ctx->state & CCM_STATE__AUTH_DATA_FINISHED ) )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return ret;
 | 
					        return MBEDTLS_ERR_CCM_BAD_SEQUENCE;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ctx->plaintext_len > 0 && ctx->processed != ctx->plaintext_len )
 | 
					    if( ctx->plaintext_len > 0 && ctx->processed != ctx->plaintext_len )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return ret;
 | 
					        return MBEDTLS_ERR_CCM_BAD_SEQUENCE;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user