summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs28
-rw-r--r--TwoStepsAuthenticator/Authenticator.cs4
-rw-r--r--TwoStepsAuthenticator/CounterAuthenticator.cs12
-rw-r--r--TwoStepsAuthenticator/TimeAuthenticator.cs2
4 files changed, 23 insertions, 23 deletions
diff --git a/TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs b/TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs
index ecb96c0..7b2944f 100644
--- a/TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs
+++ b/TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs
@@ -20,17 +20,17 @@ namespace TwoStepsAuthenticator.UnitTests {
}
// Test Values from http://www.ietf.org/rfc/rfc4226.txt - Appendix D
- [TestCase("12345678901234567890", 0L, "755224")]
- [TestCase("12345678901234567890", 1L, "287082")]
- [TestCase("12345678901234567890", 2L, "359152")]
- [TestCase("12345678901234567890", 3L, "969429")]
- [TestCase("12345678901234567890", 4L, "338314")]
- [TestCase("12345678901234567890", 5L, "254676")]
- [TestCase("12345678901234567890", 6L, "287922")]
- [TestCase("12345678901234567890", 7L, "162583")]
- [TestCase("12345678901234567890", 8L, "399871")]
- [TestCase("12345678901234567890", 9L, "520489")]
- public void VerifyKeys(string secret, long counter, string code) {
+ [TestCase("12345678901234567890", 0uL, "755224")]
+ [TestCase("12345678901234567890", 1uL, "287082")]
+ [TestCase("12345678901234567890", 2uL, "359152")]
+ [TestCase("12345678901234567890", 3uL, "969429")]
+ [TestCase("12345678901234567890", 4uL, "338314")]
+ [TestCase("12345678901234567890", 5uL, "254676")]
+ [TestCase("12345678901234567890", 6uL, "287922")]
+ [TestCase("12345678901234567890", 7uL, "162583")]
+ [TestCase("12345678901234567890", 8uL, "399871")]
+ [TestCase("12345678901234567890", 9uL, "520489")]
+ public void VerifyKeys(string secret, ulong counter, string code) {
var authenticator = new CounterAuthenticator();
var base32Secret = Base32Encoding.ToString(Encoding.ASCII.GetBytes(secret));
@@ -45,10 +45,10 @@ namespace TwoStepsAuthenticator.UnitTests {
// Test Values from http://www.ietf.org/rfc/rfc4226.txt - Appendix D
var base32Secret = Base32Encoding.ToString(Encoding.ASCII.GetBytes("12345678901234567890"));
- long usedCounter;
- Assert.True(authenticator.CheckCode(base32Secret, "520489", 0L, out usedCounter));
+ ulong usedCounter;
+ Assert.True(authenticator.CheckCode(base32Secret, "520489", 0uL, out usedCounter));
- Assert.AreEqual(usedCounter, 9L);
+ Assert.AreEqual(usedCounter, 9uL);
}
}
}
diff --git a/TwoStepsAuthenticator/Authenticator.cs b/TwoStepsAuthenticator/Authenticator.cs
index 81dc020..eea3612 100644
--- a/TwoStepsAuthenticator/Authenticator.cs
+++ b/TwoStepsAuthenticator/Authenticator.cs
@@ -21,8 +21,8 @@ namespace TwoStepsAuthenticator
return new String(keyChars);
}
- protected string GetCodeInternal(string secret, long challengeValue) {
- long chlg = challengeValue;
+ protected string GetCodeInternal(string secret, ulong challengeValue) {
+ ulong chlg = challengeValue;
byte[] challenge = new byte[8];
for (int j = 7; j >= 0; j--) {
challenge[j] = (byte)((int)chlg & 0xff);
diff --git a/TwoStepsAuthenticator/CounterAuthenticator.cs b/TwoStepsAuthenticator/CounterAuthenticator.cs
index b9ed5d2..e9162fd 100644
--- a/TwoStepsAuthenticator/CounterAuthenticator.cs
+++ b/TwoStepsAuthenticator/CounterAuthenticator.cs
@@ -26,7 +26,7 @@ namespace TwoStepsAuthenticator {
/// <param name="secret">Shared Secret</param>
/// <param name="counter">Current Counter</param>
/// <returns>OTP</returns>
- public string GetCode(string secret, long counter) {
+ public string GetCode(string secret, ulong counter) {
return GetCodeInternal(secret, counter);
}
@@ -37,8 +37,8 @@ namespace TwoStepsAuthenticator {
/// <param name="code">OTP</param>
/// <param name="counter">Current Counter Position</param>
/// <returns>true if any code from counter to counter + WindowSize matches</returns>
- public bool CheckCode(string secret, string code, long counter) {
- long successfulSequenceNumber = 0L;
+ public bool CheckCode(string secret, string code, ulong counter) {
+ ulong successfulSequenceNumber = 0uL;
return CheckCode(secret, code, counter, out successfulSequenceNumber);
}
@@ -51,11 +51,11 @@ namespace TwoStepsAuthenticator {
/// <param name="counter">Current Counter Position</param>
/// <param name="usedCounter">Matching counter value if successful</param>
/// <returns>true if any code from counter to counter + WindowSize matches</returns>
- public bool CheckCode(string secret, string code, long counter, out long usedCounter) {
+ public bool CheckCode(string secret, string code, ulong counter, out ulong usedCounter) {
var codeMatch = false;
- long successfulSequenceNumber = 0L;
+ ulong successfulSequenceNumber = 0uL;
- for (int i = 0; i <= WindowSize; i++) {
+ for (uint i = 0; i <= WindowSize; i++) {
if (ConstantTimeEquals(GetCode(secret, counter + i), code)) {
codeMatch = true;
successfulSequenceNumber = counter + i;
diff --git a/TwoStepsAuthenticator/TimeAuthenticator.cs b/TwoStepsAuthenticator/TimeAuthenticator.cs
index 8e8e462..0cfc525 100644
--- a/TwoStepsAuthenticator/TimeAuthenticator.cs
+++ b/TwoStepsAuthenticator/TimeAuthenticator.cs
@@ -35,7 +35,7 @@ namespace TwoStepsAuthenticator {
TimeSpan ts = (date.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc));
var interval = (long)ts.TotalSeconds / 30;
- return GetCodeInternal(secret, interval);
+ return GetCodeInternal(secret, (ulong)interval);
}
/// <summary>