Security Scol plugin
securityplugin.cpp
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25/*
26 Security based on beeCrypt library : beecrypt.sourceforge.net
27 First version : may 2009
28 Author : Bastien BOURINEAU
29*/
30
37#include <scolPlugin.h>
38
39#include "rsa.h"
40using CryptoPP::RSA;
41using CryptoPP::InvertibleRSAFunction;
42using CryptoPP::RSAES_OAEP_SHA_Encryptor;
43using CryptoPP::RSAES_OAEP_SHA_Decryptor;
44
45using CryptoPP::RSAES_PKCS1v15_Encryptor;
46using CryptoPP::RSAES_PKCS1v15_Decryptor;
47
48using CryptoPP::InvertibleRSAFunction;
49typedef CryptoPP::RSAFunction RSAPublicKey;
50typedef CryptoPP::InvertibleRSAFunction RSAPrivateKey;
51
52#include "sha.h"
53using CryptoPP::SHA1;
54
55#include "filters.h"
56using CryptoPP::StringSink;
57using CryptoPP::StringSource;
58using CryptoPP::PK_EncryptorFilter;
59using CryptoPP::PK_DecryptorFilter;
60using CryptoPP::StreamTransformationFilter;
61
62#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
63#include "../cryptopp/md5.h"
64
65#include "aes.h"
66using CryptoPP::AES;
67
68#include "ccm.h"
69using CryptoPP::CBC_Mode;
70
71#include "files.h"
72using CryptoPP::FileSink;
73using CryptoPP::FileSource;
74
75#include "osrng.h"
76using CryptoPP::AutoSeededRandomPool;
77
78#include "secblock.h"
79using CryptoPP::SecByteBlock;
80
81#include "cryptlib.h"
82using CryptoPP::Exception;
83using CryptoPP::DecodingResult;
84
85#include <hex.h>
86using CryptoPP::HexEncoder;
87using CryptoPP::HexDecoder;
88
89#include <string>
90using std::string;
91
92#include <iostream>
93using std::cout;
94using std::cerr;
95using std::endl;
96
97
98//#define _SCOL_DEBUG_
99
101#ifdef SCOL_STATIC
102extern cbmachine ww;
103extern mmachine mm;
104#else
105cbmachine ww;
106mmachine mm;
107#endif
108
125int _RSAgetKeyPair(mmachine m)
126{
127#ifdef _SCOL_DEBUG_
128 MMechostr(0,"_RSAgetKeyPair\n");
129#endif
130
131 int keysize = MMget(m, 0);
132 if (keysize == NIL)
133 {
134 MMset(m, 0, NIL);
135 return 0 ;
136 }
137
139 // Generate keys
140 AutoSeededRandomPool rng;
141
142 InvertibleRSAFunction parameters;
143 parameters.GenerateRandomWithKeySize(rng, MTOI(keysize));
144
145 RSA::PrivateKey privateKey(parameters);
146 RSA::PublicKey publicKey(parameters);
147
148 //RSAPrivateKey privateKey;
149 //privateKey.Initialize(rng, keysize /*, e=17*/);
150 //RSAPublicKey publicKey( privateKey );
151
152 if (!privateKey.Validate(rng, 3) || !publicKey.Validate(rng, 3))
153 {
154 MMechostr(0,"_RSAgetKeyPair Privilege Error\n");
155 MMset(m, 0, NIL);
156 return 0;
157 }
158
159 string sPublicKey;
160 string sPrivateKey;
161
162 HexEncoder hxPublicKey(new StringSink(sPublicKey));
163 HexEncoder hxPrivateKey(new StringSink(sPrivateKey));
164
165 publicKey.Save(hxPublicKey);
166 privateKey.Save(hxPrivateKey);
167
168 // remove function parameter before the str push
169 MMpull(m);
170 Mpushstrbloc(m, (char *)sPrivateKey.c_str());
171 Mpushstrbloc(m, (char *)sPublicKey.c_str());
172 if(MMpush(m,2*2))
173 return MERRMEM;
174
175 if(int k=MBdeftab(m))
176 return k;
177
178#ifdef _SCOL_DEBUG_
179 MMechostr(0,"ok\n");
180#endif
181
182 return 0;
183}
184
185
195int _RSAencryptMessage(mmachine m)
196{
197#ifdef _SCOL_DEBUG_
198 MMechostr(0,"_RSAcryptMessage\n");
199#endif
200
201 int key = MTOP(MMpull(m));
202 int mess = MTOP(MMpull(m));
203 if (mess==NIL || key==NIL)
204 {
205 MMpush(m, NIL);
206 return 0;
207 }
208
209 int msize = MMsizestr(m, mess);
210 byte* smess = (byte*)MMstart(m, (mess)+1);
211 char* sckey = MMstartstr(m, key);
212
213 if (smess == NULL || sckey == NULL)
214 {
215 MMpush(m, NIL);
216 return 0;
217 }
218
219 string sPublicKey = string(sckey);
220 string sEncrypted, sEncryptedHex;
221
222 //MMechostr(0,"_RSAencryptMessage : %s \n", sMessage.c_str());
223
224 AutoSeededRandomPool rng;
225
226 try
227 {
228 RSA::PublicKey publicKey;
229 HexDecoder decoder;
230 decoder.Put((byte*)sPublicKey.c_str(), sPublicKey.size());
231 decoder.MessageEnd();
232 publicKey.Load(decoder);
233
234 //RSAES_PKCS1v15_Encryptor encrypt( publicKey );
235 RSAES_OAEP_SHA_Encryptor encrypt( publicKey );
236
237 StringSource(smess, msize, true, new PK_EncryptorFilter(rng, encrypt, new StringSink(sEncrypted)));
238
239 HexEncoder encoder;
240 encoder.Attach(new StringSink(sEncryptedHex));
241 encoder.Put((byte *)sEncrypted.c_str(), sEncrypted.size());
242 encoder.MessageEnd();
243 }
244 catch (CryptoPP::Exception& encrypt)
245 {
246 MMechostr(0,"_RSAencryptMessage Error : %s \n", encrypt.what());
247 MMpush(m, NIL);
248 return 0;
249 }
250
251 int res = MMmalloc(m, STR_SIZE(sEncryptedHex.size()), TYPEBUF);
252 if (res == NIL)
253 {
254 MMpush(m, NIL);
255 return MERRMEM;
256 }
257
258 MMstore(m, res, 0, sEncryptedHex.size());
259 char* BS = MMstartstr(m, res);
260 memcpy(BS, sEncryptedHex.c_str(), sEncryptedHex.size());
261 BS[sEncryptedHex.size()] = 0;
262 int k = MMpush(m, PTOM(res));
263
264#ifdef _SCOL_DEBUG_
265 MMechostr(0,"ok\n");
266#endif
267
268 return k;
269}
270
271
281int _RSAdecryptMessage(mmachine m)
282{
283#ifdef _SCOL_DEBUG_
284 MMechostr(0,"_RSAdecryptMessage\n");
285#endif
286
287 int key = MTOP(MMpull(m));
288 int mess = MTOP(MMpull(m));
289 if (mess==NIL || key==NIL)
290 {
291 MMpush(m, NIL);
292 return 0;
293 }
294
295 int msize = MMsizestr(m, mess);
296 byte* smess = (byte*)MMstart(m, (mess)+1);
297 char* sckey = MMstartstr(m,key);
298
299 if (smess == NULL || sckey == NULL)
300 {
301 MMpush(m, NIL);
302 return 0;
303 }
304
305 string sPrivateKey = string(sckey);
306 string sDecrypted, sMessage;
307
308 //MMechostr(0,"_RSAdecryptMessage : %s \n", sMessage.c_str());
309
310 AutoSeededRandomPool rng;
311
312 try
313 {
314 HexDecoder mdecoder;
315 mdecoder.Attach(new StringSink(sMessage));
316 mdecoder.Put(smess, msize);
317 mdecoder.MessageEnd();
318
319 RSA::PrivateKey privateKey;
320 HexDecoder kdecoder;
321 kdecoder.Put((byte*)sPrivateKey.c_str(), sPrivateKey.size());
322 kdecoder.MessageEnd();
323 privateKey.Load(kdecoder);
324
325 //RSAES_PKCS1v15_Decryptor decrypt( privateKey );
326 RSAES_OAEP_SHA_Decryptor decrypt(privateKey);
327
328 StringSource(sMessage, true, new PK_DecryptorFilter(rng, decrypt, new StringSink(sDecrypted)));
329
330 //MMechostr(0,"_RSAdecryptMessage : %s \n", sDecrypted.c_str());
331
332 }
333 catch (CryptoPP::Exception& decrypt)
334 {
335 MMechostr(0, "_RSAdecryptMessage Error : %s \n", decrypt.what());
336 return MMpush(m, NIL);
337 }
338
339 int res = MMmalloc(m, STR_SIZE(sDecrypted.size()), TYPEBUF);
340 if (res == NIL)
341 {
342 MMpush(m, NIL);
343 return MERRMEM;
344 }
345
346 MMstore(m, res, 0, sDecrypted.size());
347 char* BS = MMstartstr(m, res);
348 memcpy(BS, sDecrypted.c_str(), sDecrypted.size());
349 BS[sDecrypted.size()] = 0;
350 int k = MMpush(m, PTOM(res));
351
352#ifdef _SCOL_DEBUG_
353 MMechostr(0,"ok\n");
354#endif
355
356 return k;
357}
358
359
367// fun[] [S]
368int _AESgetKey(mmachine m)
369{
370#ifdef _SCOL_DEBUG_
371 MMechostr(0,"_AESgetKey\n");
372#endif
373
374 AutoSeededRandomPool prng;
375
376 byte key[AES::DEFAULT_KEYLENGTH];
377 prng.GenerateBlock(key, sizeof(key));
378
379 string sKey;
380
381 // Pretty print
382 StringSource(key, sizeof(key), true, new HexEncoder(new StringSink(sKey)));
383
384 int k = Mpushstrbloc(m, (char *)sKey.c_str());
385
386#ifdef _SCOL_DEBUG_
387 MMechostr(0,"ok\n");
388#endif
389
390 return k;
391}
392
393
394
404int _AESencryptMessage(mmachine m)
405{
406#ifdef _SCOL_DEBUG_
407 MMechostr(0,"_AESencryptMessage\n");
408#endif
409
410 int key = MTOP(MMpull(m));
411 int mess = MTOP(MMpull(m));
412 if (mess==NIL || key==NIL)
413 {
414 MMpush(m, NIL);
415 return 0;
416 }
417
418 int msize = MMsizestr(m, mess);
419 byte* smess = (byte*)MMstart(m, (mess)+1);
420 char* sckey = MMstartstr(m, key);
421
422 if (smess == NULL || sckey == NULL)
423 {
424 MMpush(m, NIL);
425 return 0;
426 }
427
428 //MMechostr(MSKFOO,"_AESencryptMessage : mess char size %i \n", msize);
429
430 string sKeyHex = string(sckey);
431 string sEncrypted, sEncryptedHex, sIv, sKey;
432
433 //MMechostr(MSKFOO,"_AESencryptMessage : mess string size %i \n", sMessage.length());
434 //MMechostr(0,"_AESencryptMessage : %s \n", sMessage.c_str());
435
436 AutoSeededRandomPool prng;
437
438 byte iv[AES::BLOCKSIZE];
439 prng.GenerateBlock(iv, sizeof(iv));
440
441 try
442 {
443 HexDecoder kdecoder;
444 kdecoder.Attach(new StringSink(sKey));
445 kdecoder.Put((byte *)sKeyHex.c_str(), sKeyHex.size());
446 kdecoder.MessageEnd();
447 }
448 catch( CryptoPP::Exception& e)
449 {
450 MMechostr(0,"_AESencryptMessage Error : %s \n", e.what());
451 return MMpush(m,NIL) ;
452 }
453
454 try
455 {
457 encrypt.SetKeyWithIV((byte *)sKey.c_str(), sKey.size(), iv);
458
459 // The StreamTransformationFilter adds padding
460 // as required. CBC Mode must be padded to the
461 // block size of the cipher.
462 StringSource(smess, msize, true, new StreamTransformationFilter(encrypt, new StringSink(sEncrypted)));
463 }
464 catch( CryptoPP::Exception& encrypt)
465 {
466 MMechostr(0,"_AESencryptMessage Error : %s \n", encrypt.what());
467 return MMpush(m, NIL);
468 }
469
470 try
471 {
472 HexEncoder encoder;
473 encoder.Attach(new StringSink(sEncryptedHex));
474 encoder.Put((byte *)sEncrypted.c_str(), sEncrypted.size());
475 encoder.MessageEnd();
476 }
477 catch( CryptoPP::Exception& e)
478 {
479 MMechostr(0,"_AESencryptMessage Error : %s \n", e.what());
480 return MMpush(m, NIL);
481 }
482
483 try
484 {
485 // encode iv
486 StringSource( iv, sizeof(iv), true, new HexEncoder(new StringSink(sIv)));
487 }
488 catch( CryptoPP::Exception& e)
489 {
490 MMechostr(0,"_AESencryptMessage Error : %s \n", e.what());
491 return MMpush(m, NIL);
492 }
493
494 // Add message after IV for CBC mode
495 sIv.append(sEncryptedHex);
496
497 int res = MMmalloc(m, STR_SIZE(sIv.size()), TYPEBUF);
498 if (res == NIL)
499 {
500 MMpush(m, NIL);
501 return MERRMEM;
502 }
503
504 MMstore(m, res, 0, sIv.size());
505 char* BS = MMstartstr(m, res);
506 memcpy(BS, sIv.c_str(), sIv.size());
507 BS[sIv.size()] = 0;
508 int k = MMpush(m, PTOM(res));
509
510#ifdef _SCOL_DEBUG_
511 MMechostr(0,"ok\n");
512#endif
513
514 return k;
515}
516
517
518
528int _AESdecryptMessage(mmachine m)
529{
530#ifdef _SCOL_DEBUG_
531 MMechostr(0,"_AESencryptMessage\n");
532#endif
533
534 int key = MTOP(MMpull(m));
535 int mess = MTOP(MMpull(m));
536 if (mess==NIL || key==NIL)
537 {
538 MMpush(m, NIL);
539 return 0;
540 }
541
542 int msize = MMsizestr(m, mess);
543 byte* smess = (byte*)MMstart(m, (mess)+1);
544 char* sckey = MMstartstr(m,key);
545
546 if (smess == NULL || sckey == NULL)
547 {
548 MMpush(m, NIL);
549 return 0;
550 }
551
552 string sKeyHex = string(sckey);
553 string sMessage, sEncrypted, sEncryptedHex, sKey;
554
555 try
556 {
557 HexDecoder mdecoder;
558 mdecoder.Attach( new StringSink( sEncrypted ) );
559 mdecoder.Put(smess, msize);
560 mdecoder.MessageEnd();
561 }
562 catch( CryptoPP::Exception& e)
563 {
564 MMechostr(0,"_AESdecryptMessage Error : %s \n", e.what());
565 return MMpush(m, NIL);
566 }
567
568 try
569 {
570 HexDecoder kdecoder;
571 kdecoder.Attach( new StringSink( sKey ) );
572 kdecoder.Put( (byte *)sKeyHex.c_str(), sKeyHex.size() );
573 kdecoder.MessageEnd();
574 }
575 catch( CryptoPP::Exception& e)
576 {
577 MMechostr(0,"_AESdecryptMessage Error : %s \n", e.what());
578 return MMpush(m, NIL);
579 }
580
581 try{
583 // extract the first 16 bits from the message to get IV for CBC mode
584 decrypt.SetKeyWithIV((byte *)sKey.c_str(), sKey.size(), (byte *)sEncrypted.substr(0, 16).c_str());
585
586 // The StreamTransformationFilter removes
587 // padding as required.
588 StringSource s(sEncrypted.substr(16), true, new StreamTransformationFilter(decrypt, new StringSink(sMessage)));
589 }
590 catch( CryptoPP::Exception& decrypt)
591 {
592 MMechostr(0,"_AESdecryptMessage Error : %s \n", decrypt.what());
593 return MMpush(m, NIL);
594 }
595
596 int res = MMmalloc(m, STR_SIZE(sMessage.size()), TYPEBUF);
597 if (res == NIL)
598 {
599 MMpush(m, NIL);
600 return MERRMEM;
601 }
602
603 MMstore(m, res, 0, sMessage.size());
604 char* BS = MMstartstr(m, res);
605 memcpy(BS, sMessage.c_str(), sMessage.size());
606 BS[sMessage.size()] = 0;
607 int k = MMpush(m, PTOM(res));
608 //Mpushstrbloc(m, (char*)sMessage.c_str());
609
610#ifdef _SCOL_DEBUG_
611 MMechostr(0,"ok\n");
612#endif
613
614 return k;
615}
616
625int _MD5value(mmachine m)
626{
627#ifdef _SCOL_DEBUG_
628 MMechostr(0,"_MD5value\n");
629#endif
630
631 int mess = MTOP(MMpull(m));
632 if (mess==NIL)
633 {
634 MMpush(m, NIL);
635 return 0;
636 }
637
638 int msize = MMsizestr(m, mess);
639 byte* smess = (byte*)MMstart(m, (mess)+1);
640
641 if (smess == NULL)
642 {
643 MMpush(m, NIL);
644 return 0;
645 }
646
647 string sMD5;
648 try
649 {
650 byte digest[ CryptoPP::Weak::MD5::DIGESTSIZE ];
651
652 CryptoPP::Weak::MD5 hash;
653 hash.CalculateDigest( digest, (const byte*)smess, msize );
654
655 CryptoPP::HexEncoder encoder;
656 encoder.Attach( new CryptoPP::StringSink( sMD5 ) );
657 encoder.Put( digest, sizeof(digest) );
658 encoder.MessageEnd();
659 }
660 catch (CryptoPP::Exception& encrypt)
661 {
662 MMechostr(0,"_MD5value Error : %s \n", encrypt.what());
663 MMpush(m, NIL);
664 return 0;
665 }
666
667 int res = MMmalloc(m, STR_SIZE(sMD5.size()), TYPEBUF);
668 if (res == NIL)
669 {
670 MMpush(m, NIL);
671 return MERRMEM;
672 }
673
674 MMstore(m, res, 0, sMD5.size());
675 char* BS = MMstartstr(m, res);
676 memcpy(BS, sMD5.c_str(), sMD5.size());
677 BS[sMD5.size()] = 0;
678 int k = MMpush(m, PTOM(res));
679
680#ifdef _SCOL_DEBUG_
681 MMechostr(0,"ok\n");
682#endif
683
684 return k;
685}
686
695int _SHA256value(mmachine m)
696{
697#ifdef _SCOL_DEBUG_
698 MMechostr(0, "_SHA256value\n");
699#endif
700
701 int mess = MTOP(MMpull(m));
702 if (mess == NIL)
703 {
704 MMpush(m, NIL);
705 return 0;
706 }
707
708 int msize = MMsizestr(m, mess);
709 byte* smess = (byte*)MMstart(m, (mess)+1);
710
711 if (smess == NULL)
712 {
713 MMpush(m, NIL);
714 return 0;
715 }
716
717 string sScrypt;
718 try
719 {
720 byte digest[CryptoPP::SHA256::DIGESTSIZE];
721
722 CryptoPP::SHA256 hash;
723 hash.CalculateDigest(digest, (const byte*)smess, msize);
724
725 CryptoPP::HexEncoder encoder;
726 encoder.Attach(new CryptoPP::StringSink(sScrypt));
727 encoder.Put(digest, sizeof(digest));
728 encoder.MessageEnd();
729 }
730 catch (CryptoPP::Exception& encrypt)
731 {
732 MMechostr(0, "_SHA256value Error : %s \n", encrypt.what());
733 MMpush(m, NIL);
734 return 0;
735 }
736
737 int res = MMmalloc(m, STR_SIZE(sScrypt.size()), TYPEBUF);
738 if (res == NIL)
739 {
740 MMpush(m, NIL);
741 return MERRMEM;
742 }
743
744 MMstore(m, res, 0, sScrypt.size());
745 char* BS = MMstartstr(m, res);
746 memcpy(BS, sScrypt.c_str(), sScrypt.size());
747 BS[sScrypt.size()] = 0;
748 int k = MMpush(m, PTOM(res));
749
750#ifdef _SCOL_DEBUG_
751 MMechostr(0, "ok\n");
752#endif
753
754 return k;
755}
756
765int _SHA512value(mmachine m)
766{
767#ifdef _SCOL_DEBUG_
768 MMechostr(0, "_SHA512value\n");
769#endif
770
771 int mess = MTOP(MMpull(m));
772 if (mess == NIL)
773 {
774 MMpush(m, NIL);
775 return 0;
776 }
777
778 int msize = MMsizestr(m, mess);
779 byte* smess = (byte*)MMstart(m, (mess)+1);
780
781 if (smess == NULL)
782 {
783 MMpush(m, NIL);
784 return 0;
785 }
786
787 string sScrypt;
788 try
789 {
790 byte digest[CryptoPP::SHA512::DIGESTSIZE];
791
792 CryptoPP::SHA512 hash;
793 hash.CalculateDigest(digest, (const byte*)smess, msize);
794
795 CryptoPP::HexEncoder encoder;
796 encoder.Attach(new CryptoPP::StringSink(sScrypt));
797 encoder.Put(digest, sizeof(digest));
798 encoder.MessageEnd();
799 }
800 catch (CryptoPP::Exception& encrypt)
801 {
802 MMechostr(0, "_SHA512value Error : %s \n", encrypt.what());
803 MMpush(m, NIL);
804 return 0;
805 }
806
807 int res = MMmalloc(m, STR_SIZE(sScrypt.size()), TYPEBUF);
808 if (res == NIL)
809 {
810 MMpush(m, NIL);
811 return MERRMEM;
812 }
813
814 MMstore(m, res, 0, sScrypt.size());
815 char* BS = MMstartstr(m, res);
816 memcpy(BS, sScrypt.c_str(), sScrypt.size());
817 BS[sScrypt.size()] = 0;
818 int k = MMpush(m, PTOM(res));
819
820#ifdef _SCOL_DEBUG_
821 MMechostr(0, "ok\n");
822#endif
823
824 return k;
825}
826
827static NativeDefinition sSecurityDef[] =
828{
829 { "_RSAgetKeyPair", 1, "fun [I] [S S]", _RSAgetKeyPair },
830 { "_RSAencryptMessage", 2, "fun [S S] S", _RSAencryptMessage },
831 { "_RSAdecryptMessage", 2, "fun [S S] S", _RSAdecryptMessage },
832 { "_AESgetKey", 0, "fun [] S", _AESgetKey },
833 { "_AESencryptMessage", 2, "fun [S S] S", _AESencryptMessage },
834 { "_AESdecryptMessage", 2, "fun [S S] S", _AESdecryptMessage },
835 { "_MD5value", 1, "fun [S] S", _MD5value },
836 { "_SHA256value", 1, "fun [S] S", _SHA256value },
837 { "_SHA512value", 1, "fun [S] S", _SHA512value }
838};
839
840// Everything inside _cond and _endcond is ignored by doxygen
842
847int LoadSecurity(mmachine m)
848{
849 int k = PKhardpak2(m, "SecurityEngine.pkg-1.0", sizeof(sSecurityDef) / sizeof(sSecurityDef[0]), sSecurityDef);
850 MMechostr(MSKDEBUG,"\n" );
851 return k;
852}
854
855#ifndef SCOL_STATIC
859extern "C" SCOL_EXPORT int ScolLoadPlugin(mmachine m, cbmachine w)
860{
861 int k = 0;
862 SCOLinitplugin(w);
863 LoadSecurity(m);
864 return k;
865}
866
870extern "C" SCOL_EXPORT int ScolUnloadPlugin()
871{
872 return 0;
873}
874#else
878extern "C" SCOL_EXPORT int ScolSecurityLoadPlugin(mmachine m, cbmachine w)
879{
880 int k = 0;
881 SCOLinitplugin(w);
882 LoadSecurity(m);
883 return k;
884}
885
889extern "C" SCOL_EXPORT int ScolSecurityUnloadPlugin()
890{
891 return 0;
892}
893#endif //SCOL_STATIC
Class file for the AES cipher (Rijndael)
CCM block cipher mode of operation.
void Load(BufferedTransformation &bt)
BER decode ASN.1 object.
Definition asn.h:696
void Save(BufferedTransformation &bt) const
DER encode ASN.1 object.
Definition asn.h:691
bool MessageEnd(int propagation=-1, bool blocking=true)
Signals the end of messages to the object.
Definition cryptlib.h:1743
virtual void Attach(BufferedTransformation *newAttachment)
Add newAttachment to the end of attachment chain.
Definition cryptlib.cpp:832
size_t Put(byte inByte, bool blocking=true)
Input a byte for processing.
Definition cryptlib.h:1673
Block cipher mode of operation aggregate.
Definition modes.h:347
void GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize)
Generate a random key or crypto parameters.
Definition cryptlib.cpp:840
Decode base 16 data back to bytes.
Definition hex.h:35
Converts given data to base 16.
Definition hex.h:16
RSA trapdoor function using the private key.
Definition rsa.h:63
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
Definition rsa.cpp:260
void Save(BufferedTransformation &bt) const
DER encode ASN.1 object.
Definition rsa.h:105
void Load(BufferedTransformation &bt)
BER decode ASN.1 object.
Definition rsa.h:103
Filter wrapper for PK_Decryptor.
Definition filters.h:1110
Filter wrapper for PK_Encryptor.
Definition filters.h:1095
RSA trapdoor function using the public key.
Definition rsa.h:24
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
Definition rsa.cpp:76
Filter wrapper for StreamTransformation.
Definition filters.h:532
String-based implementation of the Source interface.
Definition filters.h:1459
Abstract base classes that provide a uniform interface to this library.
Classes providing file-based library services.
Implementation of BufferedTransformation's attachment interface.
int _RSAdecryptMessage(mmachine m)
_RSAdecryptMessage : This function decrypt a message using the RSA private key
int _AESgetKey(mmachine m)
_AESgetKey : This function generate an AES key
int _AESdecryptMessage(mmachine m)
_AESdecryptMessage : This function decrypt a message using the AES key
int _MD5value(mmachine m)
_MD5value : This function get the MD5 value from a string
int _SHA512value(mmachine m)
_SHA512value : This function get the SHA512 value from a string
int _RSAencryptMessage(mmachine m)
_RSAencryptMessage : This function encrypt a message using the RSA public key
int _RSAgetKeyPair(mmachine m)
_RSAgetKeyPair : This function generate the RSA private and public key with the size passed in parame...
int _SHA256value(mmachine m)
_SHA256value : This function get the SHA256 value from a string
int _AESencryptMessage(mmachine m)
_AESencryptMessage : This function encrypt a message using the AES key
Classes for HexEncoder and HexDecoder.
Classes for access to the operating system's random number generators.
Classes for the RSA cryptosystem.
Classes and functions for secure memory allocations.
Classes for SHA-1 and SHA-2 family of message digests.