## Setting up curves with different numbits for ElGamal

This book and the software is very useful for doing experiments of encrypting using elliptic curve cryptography. I’ve been reading some thread with questions on how to change curve parameters, and here’s how:

To change the number of bits, you have to set it in field2n.h

Choose the polynomial irreducible in polymain.c

Set the message to be encrypted in elgamal.c (important note: the length of the message depends on the numbits of the curve)

## Encryption – Decryption finally works

With the help of this debugger and that debugger, changing the data from this:

into this:

make the code works. It’s because the data occupied more space than the capacity of the number of words.

``` lss-67-39:Rosing Experiments CG chika\$ ./test_elgamal_CG poly_prime = 8 0 0 0 0 c9 setting up curve```

``` the curve after setting up: form: 1 a2: 0 0 0 0 0 2 a6: 0 0 0 0 0 1 counter = 0 inc = 5 Base point x: 5 63323eab 10fc68f8 254d4d11 d2d518f2 9979dd24 y: 4 883e6269 de8bf93e f6c224e3 330dbf7f 2dd25ec1 create side 2's private key Side 2 secret: 5 5d0be8bb a913fcdb 91edee60 4da6d486 295d85ac Generate side 2's public key Side 2 public key x: 0 60838c40 7580aec4 b658d152 729f7f67 51d694bd y: 0 1be3f90c c4a81de1 848ff01b d63e97a4 6b46c459 data = 0 68616c6c 6f0a0000 0 0 60000000 Hide data on curve and send from side 1 to side 2 curve before send_elgamal: form: 1 a2: 0 0 0 0 0 2 a6: 0 0 0 0 0 1 Their_public before send_elgamal: x: 0 60838c40 7580aec4 b658d152 729f7f67 51d694bd y: 0 1be3f90c c4a81de1 848ff01b d63e97a4 6b46c459 =====IN send_elgamal===== data (in send_gamal function) : 0 68616c6c 6f0a0000 0 0 60000000 Base point x: 5 63323eab 10fc68f8 254d4d11 d2d518f2 9979dd24 y: 4 883e6269 de8bf93e f6c224e3 330dbf7f 2dd25ec1 Base curve form: 1 a2: 0 0 0 0 0 2 a6: 0 0 0 0 0 1 random value: 5 3a0f94f6 e0caf9a7 2d189f04 8591c5e5 3935d4dc Random point C1 x: 2 d6670f0 ab08aca3 8818adbe cf36881d 83accc06 y: 2 cad560f5 72c889b5 226934a2 733455c8 c53a15a6 counter = 0 inc = 0 raw point M (after poly_embed) x: 0 68616c6c 6f0a0000 0 0 60000000 y: 0 7a64a103 a296a42d 4130d375 23ef2cf2 3f1a3ec0 Their_public: x: 0 60838c40 7580aec4 b658d152 729f7f67 51d694bd y: 0 1be3f90c c4a81de1 848ff01b d63e97a4 6b46c459 hidden point (after poly_elptic_mul) x: 7 1f5fceb7 8269106c c1708600 cde8821b 38e0c7ee y: 2 d752fec4 40840001 be4a3e7f 347e7013 7f36ce97 Hidden data (C2): x: 6 a8a348b9 60a911b7 852a3bb9 8ba949df 5a157ae y: 0 239b098 7584aea3 af4431db 2f3fa3f4 312c5ea9 Random point (C1): x: 2 d6670f0 ab08aca3 8818adbe cf36881d 83accc06 y: 2 cad560f5 72c889b5 226934a2 733455c8 c53a15a6 =====OUT send_elgamal AFTER send_elgamal curve after send_elgamal: form: 1 a2: 0 0 0 0 0 2 a6: 0 0 0 0 0 1 Hidden data (C2) x: 6 a8a348b9 60a911b7 852a3bb9 8ba949df 5a157ae y: 0 239b098 7584aea3 af4431db 2f3fa3f4 312c5ea9 Random point (C1) x: 2 d6670f0 ab08aca3 8818adbe cf36881d 83accc06 y: 2 cad560f5 72c889b5 226934a2 733455c8 c53a15a6 Recover transmitted message IN receive_elgamal Base curve in receive_elgamal form: 1 a2: 0 0 0 0 0 2 a6: 0 0 0 0 0 1 Hidden_data (in receive_elgamal) : x: 6 a8a348b9 60a911b7 852a3bb9 8ba949df 5a157ae y: 0 239b098 7584aea3 af4431db 2f3fa3f4 312c5ea9 Random point x: 2 d6670f0 ab08aca3 8818adbe cf36881d 83accc06 y: 2 cad560f5 72c889b5 226934a2 733455c8 c53a15a6 hidden_point (d*C1): x: 7 1f5fceb7 8269106c c1708600 cde8821b 38e0c7ee y: 2 d752fec4 40840001 be4a3e7f 347e7013 7f36ce97 &raw_point: x: 0 68616c6c 6f0a0000 0 0 60000000 y: 0 7a64a103 a296a42d 4130d375 23ef2cf2 3f1a3ec0 raw_point.x 0 68616c6c 6f0a0000 0 0 60000000 &raw_data (point): x: bffff630 bbe72787 d25ef6fb 139332fc 90db35c4 fd129391 y: 0 2 d6670f0 ab08aca3 8818adbe cf36881d raw_data (point): x: 0 68616c6c 6f0a0000 0 0 60000000 y: 0 68616c6c 6f0a0000 0 0 60000000 &raw_data (field): bffff630 bbe72787 d25ef6fb 139332fc 90db35c4 fd129391 raw_data (field): 0 68616c6c 6f0a0000 0 0 60000000 =====OUT receive elgamal ```

```sent data 0 68616c6c 6f0a0000 0 0 60000000 received data (field) 0 68616c6c 6f0a0000 0 0 60000000 ```

## Houston, we cannot recover the plaintext

``` poly_prime = 8 0 0 0 0 c9 data test = 68616c6c 6f0a0000 0 0 0 6000000 setting up curves```

``` the curve after setting up: form: 1 a2: 2 0 0 0 0 0 a6: 1 0 0 0 0 0 counter = 0 inc = 5 Base point x: 5 63323eab 10fc68f8 254d4d11 d2d518f2 9979dd24 y: 7 95f678a8 39481c22 2f4c7995 4a571060 6fe263b2 create side 2's private key Side 2 secret: 5 5d0be8bb a913fcdb 91edee60 4da6d486 295d85ac Generate side 2's public key Side 2 public key x: d107f500 66784cc8 9a0621db 9050de48 31c6e7c5 7d65d83b y: 2 1763b098 91e23a1e 2f96df5c 50c63a33 a4b16c75 Hide data on curve and send from side 1 to side 2 counter = 0 inc = 0 counter = 0 -- pnt->x = x: bffff4d8 1 bffff508 90483f7b a0073a58 905e07e8 y: 100131 1000 0 bffff7a0 bffff71c 1ed5 counter = 1 -- pnt->x = x: bffff4d8 1 bffff508 90483f7b a0073a58 905e07e8 y: 100132 1000 0 bffff7a0 bffff71c 1ed5 Hidden data x: 100135 70f0eb24 c996c3e4 2d120279 e9f3ec30 3370129a y: 100132 7a61b198 ccba8673 27995624 c069db6f ab7bdfaa Random point x: d107f503 81d255cd 358038a7 148e84da a7b39f16 75d320c4 y: 3 e0053e42 6538a7a0 41dabd3 4cb90701 9a31b3b0 Recover transmitted message ```

```sent data 100130 1000 0 bffff7a0 bffff71c 1ed5 received data d117f431 a8e83258 f59857d7 646d8b77 90191393 f6674925 ```

• #### Budi Rahardjo 9:15 pm on April 9, 2010 Permalink | Reply

lagi mikir debuggingnya …

• #### CG 4:32 am on April 10, 2010 Permalink | Reply

iya ini lagi di debug, pusing

## El-Gamal with Pari

Encrypt – decrypt successful.

• #### Budi Rahardjo 10:16 pm on October 21, 2009 Permalink | Reply

Congratulation! Good stuff 🙂

• #### CG 11:11 am on May 19, 2010 Permalink | Reply

thank you 🙂

• #### romi 3:45 am on May 17, 2011 Permalink | Reply

what its mean: gen P(l): to automatically generate the parameter p, where |logp|2  l bits, and set the appropriate generator g.
jpj2  can be interpreted as:
| jp|2 = l, or
| jp|2 = l – 1, or
|jp|2 = l + 1:

help me pliss

• #### romi 3:46 am on May 17, 2011 Permalink

this thing is in elgamal
i am not understand what the task want

• #### oman 7:47 pm on May 18, 2010 Permalink | Reply

can i know how u did this? any coding involved? thanks 😉

## Implementing ElGamal Elliptic Curve Cryptography

Steps of implementing ElGamal ECC:

1. Generating elliptic curve and choosing random base point ( $B$ )
2. Generating private and public key for the receiver ( A computes $P_A=k_AB$ and send it to B. B computes $P_B=k_BB$ )
3. Generating message and a random point ( message point = $P_m$, A then choose a random bit pattern $r$ )
4. Embed the message onto the curve and send the result with the random point ( A computes two points: $P_r=rB$ and $P_h=P_m+rP_B$ then send the two points to B)
5. Decrypt the ciphertext and make sure the data sent and received are the same ( B computes $P_s=k_BP_r$ and substracts this from $P_h$ to get $P_m=P_h-P_s$)

• #### Bobby Prabowo 12:42 pm on May 12, 2010 Permalink | Reply

kok eneg yah liatnya. wkwkwkw

• #### CG 2:00 pm on May 12, 2010 Permalink | Reply

keknya lebih eneg yang ngetik 😀

• #### CG 6:35 pm on October 4, 2011 Permalink | Reply

tft: eh kalem, yang udah advanced mah ga diposting disini, nanti disertasi gue dicuri orang 😛

## Developing Simple Protocols

After reading this book and getting more headaches while moving back and forth from chapter 5 to chapter 9, I decided to develop a code for two major protocols: Diffie-Hellman and ElGamal.

The earlier target was to observe the process of embedding a message into a point in elliptic curve, encrypt it, then decrypt it. The book provides the source code but I’m going to develop my own version to make it simpler and understandable, at least in my point of view 😉

Now I’m still configuring the data structure and trying to make the modules as simple as possible, using polynomial basis. I set the deadline to be at least next week!

• #### Rindu 11:01 am on June 27, 2008 Permalink | Reply

keep trying chika 🙂

c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r