~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to src/fuzzer/ecc_helper.h

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* (C) 2015,2016 Jack Lloyd
 
3
*
 
4
* Botan is released under the Simplified BSD License (see license.txt)
 
5
*/
 
6
 
 
7
#ifndef ECC_HELPERS_H_
 
8
#define ECC_HELPERS_H_
 
9
 
 
10
#include "fuzzers.h"
 
11
#include <botan/curve_gfp.h>
 
12
#include <botan/ec_group.h>
 
13
#include <botan/reducer.h>
 
14
 
 
15
namespace {
 
16
 
 
17
inline std::ostream& operator<<(std::ostream& o, const Botan::PointGFp& point)
 
18
   {
 
19
   o << point.get_affine_x() << "," << point.get_affine_y();
 
20
   return o;
 
21
   }
 
22
 
 
23
void check_ecc_math(const Botan::EC_Group& group,
 
24
                    const uint8_t in[], size_t len)
 
25
   {
 
26
   // These depend only on the group, which is also static
 
27
   static const Botan::PointGFp base_point = group.get_base_point();
 
28
   static Botan::Blinded_Point_Multiply blind(base_point, group.get_order(), 4);
 
29
 
 
30
   const size_t hlen = len / 2;
 
31
   const Botan::BigInt a = Botan::BigInt::decode(in, hlen);
 
32
   const Botan::BigInt b = Botan::BigInt::decode(in + hlen, len - hlen);
 
33
 
 
34
   const Botan::BigInt c = a + b;
 
35
 
 
36
   const Botan::PointGFp P = base_point * a;
 
37
   const Botan::PointGFp Q = base_point * b;
 
38
   const Botan::PointGFp R = base_point * c;
 
39
 
 
40
   const Botan::PointGFp A1 = P + Q;
 
41
   const Botan::PointGFp A2 = Q + P;
 
42
 
 
43
   FUZZER_ASSERT_EQUAL(A1, A2);
 
44
 
 
45
   const Botan::PointGFp P1 = blind.blinded_multiply(a, fuzzer_rng());
 
46
   const Botan::PointGFp Q1 = blind.blinded_multiply(b, fuzzer_rng());
 
47
   const Botan::PointGFp R1 = blind.blinded_multiply(c, fuzzer_rng());
 
48
 
 
49
   const Botan::PointGFp S1 = P1 + Q1;
 
50
   const Botan::PointGFp S2 = Q1 + P1;
 
51
 
 
52
   FUZZER_ASSERT_EQUAL(S1, S2);
 
53
   FUZZER_ASSERT_EQUAL(S1, A1);
 
54
   }
 
55
 
 
56
}
 
57
 
 
58
#endif