summary refs log tree commit diff
path: root/crypto/src/math
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-07-01 16:04:26 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-07-01 16:04:26 +0700
commit7667960b24e63b23518408337c69d5f36c5dfd94 (patch)
tree5a4d0d42d37cd2413b3ec7b68eccfb16f3d4a858 /crypto/src/math
parentRework EdDSA precomputations (diff)
downloadBouncyCastle.NET-ed25519-7667960b24e63b23518408337c69d5f36c5dfd94.tar.xz
Custom serialization
Diffstat (limited to 'crypto/src/math')
-rw-r--r--crypto/src/math/BigInteger.cs15
1 files changed, 13 insertions, 2 deletions
diff --git a/crypto/src/math/BigInteger.cs b/crypto/src/math/BigInteger.cs
index 98d1fcb1d..50229e2db 100644
--- a/crypto/src/math/BigInteger.cs
+++ b/crypto/src/math/BigInteger.cs
@@ -2,6 +2,7 @@ using System;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Globalization;
+using System.Runtime.Serialization;
 using System.Text;
 
 using Org.BouncyCastle.Security;
@@ -9,9 +10,7 @@ using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Math
 {
-#if !PORTABLE
     [Serializable]
-#endif
     public class BigInteger
     {
         // The first few odd primes
@@ -239,10 +238,22 @@ namespace Org.BouncyCastle.Math
 
         private int[] magnitude; // array of ints with [0] being the most significant
         private int sign; // -1 means -ve; +1 means +ve; 0 means 0;
+
+        [NonSerialized]
         private int nBits = -1; // cache BitCount() value
+        [NonSerialized]
         private int nBitLength = -1; // cache BitLength() value
+        [NonSerialized]
         private int mQuote = 0; // -m^(-1) mod b, b = 2^32 (see Montgomery mult.), 0 when uninitialised
 
+        [OnDeserialized]
+        private void OnDeserialized(StreamingContext context)
+        {
+            this.nBits = -1;
+            this.nBitLength = -1;
+            this.mQuote = 0;
+        }
+
         private static int GetByteLength(
             int nBits)
         {