porting dhm functions to polarssl-1.3.0