Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: crypto/p224_unittest.cc

Issue 2677583002: Fix non-noise cpplint errors in //crypto. (Closed)
Patch Set: fix p224_unittest.cc Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « crypto/p224_spake.cc ('k') | crypto/random.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "crypto/p224.h" 10 #include "crypto/p224.h"
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 TEST(P224, ExternalToInternalAndBack) { 771 TEST(P224, ExternalToInternalAndBack) {
772 Point point; 772 Point point;
773 773
774 EXPECT_TRUE(point.SetFromString(base::StringPiece( 774 EXPECT_TRUE(point.SetFromString(base::StringPiece(
775 reinterpret_cast<const char *>(kBasePointExternal), 775 reinterpret_cast<const char *>(kBasePointExternal),
776 sizeof(kBasePointExternal)))); 776 sizeof(kBasePointExternal))));
777 777
778 const std::string external = point.ToString(); 778 const std::string external = point.ToString();
779 779
780 ASSERT_EQ(external.size(), 56u); 780 ASSERT_EQ(external.size(), 56u);
781 EXPECT_TRUE(memcmp(external.data(), kBasePointExternal, 781 EXPECT_EQ(0, memcmp(external.data(), kBasePointExternal,
782 sizeof(kBasePointExternal)) == 0); 782 sizeof(kBasePointExternal)));
783 } 783 }
784 784
785 TEST(P224, ScalarBaseMult) { 785 TEST(P224, ScalarBaseMult) {
786 Point point; 786 Point point;
787 787
788 for (size_t i = 0; i < arraysize(kNISTTestVectors); i++) { 788 for (size_t i = 0; i < arraysize(kNISTTestVectors); i++) {
789 p224::ScalarBaseMult(kNISTTestVectors[i].scalar, &point); 789 p224::ScalarBaseMult(kNISTTestVectors[i].scalar, &point);
790 const std::string external = point.ToString(); 790 const std::string external = point.ToString();
791 ASSERT_EQ(external.size(), 56u); 791 ASSERT_EQ(external.size(), 56u);
792 EXPECT_TRUE(memcmp(external.data(), kNISTTestVectors[i].affine, 792 EXPECT_EQ(0, memcmp(external.data(), kNISTTestVectors[i].affine,
793 external.size()) == 0); 793 external.size()));
794 } 794 }
795 } 795 }
796 796
797 TEST(P224, Addition) { 797 TEST(P224, Addition) {
798 Point a, b, minus_b, sum, a_again; 798 Point a, b, minus_b, sum, a_again;
799 799
800 ASSERT_TRUE(a.SetFromString(base::StringPiece( 800 ASSERT_TRUE(a.SetFromString(base::StringPiece(
801 reinterpret_cast<const char *>(kNISTTestVectors[10].affine), 56))); 801 reinterpret_cast<const char *>(kNISTTestVectors[10].affine), 56)));
802 ASSERT_TRUE(b.SetFromString(base::StringPiece( 802 ASSERT_TRUE(b.SetFromString(base::StringPiece(
803 reinterpret_cast<const char *>(kNISTTestVectors[11].affine), 56))); 803 reinterpret_cast<const char *>(kNISTTestVectors[11].affine), 56)));
804 804
805 p224::Negate(b, &minus_b); 805 p224::Negate(b, &minus_b);
806 p224::Add(a, b, &sum); 806 p224::Add(a, b, &sum);
807 EXPECT_TRUE(memcmp(&sum, &a, sizeof(sum)) != 0); 807 EXPECT_NE(0, memcmp(&sum, &a, sizeof(sum)));
808 p224::Add(minus_b, sum, &a_again); 808 p224::Add(minus_b, sum, &a_again);
809 EXPECT_TRUE(a_again.ToString() == a.ToString()); 809 EXPECT_EQ(a_again.ToString(), a.ToString());
810 } 810 }
811 811
812 TEST(P224, Infinity) { 812 TEST(P224, Infinity) {
813 char zeros[56]; 813 char zeros[56];
814 memset(zeros, 0, sizeof(zeros)); 814 memset(zeros, 0, sizeof(zeros));
815 815
816 // Test that x^0 = ∞. 816 // Test that x^0 = ∞.
817 Point a; 817 Point a;
818 p224::ScalarBaseMult(reinterpret_cast<const uint8_t*>(zeros), &a); 818 p224::ScalarBaseMult(reinterpret_cast<const uint8_t*>(zeros), &a);
819 EXPECT_TRUE(memcmp(zeros, a.ToString().data(), sizeof(zeros)) == 0); 819 EXPECT_EQ(0, memcmp(zeros, a.ToString().data(), sizeof(zeros)));
820 820
821 // We shouldn't allow ∞ to be imported. 821 // We shouldn't allow ∞ to be imported.
822 EXPECT_FALSE(a.SetFromString(std::string(zeros, sizeof(zeros)))); 822 EXPECT_FALSE(a.SetFromString(std::string(zeros, sizeof(zeros))));
823 } 823 }
824 824
825 } // namespace crypto 825 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/p224_spake.cc ('k') | crypto/random.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698