rsa.h
1 /*
2 ** UICore
3 ** Copyright (c) 1997-2015 The UICore 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 UICore 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 #include "secret.h"
50 #include "../System/databuffer.h"
51 
52 namespace uicore
53 {
54  class Random;
55 
59  class RSA
60  {
61  public:
70  static void create_keypair(Random &random, SecretPtr &out_private_exponent, DataBufferPtr &out_public_exponent, DataBufferPtr &out_modulus, int key_size_in_bits = 1024, int public_exponent_value = 65537);
71 
80  static DataBufferPtr encrypt(int block_type, Random &random, const DataBufferPtr &in_public_exponent, const DataBufferPtr &in_modulus, const SecretPtr &in_data);
81 
93  static DataBufferPtr 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);
94 
104  static SecretPtr decrypt(const SecretPtr &in_private_exponent, const DataBufferPtr &in_modulus, const DataBufferPtr &in_data);
105 
117  static SecretPtr decrypt(const SecretPtr &in_private_exponent, const void *in_modulus, unsigned int in_modulus_size, const void *in_data, unsigned int in_data_size);
118  };
119 }
static void create_keypair(Random &random, SecretPtr &out_private_exponent, DataBufferPtr &out_public_exponent, DataBufferPtr &out_modulus, int key_size_in_bits=1024, int public_exponent_value=65537)
Create a keypair.
RSA class.
Definition: rsa.h:59
std::shared_ptr< Secret > SecretPtr
Definition: secret.h:59
static SecretPtr decrypt(const SecretPtr &in_private_exponent, const DataBufferPtr &in_modulus, const DataBufferPtr &in_data)
Decrypt.
Random class.
Definition: random.h:39
std::shared_ptr< DataBuffer > DataBufferPtr
Definition: databuffer.h:66
static DataBufferPtr encrypt(int block_type, Random &random, const DataBufferPtr &in_public_exponent, const DataBufferPtr &in_modulus, const SecretPtr &in_data)
Encrypt.
Definition: Application/application.h:35