digiKam
yfrsa.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2010-11-14
7  * Description : Yandex authentication module
8  *
9  * This is an Yandex implementation of RSA algorithm.
10  * It differs from the standard RSA and incompatible with it.
11  *
12  * Based on code parts from pegwit program written by George Barwood.
13  * This code is in the public domain; do with it what you wish.
14  *
15  * See links for more details:
16  * Author homepage
17  * www.george-barwood.pwp.blueyonder.co.uk/hp/
18  *
19  * Getting token for Yandex.Fotki web service
20  * api.yandex.ru/fotki/doc/overview/authorization-token.xml
21  *
22  * Yandex published source code
23  * download.yandex.ru/api-fotki/c-yamrsa.tar.gz
24  *
25  * Yandex company web site
26  * https://company.yandex.com/
27  *
28  * Included by Roman Tsisyk <roman at tsisyk dot com>
29  * All unneeded parts was commented out and can be removed
30  *
31  * ============================================================ */
32 
33 #ifndef DIGIKAM_YF_RSA_H
34 #define DIGIKAM_YF_RSA_H
35 
36 // C++ includes
37 
38 #include <cstdlib> // std::size_t
39 
40 namespace YFAuth
41 {
42 // VLONG.HPP ---------------------------------
43 
44 class vlong // very long integer - can be used like long
45 {
46 public:
47 
48  // Standard arithmetic operators
49 
50  friend vlong operator +( const vlong& x, const vlong& y );
51  friend vlong operator -( const vlong& x, const vlong& y );
52  friend vlong operator *( const vlong& x, const vlong& y );
53  friend vlong operator /( const vlong& x, const vlong& y );
54  friend vlong operator %( const vlong& x, const vlong& y );
55  vlong& operator +=( const vlong& x );
56  vlong& operator -=( const vlong& x );
57 
58 public:
59 
60  // Standard comparison operators
61 
62  friend inline int operator !=( const vlong& x, const vlong& y )
63  {
64  return (x.cf( y ) != 0);
65  }
66 
67  friend inline int operator ==( const vlong& x, const vlong& y )
68  {
69  return (x.cf( y ) == 0);
70  }
71 
72  friend inline int operator >=( const vlong& x, const vlong& y )
73  {
74  return (x.cf( y ) >= 0);
75  }
76 
77  friend inline int operator <=( const vlong& x, const vlong& y )
78  {
79  return (x.cf( y ) <= 0);
80  }
81 
82  friend inline int operator > ( const vlong& x, const vlong& y )
83  {
84  return (x.cf( y ) > 0);
85  }
86 
87  friend inline int operator < ( const vlong& x, const vlong& y )
88  {
89  return (x.cf( y ) < 0);
90  }
91 
92 public:
93 
94  // Construction and conversion operations
95  vlong(unsigned x = 0); // krazy:exclude=explicit
96  // copy constructor
97  vlong(const vlong& x);
98  ~vlong();
99 
100  operator unsigned ();
101  vlong& operator =(const vlong& x);
102 
103  void load( unsigned* a, unsigned n ); // load value, a[0] is lsw
104  void store( unsigned* a, unsigned n ) const; // low level save, a[0] is lsw
105  unsigned get_nunits() const;
106  unsigned bits() const;
107 
108 private:
109 
110  class vlong_value* value;
111  int negative;
112  int cf( const vlong& x ) const;
113  void docopy();
114 
115  friend class monty;
116 };
117 
118 // RSA.HPP -------------------------------------------
119 
121 {
122 public:
123 
125  vlong encrypt( const vlong& plain ); // Requires 0 <= plain < m
126  void MakeMe(const char*);
127 };
128 
129 class private_key : public public_key
130 {
131 public:
132 
134 };
135 
136 // ---------------------------------------------------
137 
138 #define MAX_CRYPT_BITS 1024
139 
141 {
142  class private_key prkface;
143 
144  void EncryptPortion(const char* pt, std::size_t, char* ct, std::size_t&);
145 
146 public:
147 
149  virtual ~CCryptoProviderRSA();
150 
151  virtual void Encrypt(const char*, std::size_t, char*, std::size_t&);
152  virtual void ImportPublicKey(const char*);
153 };
154 
155 } // namespace YFAuth
156 
157 #endif // DIGIKAM_YF_RSA_H
Definition: yfrsa.h:141
virtual void ImportPublicKey(const char *)
Definition: yfrsa.cpp:901
virtual void Encrypt(const char *, std::size_t, char *, std::size_t &)
Definition: yfrsa.cpp:906
CCryptoProviderRSA()
Definition: yfrsa.cpp:860
virtual ~CCryptoProviderRSA()
Definition: yfrsa.cpp:864
Definition: yfrsa.h:130
vlong p
Definition: yfrsa.h:133
vlong q
Definition: yfrsa.h:133
Definition: yfrsa.h:121
void MakeMe(const char *)
Definition: yfrsa.cpp:855
vlong m
Definition: yfrsa.h:124
vlong e
Definition: yfrsa.h:124
vlong encrypt(const vlong &plain)
Definition: yfrsa.cpp:789
Definition: yfrsa.h:45
unsigned get_nunits() const
Definition: yfrsa.cpp:475
friend int operator<=(const vlong &x, const vlong &y)
Definition: yfrsa.h:77
friend int operator!=(const vlong &x, const vlong &y)
Definition: yfrsa.h:62
friend int operator>(const vlong &x, const vlong &y)
Definition: yfrsa.h:82
void store(unsigned *a, unsigned n) const
Definition: yfrsa.cpp:467
friend int operator<(const vlong &x, const vlong &y)
Definition: yfrsa.h:87
friend int operator>=(const vlong &x, const vlong &y)
Definition: yfrsa.h:72
friend class monty
Definition: yfrsa.h:115
~vlong()
Definition: yfrsa.cpp:548
friend vlong operator/(const vlong &x, const vlong &y)
Definition: yfrsa.cpp:632
unsigned bits() const
Definition: yfrsa.cpp:480
vlong(unsigned x=0)
Definition: yfrsa.cpp:517
void load(unsigned *a, unsigned n)
Definition: yfrsa.cpp:456
vlong & operator-=(const vlong &x)
Definition: yfrsa.cpp:587
vlong & operator=(const vlong &x)
Definition: yfrsa.cpp:531
friend vlong operator%(const vlong &x, const vlong &y)
Definition: yfrsa.cpp:655
friend vlong operator+(const vlong &x, const vlong &y)
Definition: yfrsa.cpp:610
friend vlong operator*(const vlong &x, const vlong &y)
Definition: yfrsa.cpp:624
vlong & operator+=(const vlong &x)
Definition: yfrsa.cpp:565
friend int operator==(const vlong &x, const vlong &y)
Definition: yfrsa.h:67
friend vlong operator-(const vlong &x, const vlong &y)
Definition: yfrsa.cpp:617
qulonglong value
Definition: itemviewutilities.cpp:592
Definition: yfauth.cpp:40