c# - Custom Asymmetric Cryptography Algorithm -


i want use asymmetric cryptography algorithm, need have short key size(not rsa @ least 384). need around 20. possible?

there several ways have short key size.

1. rsa

a rsa public key consists in big number n (the "modulus") , (usually small) number e (the public exponent). e can small 3, , in closed setup (where control key generation) can force use of conventional e, same everybody. typical size n 1024 bits (i.e. 128 bytes).

n product of 2 prime numbers (n = p*q). knowledge of p , q sufficient rebuild private key (nominally value d multiplicative inverse of e modulo p-1 , q-1). assuming n known, knowledge of p alone sufficient (if know n , p, can compute q simple division). proper security, p , q should have similar sizes, taking smaller of two, still need store 512 bits or -- that's 64 bytes).

it has been suggested select small d (the "private exponent"). makes e random, hence large; can no longer use conventional small value e. doubles public key size. also, forcing small d can make key weak (it has been shown case when size of d no more 29% of size of n, not prove in way d of 30% size of n safe). considered bad idea.

2. dsa / diffie-hellman

dsa digital signature algorithm. diffie-hellman key exchange algorithm. both "asymmetric cryptographic algorithms" , use 1 or other, or both, depending on needs. in both cases, there public mathematical group (numbers modulo big prime number p basic dsa , dh; elliptic curve variants use elliptic curve group); public key group element, , private key discrete logarithm of element relatively conventional generator. in other words, prime p , number g modulo p given (they can shared key holders, even); private key number x corresponding public key y = gx mod p. private key chosen modulo small prime q. q known , must large enough defeat generic discrete logarithm algorithms; in practice, want 160-bit or more q.

this means private key fits in 20 bytes. that's not 20 decimal digits, closer.

3. cryptographic algorithm

when generate key pair, with:

  1. a deterministic procedure;
  2. a source of random bits.

for instance, rsa, generate p , q creating random odd numbers of right size , looping until prime number found. given random source, whole process deterministic: given same random bits, find same primes p , q.

hence can develop prng seeded secret key k , use random source key generation process. whenever need private key, run key generation process again, using k input. , voilà! private key, 1 need store, k.

with rsa, makes private key usage quite expensive (rsa key generation not easy). however, dsa / diffie-hellman, inexpensive: private key random number modulo q (the group order) can generated less cost using private key digital signature or asymmetric key exchange.

this leads following procedure:

  • the "private key", stored, k.
  • the group parameters dsa / diffie-hellman hardcoded in application; uses same group , not problem. group order q, known prime of @ least 160 bits. if use elliptic curve variant, q property of curve, hence given.
  • when need sign or perform key exchange (key exchange used emulate asymmetric encryption), compute sha-512(k), yields 512-bit sequence. take first half (256 bits), interpret number (with big-endian or little-endian convention, wish, provided use same convention), , reduce modulo q private dsa key. similarly, use second half of sha-512 output private dh key.

the key generation biased not imply security trouble. note if need dsa key and dh key, can use same group should not use same private key (hence use of both halves of sha-512 output).

how big should k ? hash function such sha-512, k can arbitrary sequence of bits. however, k should wide enough defeat exhaustive search. 1024-bit rsa key, or 1024-bit dsa modulus (the p modulus dsa), provide security level equivalent 80-bit symmetric key. similarly, 160-bit group order dsa/dh provides same level. 80 bits not much; cannot go lower if want taken seriously. means k should chosen among space of @ least 280 possible keys; in other words, if k selected uniformly random bytes, must @ least 10 bytes long. decimal digits, need @ least 24 digits. below intrinsically weak, , that's unavoidable.

standard warning: if of above not obvious or crystal clear you, not think implementing it. implementation of cryptographic algorithm tricky, since deadliest errors cannot tested (it not because program runs , appears work not contain security weaknesses).


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -