mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-04 04:32:24 -05:00 
			
		
		
		
	Free peer's public key as soon as it's no longer needed
On constrained devices, this saves a significant amount of RAM that might be needed for subsequent expensive operations like ECDHE.
This commit is contained in:
		
							parent
							
								
									b9d4479080
								
							
						
					
					
						commit
						ae553dde3a
					
				@ -2331,6 +2331,10 @@ static int ssl_write_encrypted_pms( mbedtls_ssl_context *ssl,
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
 | 
				
			||||||
 | 
					    /* We don't need the peer's public key anymore. Free it. */
 | 
				
			||||||
 | 
					    mbedtls_pk_free( peer_pk );
 | 
				
			||||||
 | 
					#endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
 | 
				
			||||||
    return( 0 );
 | 
					    return( 0 );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED ||
 | 
					#endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED ||
 | 
				
			||||||
@ -2440,6 +2444,13 @@ static int ssl_get_ecdh_params_from_cert( mbedtls_ssl_context *ssl )
 | 
				
			|||||||
        return( MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE );
 | 
					        return( MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
 | 
				
			||||||
 | 
					    /* We don't need the peer's public key anymore. Free it,
 | 
				
			||||||
 | 
					     * so that more RAM is available for upcoming expensive
 | 
				
			||||||
 | 
					     * operations like ECDHE. */
 | 
				
			||||||
 | 
					    mbedtls_pk_free( peer_pk );
 | 
				
			||||||
 | 
					#endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( ret );
 | 
					    return( ret );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) ||
 | 
					#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) ||
 | 
				
			||||||
@ -2796,6 +2807,13 @@ start_processing:
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
            return( ret );
 | 
					            return( ret );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
 | 
				
			||||||
 | 
					        /* We don't need the peer's public key anymore. Free it,
 | 
				
			||||||
 | 
					         * so that more RAM is available for upcoming expensive
 | 
				
			||||||
 | 
					         * operations like ECDHE. */
 | 
				
			||||||
 | 
					        mbedtls_pk_free( peer_pk );
 | 
				
			||||||
 | 
					#endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif /* MBEDTLS_KEY_EXCHANGE__WITH_SERVER_SIGNATURE__ENABLED */
 | 
					#endif /* MBEDTLS_KEY_EXCHANGE__WITH_SERVER_SIGNATURE__ENABLED */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user