Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® Software > Cryptography with PSoC Creator 2.2

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



Cryptography with PSoC Creator 2.2
Moderator:
JFMD

Post Reply
Follow this topic



Cryptography with PSoC Creator 2.2

Antonio S. posted on 30 Apr 2013 6:18 AM PST
Member
4 Forum Posts

 Hello,

I'm new in this forum, and this is my first message. Several times I've searched in this forum some advice for my problems, and often I've found it. But now, I've not found no solutions, so I'm here to ask directly to you.

I need to implement a decryption of a RSA 1024 crypted message, I've got PSoC Creator  2.2 Component Pack 5 (2.2.0.293) and a CY8CKIT-001 PSoC Development Board with a PSoC 5 board mounted.

I tried to use some libraries such as PolarSSL or OpenSSL but I had some problems with the dependencies, so I want to ask you if somebody know about any thin library that implements a RSA 1024 decryption for Cortex M3 architecture like PSoC 5 (or in general for embedded systems), and if someone had ever used it.

Thanks a lot for your time.

Regards

Antonio




Re: Cryptography with PSoC Creator 2.2

hli posted on 30 Apr 2013 07:32 AM PST
Top Contributor
675 Forum Posts

A google search for "rsa library cortex m3" yields e.g. https://code.google.com/p/lpc1343codebase/source/browse/trunk/drivers/rsa/rsa.c?r=131 . Otherwise, there is also cyassl: (http://www.yassl.com/yaSSL/Products-cyassl.html ) or MatrixSSL (http://www.matrixssl.org/ ) which both claim availability on ARM.



Re: Cryptography with PSoC Creator 2.2

Antonio S. posted on 30 Apr 2013 08:00 AM PST
Member
4 Forum Posts

 Hi, thanks a lot for the reply.

I've already searched on Google, I've found your links, unfortunately I need a 1024 bits implementation, I've tried the cyassl-2.6.0 library but for the several dependences I gave up, for search something thinner, now I try to use matrixssl-3-4-2-open library, I hope to find out a solution. I hope that someone have already used some library like this in PSoC Creator. Anyway, if the Matrix library works I'll tell you here.

Antonio



Re: Cryptography with PSoC Creator 2.2

hli posted on 30 Apr 2013 12:10 PM PST
Top Contributor
675 Forum Posts

I wish you good luck! And I'm looking forward to hear about your success (and even if it doesn't work out)



Re: Cryptography with PSoC Creator 2.2

hli posted on 02 May 2013 03:19 PM PST
Top Contributor
675 Forum Posts

Btw: Wikipedia says for PolarSSL "It is also highly modular: each component, such as a cryptographic function, can be used independently from the rest of the framework".

So it should be possible to just use the RSA implementation, and remove the rest of the library. This should remove most (if not all) of the dependencies. You might want look at its predecessor (xyssl) too, maybe its easier there...



Re: Cryptography with PSoC Creator 2.2

hli posted on 03 May 2013 12:55 AM PST
Top Contributor
675 Forum Posts

Actually, I just tested that. I copied rsa.c, rsa.h, config.h, bignum.h from the PolarSSL distribution, and removed the POLARSSL_PKCS1_V21 and POLARSSL_SELF_TEST defines from config.h. After that, the code compiled just fine.

Note that I did not test whether encryption / decryption works...



Re: Cryptography with PSoC Creator 2.2

Antonio S. posted on 03 May 2013 06:20 AM PST
Member
4 Forum Posts

 Hello,

thanks a lot for your advice, I've tried several libraries, now I'm trying again PolarSSL, the point is that I need not to generate a RSA Key because I already have one, so I need to set my private RSA Key to the library, I've the PEM and the DER format. For 1024 bit(and more) RSA I think I need to bignum.c and bn_mul.h in addiction with the files you told me. Anyway, I'm going to find a way to set my private RSA Key (different by RSA certificate) and if I'll be able to do this I'll try to decrypt..if you have more information I'll be grateful to you.

 

Antonio



Re: Cryptography with PSoC Creator 2.2

Antonio S. posted on 06 May 2013 02:13 AM PST
Member
4 Forum Posts

Good news, I resolved all the problems, now I'm going to do a summary of all:

I used the PolarSSL library, but not all of it, indeed I only copied these files:

bignum.h

bn_mul.h

config.h

rsa.h

bignum.c

rsa.c

and removed the POLARSSL_PKCS1_V21 and POLARSSL_SELF_TEST defines from config.h

With some compilers and version of PolarSSL there will be some errors, in this case it needs to edit bignum.c as descript in this page: http://e2e.ti.com/support/development_tools/compiler/f/343/t/197852.aspx

add this lines:

 

#define MULADDC_INIT \
{ \
t_uint s0, s1, b0, b1; \
t_uint r0, r1, rx, ry; \
b0 = ( b << biH ) >> biH; \
b1 = ( b >> biH );

#define MULADDC_CORE \
s0 = ( *s << biH ) >> biH; \
s1 = ( *s >> biH ); s++; \
rx = s0 * b1; r0 = s0 * b0; \
ry = s1 * b0; r1 = s1 * b1; \
r1 += ( rx >> biH ); \
r1 += ( ry >> biH ); \
rx <<= biH; ry <<= biH; \
r0 += rx; r1 += (r0 < rx); \
r0 += ry; r1 += (r0 < ry); \
r0 += c; r1 += (r0 < c); \
r0 += *d; r1 += (r0 < *d); \
c = r1; *(d++) = r0;

#define MULADDC_STOP \
}

and replace these lines:

 

do {

        *d += c; c = ( *d < c ); d++;
    }
    while( c != 0 );
 
with these lines:

 

 

do {

      t_uint temp = *d;
     if (c != 0)
             *d = temp + c;
     c = ( *d < c );
     d++;
}
while( c != 0 );

Ok, now it works, if you want to set your private key and you have the XML fornat you can use this functions:

 

rsa.len = MAXDIGITS;

mpi_read_string( &rsa.N , 16, RSA_N  );

mpi_read_string( &rsa.E , 16, RSA_E  );

mpi_read_string( &rsa.D , 16, RSA_D  );

mpi_read_string( &rsa.P , 16, RSA_P  );

mpi_read_string( &rsa.Q , 16, RSA_Q  );

mpi_read_string( &rsa.DP, 16, RSA_DP );

mpi_read_string( &rsa.DQ, 16, RSA_DQ );

mpi_read_string( &rsa.QP, 16, RSA_QP );

Finally I want to thank hli for his contribute to solve the problem. Thank you very much, I hope these posts will help someone else have to implements RSA1024

Antonio

 

 

 

 



Re: Cryptography with PSoC Creator 2.2

hli posted on 06 May 2013 03:00 AM PST
Top Contributor
675 Forum Posts

Thanks for your feedback! I'm happy that you got your problem solved.






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20