LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-28-2017, 02:38 PM   #1
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Rep: Reputation: 40
Comparing encryption techniques RSA, Blowfish, etc?


Hi group,

I am writing a peer to peer C program and tried using RSA. I found during testing that RSA has a big problem. In my test program
Code:
int main() {  // main()

  char Key[] = "1234567890";
  unsigned  char Out[1024];
  unsigned  char In[ 1024];
  int       RC, L, RSA_Len;

  RSA *My_RSA = RSA_new();
  BIGNUM *bne = BN_new();
  BN_set_word( bne, RSA_F4 ); 
  
  RC = RSA_generate_key_ex( My_RSA, 2048, bne, NULL );
  BN_free( bne );
  
  if( RSA_check_key( My_RSA ) != 1 )  {
     printf( RED "RSA Make Key Failed\n" OFF );
     return 1;  }
  else printf( BLUE "RSA check key good\n" OFF );

  L = strlen( Key );
  printf ( BLUE "Key: %s" OFF, Key );
  Dump( Key, L );
 
  RSA_Len = RSA_public_encrypt( L,
				(uchar*) Key,
				(uchar*) In,
				My_RSA,
				RSA_PKCS1_OAEP_PADDING );

  printf( BLUE "Encrypted: %d" OFF, RSA_Len );
  Dump( In, RSA_Len );

  int Out_Len;
  Out_Len = RSA_private_decrypt( RSA_Len, RSA_PKCS1_OAEP_PADDING );
  
  printf( BLUE  "Decrypted: %d" OFF, Out_Len );  
  Dump( Out, Out_Len );

  if( !strcmp( (char *)Key, (char *)Out ) )  {
     printf(   "Encrypt/Decrypt failed\n" );  }
  else printf( "Encrypt/Decrypt Passed\n" );

  return 0;  }
I found that RSA created a 256 byte message from a 10 byte input string. I was told that this is due to padding? Further read says that RSA without padding is insecure?

This seams like a real drawback to using RSA? Is there a way to use RSA and not create such a network intense load?

Thanks for your time.
 
Old 02-28-2017, 03:27 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,642
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
Padding is used to increase the security of RSA. See: this StackExchange post and this one.
Quote:
Textbook (non-padded ...) RSA has no semantic security, therefore it is not secure against chosen plaintext attacks or ciphertext attacks. This is because, respectively, it is deterministic (encrypting the same message twice produces the same ciphertext) and multiplicatively homomorphic (an encrypted values can be multiplicatively modified under encryption).
Don't be concerned if the ciphertext is longer than the plaintext: this is by design, and "surely your network can handle it."

As far as cryptographic security is concerned, the general rule is that "the cipher, itself" is never what actually fails. Instead, it's something about key management. Therefore, whenever possible, use an encryption suite that handles everything ... "aye, from beginning to end" ... in standard, peer-reviewed ways. Then, implement the suite in your application precisely as is recommended. Secure communications is "ook big voodoo," and these cats know what they're talking about.

All of the currently available civilian-grade encryption systems are sincerely believed (cryptographers never say "known") to provide more-than-enough security "for civilian purposes,", provided that they are deployed in precisely the right way. It matters far less "which [modern ...] cipher you pick," than that you deploy the cipher the total communications infrastructure correctly.

(Yes, "your tax dollars are at work." NSA etc. is very heavily involved in cipher system peer-review. Part of their mission is to provide support and expertise to civilian communications security and best-practices.)

Last edited by sundialsvcs; 02-28-2017 at 08:13 PM.
 
2 members found this post helpful.
Old 02-28-2017, 03:48 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by MrUmunhum View Post
I found that RSA created a 256 byte message from a 10 byte input string. I was told that this is due to padding? Further read says that RSA without padding is insecure?
A ten byte encryption of a ten byte input string can be NOTHING other than character and/or bit transpositions... easily brute forced and trivial to break regardless of how clever the transposition algorithm might be.

ONE of the things that encryption does is to conceal all knowledge of the encrytped message length by padding at some point in the encryption process.

Last edited by astrogeek; 02-28-2017 at 03:49 PM. Reason: added bits to be complete
 
2 members found this post helpful.
Old 02-28-2017, 03:54 PM   #4
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Original Poster
Rep: Reputation: 40
Excellent comments. Thanks.
 
Old 02-28-2017, 08:09 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by MrUmunhum View Post
Is there a way to use RSA and not create such a network intense load?
You encrypt only a single symmetric key with RSA, then use the symmetric algorithm to encrypt the rest of your data. No practical system uses just RSA by itself.

https://en.wikipedia.org/wiki/Hybrid_cryptosystem
 
Old 03-01-2017, 08:34 AM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,642
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
Quote:
Originally Posted by ntubski View Post
You encrypt only a single symmetric key with RSA, then use the symmetric algorithm to encrypt the rest of your data. No practical system uses just RSA by itself.

https://en.wikipedia.org/wiki/Hybrid_cryptosystem
... and this is exactly what well-known systems such as PGP® or GPG already do [for you].

The world of crypto is fraught with traps for the earnest and well-meaning "do it yourselfer," including for example how the symmetric key is chosen, and how it is periodically changed (during a telecommunications session). All the more reason to use an industry-standard, peer-reviewed library to perform the total task of encryption and key-management.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
blowfish encryption algorithm mutwkil Linux - Security 2 06-17-2011 01:42 PM
Online rsa encryption cad General 2 05-03-2007 07:40 AM
Password Encryption: DES, MD5, Blowfish. swiadek Linux - Security 7 02-13-2006 04:27 PM
Password Encryption: DES, MD5, Blowfish. swiadek Linux - General 1 02-13-2006 05:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 06:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration