00001 /* 00002 ** ClanLib SDK 00003 ** Copyright (c) 1997-2011 The ClanLib Team 00004 ** 00005 ** This software is provided 'as-is', without any express or implied 00006 ** warranty. In no event will the authors be held liable for any damages 00007 ** arising from the use of this software. 00008 ** 00009 ** Permission is granted to anyone to use this software for any purpose, 00010 ** including commercial applications, and to alter it and redistribute it 00011 ** freely, subject to the following restrictions: 00012 ** 00013 ** 1. The origin of this software must not be misrepresented; you must not 00014 ** claim that you wrote the original software. If you use this software 00015 ** in a product, an acknowledgment in the product documentation would be 00016 ** appreciated but is not required. 00017 ** 2. Altered source versions must be plainly marked as such, and must not be 00018 ** misrepresented as being the original software. 00019 ** 3. This notice may not be removed or altered from any source distribution. 00020 ** 00021 ** Note: Some of the libraries ClanLib may link to may have additional 00022 ** requirements or restrictions. 00023 ** 00024 ** File Author(s): 00025 ** 00026 ** Mark Page 00027 ** Michael J. Fromberger 00028 */ 00029 00030 // This class is based on the original MPI library (not NSS, because of license restrictions) with some modifications. 00031 // Some ideas and algorithms are from NSS (Netscape Security Suite). Where they have been used, the function contains a reference note 00032 // 00033 // Note, since September 2011, I believe the MPI homepage is now: http://spinning-yarns.org/michael/mpi/ 00034 // The license is as follows 00035 // This software was written by Michael J. Fromberger, 00036 // http://www.dartmouth.edu/~sting/ 00037 // 00038 // See the MPI home page at 00039 // http://www.dartmouth.edu/~sting/mpi/ 00040 // 00041 // This software is in the public domain. It is entirely free, and you 00042 // may use it and/or redistribute it for whatever purpose you choose; 00043 // however, as free software, it is provided without warranty of any 00044 // kind, not even the implied warranty of merchantability or fitness for 00045 // a particular purpose. 00046 00049 00050 #pragma once 00051 00052 #include "../api_core.h" 00053 00054 class CL_Random; 00055 class CL_Secret; 00056 class CL_DataBuffer; 00057 00063 class CL_API_CORE CL_RSA 00064 { 00067 00068 public: 00069 00078 static void create_keypair(CL_Random &random, CL_Secret &out_private_exponent, CL_DataBuffer &out_public_exponent, CL_DataBuffer &out_modulus, int key_size_in_bits = 1024, int public_exponent_value = 65537); 00079 00088 static CL_DataBuffer encrypt(int block_type, CL_Random &random, const CL_DataBuffer &in_public_exponent, const CL_DataBuffer &in_modulus, const CL_Secret &in_data); 00089 00101 static CL_DataBuffer encrypt(int block_type, CL_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); 00102 00112 static CL_Secret decrypt(const CL_Secret &in_private_exponent, const CL_DataBuffer &in_modulus, const CL_DataBuffer &in_data); 00113 00125 static CL_Secret decrypt(const CL_Secret &in_private_exponent, const void *in_modulus, unsigned int in_modulus_size, const void *in_data, unsigned int in_data_size); 00127 }; 00128