Skip to content

Commit 8d4852a

Browse files
committed
Added constant time array comparison example
1 parent 94d66bc commit 8d4852a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,13 @@ using (RSACryptoServiceProvider clientRSA = new RSACryptoServiceProvider())
5656
byte[] key1 = serverDiffie.GetVerifiedSharedPart(clientPublic);
5757
byte[] key2 = clientDiffie.GetVerifiedSharedPart(serverPublic);
5858
}
59+
```
60+
### Timing Side Channel Attack Prevention
61+
```csharp
62+
byte[] array1 = new byte[120];
63+
byte[] array2 = new byte[120];
64+
array[50] = 67;
65+
66+
// This comparison will take constant time, no matter where the diff is (if any).
67+
bool equal = ComparisonUtils.ConstTimeArrayEqual(array1, array2);
5968
```

0 commit comments

Comments
 (0)