RSA encryption on linino

hi, I'm working on a project that has a linux server running python communicating with the Yun over udp and I wanted to encrypt the packets using RSA.

I don't have any problems with the linux server using pycrypto libraries but the problem lies with the linino's lacking python-crypto library. Is there any way to install the latest pycrypto on the Yun? I tried installing using pip but it keeps returning this error:

    configure: error: no acceptable C compiler found in $PATH
    See `config.log' for more details
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-_yqGLV/pycrypto/setup.py", line 456, in <module>
        core.setup(**kw)
      File "/usr/lib/python2.7/distutils/core.py", line 152, in setup
        dist.run_commands()
      File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
        self.run_command(cmd)
      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/usr/lib/python2.7/site-packages/setuptools/command/install.py", line 53, in run
        return _install.run(self)
      File "/usr/lib/python2.7/distutils/command/install.py", line 563, in run
        self.run_command('build')
      File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/usr/lib/python2.7/distutils/command/build.py", line 127, in run
        self.run_command(cmd_name)
      File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/tmp/pip-build-_yqGLV/pycrypto/setup.py", line 251, in run
        self.run_command(cmd_name)
      File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/tmp/pip-build-_yqGLV/pycrypto/setup.py", line 278, in run
        raise RuntimeError("autoconf error")
    RuntimeError: autoconf error

    ----------------------------------------
Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-_yqGLV/pycrypto/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-m1vtUd-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-_yqGLV/pycrypto

because the linino doesn't have a C compiler. is there any way to precompile from another machine?

I really need some functions like importKey() from the latest version of pycrypto.

TIA

I don't know if it works at linino, but at least works at Yun OS.

opkg update
opkg install python-crypto
Package python-crypto (2.0.1-1) installed in root is up to date.

Let's know how it is doing.

KUM4:
...
I really need some functions like importKey() from the latest version of pycrypto.
...

Your python code?

pycrypto (2.0.1),the latest version for linino, is also installed in my linino but unfortunately it doesn't have some of the newer functionality of the latest pycrypto (2.6). I've resolved my problem using a workaround.

generate a random key(both private and public) (using pycrypto 2.6 on linux)

from Crypto.Util.randpool import RandomPool
pool = RandomPool()
pool.stir()
rsa = RSA.generate(2048, pool.get_bytes)
rsa.keydata
print rsa.n
print
print rsa.e
print
print rsa.d
print
print rsa.p
print
print rsa.q
print
print rsa.u

key=RSA.construct((rsa.n,rsa.e,rsa.d,rsa.p,rsa.q,rsa.u))
publickey = key.publickey()
print key.exportKey()
print key.publickey().exportKey()

that code will print the exports(this is not available on 2.0.1), simply save it as txt files for use of the server running on linux. but more importantly it will print n,e,d,p,q, and u values of the key (this is important because 2.0.1 on the linino doesn't have an importKey()/exportKey() function.)

using pycrypto 2.0..1 on linino, use the LONG INT values you get from the code you ran on linux:

n=19861093253177138483052877581807883677028172227874510793533064689050923485579355881905630299027704851417961023389870341517121122849413623484800170181497912814006886555341677928365432424447777115550403836821049334931126668504754025602053684165956702098110858354228024777056251052927493374544204865948082540116294635063435118461707586164630700948551114039704609698253330108371922744749377939580650120091002682348226534539986185312115442525988006898080824842580265224724133052432691070728309249249423674341896735761294674674639853933405844744801903851250185521665217170610524480935702638987855722733411817450982283653397L
e=65537L
d=18928906506045397970458913081729438673586777934987408924346075553394414328284360708297718450761699081807486816332067250583653546154038548247312257651502832480517633415218831272161271871819470015630770008570419190825535237216769781850403209891966699265302078576429141639069693410087495058782147186047319583413739497959502932359249953356174679551634487991432871342039879304836430336100482298030280965249978756243313343909668429221953670840828541040062882193235754429034828108207523166780070381992256954138333023246259188248176458430250365413520177940751580131390029387742129434965295375294406357829289815730736306173313L
p=133129799191677290212480643966480462352130365636392012512124016783237556069880280110974257974557313144352665481995770638756730020506187585922833797745797664601999529700169213055220501166342143836899790297706474505486691589573473983420053151443051846765100933872736837901316447859665420430085063668196756055137L
q=149185932629415170820057200854739789836942728605671630710585864549970871953583755337328899698490841611968093937388121307591630231816970940492453984939626971344247646304087382060058655311167151878911366550505021542158068506985086886550005200967276691007633631841037082215306076966241094428682309192637030172981L
u=149002984640457939136610566187124441496972936007903042889080875172500801604783052287838965408738682550698342192078791625225537374749141232336484227463617442390196575278691087012849946313000967757923392310012117967278468292771036659348628525844674573161174974230695321614594760396413118809538824166625126834284L

key=RSA.construct((n,e,d,p,q,u))
publickey = key.publickey()

def encrypt_RSA(message):
    encrypted = publickey.encrypt(message,64)
    return encrypted[0]

def decrypt_RSA(package):
    decrypted = key.decrypt(package) 
    return decrypted

test = encrypt_RSA("Hello World!")
print test
print decrypt_RSA(test)

this way both the linino and linux systems have a copy of the private and public keys. I realize this example code isn't the best example of RSA encryption but it's purpose is to demonstrate a workaround for import/export of keys

Very impress workaround.

I cross compiled python-crypto 2.6

opkg update
opkg remove python-crypto
wget http://www.ibuyopenwrt.com/images/software/python-crypto_2.6-1_ar71xx.ipk
opkg install python-crypto_2.6-1_ar71xx.ipk
Installing python-crypto (2.6-1) to root...
Configuring python-crypto.
nano rsa.py
from Crypto.PublicKey import RSA
from Crypto.Util.randpool import RandomPool
def encrypt_RSA(message,public_key):
    encrypted = public_key.encrypt(message,64)
    return encrypted[0]
def decrypt_RSA(package,private_key):
    decrypted = private_key.decrypt(package)
    return decrypted
pool = RandomPool()
pool.stir()
rsa_key = RSA.generate(1024,pool.get_bytes)
print rsa_key.publickey().exportKey("PEM")
print rsa_key.exportKey("PEM")
test = encrypt_RSA("Hello World!",rsa_key.publickey())
print test
print decrypt_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llHcmsQ5sD/lcoaVMFCNBrcN9EC
2ZXR8QCT1geuELuOzREuGW/SmBzuj0IHBpSuHmNQ2l6KXQ==
-----END RSA PRIVATE KEY-----
▒▒▒w▒Т▒~l▒;.▒▒▒▒Q▒▒\xѳy`;N▒▒%▒▒E▒f֙▒▒|▒▒1
▒▒٣@▒▒▒ l▒΢hk1nW▒▒~▒▒d▒
Hello World!

pycrypto (2.0.1), the latest version for linino and Yun was released way back in 2005.

Computer years <>15 human years

It is 150 years old.

It is antique and collectible antique.