OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string.h> | 5 #include <string.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 | 7 |
8 #include "crypto/p224.h" | 8 #include "crypto/p224.h" |
9 | 9 |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 reinterpret_cast<const char *>(kNISTTestVectors[10].affine), 56))); | 799 reinterpret_cast<const char *>(kNISTTestVectors[10].affine), 56))); |
800 ASSERT_TRUE(b.SetFromString(base::StringPiece( | 800 ASSERT_TRUE(b.SetFromString(base::StringPiece( |
801 reinterpret_cast<const char *>(kNISTTestVectors[11].affine), 56))); | 801 reinterpret_cast<const char *>(kNISTTestVectors[11].affine), 56))); |
802 | 802 |
803 p224::Negate(b, &minus_b); | 803 p224::Negate(b, &minus_b); |
804 p224::Add(a, b, &sum); | 804 p224::Add(a, b, &sum); |
805 EXPECT_TRUE(memcmp(&sum, &a, sizeof(sum) != 0)); | 805 EXPECT_TRUE(memcmp(&sum, &a, sizeof(sum) != 0)); |
806 p224::Add(minus_b, sum, &a_again); | 806 p224::Add(minus_b, sum, &a_again); |
807 EXPECT_TRUE(a_again.ToString() == a.ToString()); | 807 EXPECT_TRUE(a_again.ToString() == a.ToString()); |
808 } | 808 } |
| 809 |
| 810 TEST(P224, Infinity) { |
| 811 char zeros[56]; |
| 812 memset(zeros, 0, sizeof(zeros)); |
| 813 |
| 814 // Test that x^0 = ∞. |
| 815 Point a; |
| 816 p224::ScalarBaseMult(reinterpret_cast<const uint8_t*>(zeros), &a); |
| 817 EXPECT_TRUE(memcmp(zeros, a.ToString().data(), sizeof(zeros)) == 0); |
| 818 |
| 819 // We shouldn't allow ∞ to be imported. |
| 820 EXPECT_FALSE(a.SetFromString(std::string(zeros, sizeof(zeros)))); |
| 821 } |
OLD | NEW |