diff --git a/sntrup761.c b/sntrup761.c
index 123d01381..58414c4aa 100644
--- a/sntrup761.c
+++ b/sntrup761.c
@@ -15,6 +15,7 @@
 
 #include <string.h>
 #include "crypto_api.h"
+#include "xmalloc.h"
 
 #define crypto_declassify(x, y) do {} while (0)
 
@@ -1753,8 +1754,12 @@ static void Encode(unsigned char *out, const uint16_t *R, const uint16_t *M, lon
       m = (m + 255) >> 8;
     }
   }
+  uint16_t *R2 = NULL, *M2 = NULL;
+  size_t MR_len = 0;
   if (len > 1) {
-    uint16_t R2[(len + 1) / 2], M2[(len + 1) / 2];
+    MR_len = (len + 1) / 2;
+    R2 = xcalloc(MR_len, sizeof(*R2));
+    M2 = xcalloc(MR_len, sizeof(*M2));
     long long i;
     for (i = 0; i < len - 1; i += 2) {
       uint32_t m0 = M[i];
@@ -1774,6 +1779,8 @@ static void Encode(unsigned char *out, const uint16_t *R, const uint16_t *M, lon
     }
     Encode(out, R2, M2, (len + 1) / 2);
   }
+  freezero(R2, MR_len * sizeof(*R2));
+  freezero(M2, MR_len * sizeof(*R2));
 }
 
 static void Decode(uint16_t *out, const unsigned char *S, const uint16_t *M, long long len) {
@@ -1785,10 +1792,17 @@ static void Decode(uint16_t *out, const unsigned char *S, const uint16_t *M, lon
     else
       *out = uint32_mod_uint14(S[0] + (((uint16_t)S[1]) << 8), M[0]);
   }
+  uint16_t *R2 = NULL, *M2 = NULL, *bottomr = NULL;
+  uint32_t *bottomt = NULL;
+  size_t MR_len = 0, bottom_len = 0;
   if (len > 1) {
-    uint16_t R2[(len + 1) / 2], M2[(len + 1) / 2], bottomr[len / 2];
-    uint32_t bottomt[len / 2];
     long long i;
+    MR_len = (len + 1) / 2;
+    bottom_len = len / 2;
+    R2 = xcalloc(MR_len, sizeof(*R2));
+    M2 = xcalloc(MR_len, sizeof(*M2));
+    bottomr = xcalloc(bottom_len, sizeof(*bottomr));
+    bottomt = xcalloc(bottom_len, sizeof(*bottomt));
     for (i = 0; i < len - 1; i += 2) {
       uint32_t m = M[i] * (uint32_t)M[i + 1];
       if (m > 256 * 16383) {
@@ -1820,6 +1834,10 @@ static void Decode(uint16_t *out, const unsigned char *S, const uint16_t *M, lon
     }
     if (i < len) *out++ = R2[i / 2];
   }
+  freezero(R2, MR_len * sizeof(*R2));
+  freezero(M2, MR_len * sizeof(*R2));
+  freezero(bottomr, bottom_len * sizeof(*bottomr));
+  freezero(bottomt, bottom_len * sizeof(*bottomt));
 }
 
 static void R3_fromRq(small *out, const Fq *r) {
@@ -1953,12 +1971,14 @@ static void Short_fromlist(small *out, const uint32_t *in) {
 }
 
 static void Hash_prefix(unsigned char *out, int b, const unsigned char *in, int inlen) {
-  unsigned char x[inlen + 1], h[64];
+  unsigned char *x, h[64];
   int i;
+  x = xcalloc(inlen + 1, sizeof(*x));
   x[0] = b;
   for (i = 0; i < inlen; ++i) x[i + 1] = in[i];
   crypto_hash_sha512(h, x, inlen + 1);
   for (i = 0; i < 32; ++i) out[i] = h[i];
+  freezero(x, (inlen + 1) * sizeof(*x));
 }
 
 static uint32_t urandom32(void) {
