LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 06-16-2011, 06:44 AM   #1
mutwkil
Member
 
Registered: Feb 2010
Posts: 30

Rep: Reputation: 0
blowfish encryption algorithm


hi folk
can somebody give me CBC 64-bit block openssl blow fish encryption algorithm as a C source code..

or modify this one to work as mentioned above

Code:
#include <stdio.h>
#include <stdlib.h> 
#include <strings.h>
#include <string.h>
#include <openssl/blowfish.h>
#include <openssl/evp.h> 
 
int main(void) { 
 
    char plaintext[1024] = "Hello World? - this is a test of Blowfish! of which I'm curious to see if it really is working.\n";
    char ciphertext[1024]= {0,};
    char mykey[EVP_MAX_KEY_LENGTH] = "blowfish_key";
    char iv[EVP_MAX_IV_LENGTH] = "blowfish";
    int tmp_len = 0, in_len, out_len=0;
    EVP_CIPHER_CTX ctx;
 
    //memset(mykey,0,sizeof(mykey));
    //memset(iv,0,sizeof(iv));
 
    in_len = strlen(plaintext);
 
    printf("No encrypt: %s\n", plaintext);   
 
    //Encrypt           //EVP_bf_cfb
    EVP_EncryptInit(&ctx, EVP_bf_cbc(), (unsigned char *)mykey, (unsigned char *)iv);
    EVP_EncryptUpdate(&ctx, (unsigned char *)ciphertext, &out_len, (unsigned char *)plaintext, in_len);    //Block through the mem to be encrypted
    tmp_len += out_len;
    EVP_EncryptFinal(&ctx, (unsigned char *) &ciphertext[out_len], &out_len); //Finish any remaining encryption and throw a pad on
    tmp_len += out_len;
    printf("Encrypted: %s\n", ciphertext);

	printf("\n\n%d",strlen(ciphertext));
 
    //Reset memory for Decryption
    memset(plaintext,0,sizeof(plaintext));
    in_len = tmp_len;
    out_len = tmp_len = 0;
 
    //decrypt		//EVP_bf_cfb
    EVP_DecryptInit(&ctx, EVP_bf_cbc(), (unsigned char *)mykey, (unsigned char *)iv);
    EVP_DecryptUpdate(&ctx, (unsigned char *)plaintext, &out_len, (unsigned char *)ciphertext, in_len);
    tmp_len += out_len;
    EVP_DecryptFinal(&ctx, (unsigned char *)&plaintext[out_len], &out_len);
    tmp_len += out_len;
 
    //Zero out the pad
    memset(&plaintext[tmp_len],0,(int)(sizeof(plaintext)) - tmp_len);
 
    printf("Decrypted: %s\n", plaintext);

	printf("\n\n%d",strlen(plaintext));
 
    printf("Block Size: %d\n",EVP_CIPHER_CTX_block_size(&ctx));
 
    return 0;
}
 
Old 06-17-2011, 10:25 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by mutwkil View Post
hi folk
can somebody give me CBC 64-bit block openssl blow fish encryption algorithm as a C source code..

or modify this one to work as mentioned above
Sorry, we're not going to do your work for you, and modify your source code.

And did you bother to try to look this up?? First hits on Google:
http://www.schneier.com/blowfish-download.html
http://stackoverflow.com/questions/9...age-characters
http://www.gamedev.net/blog/198/entr...blowfish-in-c/
 
Old 06-17-2011, 01:42 PM   #3
NyteOwl
Member
 
Registered: Aug 2008
Location: Nova Scotia, Canada
Distribution: Slackware, OpenBSD, others periodically
Posts: 512

Rep: Reputation: 139Reputation: 139
Indeed Bruce Schneier has made the source code available in multiple languages for quite some time. See the link TB0ne posted above.
 
1 members found this post helpful.
  


Reply



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
help with Asymmetric Encryption algorithm mutwkil Linux - Security 1 04-12-2011 01:24 PM
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
encryption algorithm in fedora shivaligupta Programming 10 04-25-2005 01:09 AM

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

All times are GMT -5. The time now is 10:05 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