- Extra sanity check for input added

diff --git a/library/dhm.c b/library/dhm.c
index 4a59571..90e5b4b 100644
--- a/library/dhm.c
+++ b/library/dhm.c
@@ -128,6 +128,9 @@
     size_t n1, n2, n3;
     unsigned char *p;
 
+    if( mpi_cmp_int( &ctx->P, 0 ) == 0 )
+        return( POLARSSL_ERR_DHM_BAD_INPUT_DATA );
+
     /*
      * Generate X as large as possible ( < P )
      */
@@ -211,6 +214,9 @@
     if( ctx == NULL || olen < 1 || olen > ctx->len )
         return( POLARSSL_ERR_DHM_BAD_INPUT_DATA );
 
+    if( mpi_cmp_int( &ctx->P, 0 ) == 0 )
+        return( POLARSSL_ERR_DHM_BAD_INPUT_DATA );
+
     /*
      * generate X and calculate GX = G^X mod P
      */