rsa.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 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
48 #pragma once
49
50
51 namespace clan
52 {
55
56 class Random;
57 class Secret;
58 class DataBuffer;
59
63 class RSA
64 {
67
68 public:
69
78 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);
79
88 static DataBuffer encrypt(int block_type, Random &random, const DataBuffer &in_public_exponent, const DataBuffer &in_modulus, const Secret &in_data);
89
101 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);
102
112 static Secret decrypt(const Secret &in_private_exponent, const DataBuffer &in_modulus, const DataBuffer &in_data);
113
125 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);
127 };
128
129 }
130
clan
Definition: clanapp.h:35
clan::Random
Random class.
Definition: random.h:46
clan::RSA::decrypt
static Secret decrypt(const Secret &in_private_exponent, const DataBuffer &in_modulus, const DataBuffer &in_data)
Decrypt.
clan::RSA::encrypt
static DataBuffer encrypt(int block_type, Random &random, const DataBuffer &in_public_exponent, const DataBuffer &in_modulus, const Secret &in_data)
Encrypt.
clan::RSA
RSA class.
Definition: rsa.h:63
clan::RSA::create_keypair
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.
clan::DataBuffer
General purpose data buffer.
Definition: databuffer.h:42
clan::Secret
Key class.
Definition: secret.h:45