rsa.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Mark Page
27 ** Michael J. Fromberger
28 */
29 
30 // This class is based on the original MPI library (not NSS, because of license restrictions) with some modifications.
31 // Some ideas and algorithms are from NSS (Netscape Security Suite). Where they have been used, the function contains a reference note
32 //
33 // Note, since September 2011, I believe the MPI homepage is now: http://spinning-yarns.org/michael/mpi/
34 // The license is as follows
35 // This software was written by Michael J. Fromberger,
36 // http://www.dartmouth.edu/~sting/
37 //
38 // See the MPI home page at
39 // http://www.dartmouth.edu/~sting/mpi/
40 //
41 // This software is in the public domain. It is entirely free, and you
42 // may use it and/or redistribute it for whatever purpose you choose;
43 // however, as free software, it is provided without warranty of any
44 // kind, not even the implied warranty of merchantability or fitness for
45 // a particular purpose.
46 
47 #pragma once
48 
49 namespace clan
50 {
53 
54  class Random;
55  class Secret;
56  class DataBuffer;
57 
61  class RSA
62  {
63  public:
72  static void create_keypair(Random &random, Secret &out_private_exponent, DataBuffer &out_public_exponent, DataBuffer &out_modulus, int key_size_in_bits = 1024, int public_exponent_value = 65537);
73 
82  static DataBuffer encrypt(int block_type, Random &random, const DataBuffer &in_public_exponent, const DataBuffer &in_modulus, const Secret &in_data);
83 
95  static DataBuffer encrypt(int block_type, Random &random, const void *in_public_exponent, unsigned int in_public_exponent_size, const void *in_modulus, unsigned int in_modulus_size, const void *in_data, unsigned int in_data_size);
96 
106  static Secret decrypt(const Secret &in_private_exponent, const DataBuffer &in_modulus, const DataBuffer &in_data);
107 
119  static Secret decrypt(const Secret &in_private_exponent, const void *in_modulus, unsigned int in_modulus_size, const void *in_data, unsigned int in_data_size);
120  };
121 
123 }
Definition: clanapp.h:35
Random class.
Definition: random.h:46
static Secret decrypt(const Secret &in_private_exponent, const DataBuffer &in_modulus, const DataBuffer &in_data)
Decrypt.
static void create_keypair(Random &random, Secret &out_private_exponent, DataBuffer &out_public_exponent, DataBuffer &out_modulus, int key_size_in_bits=1024, int public_exponent_value=65537)
Create a keypair.
static DataBuffer encrypt(int block_type, Random &random, const DataBuffer &in_public_exponent, const DataBuffer &in_modulus, const Secret &in_data)
Encrypt.
RSA class.
Definition: rsa.h:61
General purpose data buffer.
Definition: databuffer.h:41
Key class.
Definition: secret.h:44