Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8691667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:09:59+00:00 2026-06-13T00:09:59+00:00

So for a crypto class, we are implementing Mental Poker with the SRA protocol.

  • 0

So for a crypto class, we are implementing Mental Poker with the SRA protocol. We are using the openSSL library for BIGNUM http://www.openssl.org/docs/crypto/bn.html and I am having an issue when adding encrypted cards to an array of BIGNUM structs.

#include <openssl/bn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

BIGNUM* encryptedDeck[52];
BIGNUM* bobHand[5];
BIGNUM* aliceHand[5];

int main(int argc, char* argv[]){
    int lcv = 0;
    BIGNUM *P,*Q,*N,*alpha,*alphaPrime,*beta,*betaPrime,*temp,*Pminus;
    BN_CTX *ctx = BN_CTX_new();
    P = BN_new(); //same for all BIGNUM pointers

    BN_generate_prime(P,512,1,NULL,NULL,NULL,NULL);
    BN_generate_prime(Q,512,1,NULL,NULL,NULL,NULL);
    BN_generate_prime(alpha,128,1,NULL,NULL,NULL,NULL); //Alice's key [ gcd(alpha,P) = 1 ]
    BN_generate_prime(beta,128,1,NULL,NULL,NULL,NULL);  //Bob's key. Same rule as alice's

    BN_one(temp);  //set temp to be a BIGNUM equivalent to integer 1
    BN_sub(Pminus,P,temp);

    BN_mul(N,P,Q,ctx);

    temp = BN_new();
    BIGNUM *encryptedCard = BN_new();
    for(lcv; lcv < 52; lcv++){
        BN_bin2bn(deck[lcv],strlen(deck[lcv]),temp);
        BN_mod_exp(encryptedCard,temp,beta,P,ctx);    //encrypt temp, store in encryptedCard

        printf("ec: %s\n\n",BN_bn2dec(encryptedCard));  //prints *correct numbers

        encryptedDeck[lcv] = encryptedCard;  //store cards in the array of encrypted cards
    }

    printf("00: %s\n\n",BN_bn2dec(encryptedDeck[0]));
    printf("01: %s\n\n",BN_bn2dec(encryptedDeck[1]));
    //...
    printf("40: %s\n\n",BN_bn2dec(encryptedDeck[40]));
}

The print statement in the forloop prints 52 different values (1 for each card.)

I intended for each of those values to simply be added to the array encryptedDeck, but when I check the values after exiting the loop, they are all equivalent to the 52nd card.
So for some reason, each index in the array is being overwritten for every new card? Or something weird like that.

Is there some obvious thing that I am missing when dealing with arrays of structs? The only thing that I would think of right off the bat is something about the array not being initialized with enough space or something.

I think that it is possible to convert the BIGNUM values into char* and store them in an array that way, but I tried to avoid this because I don’t know how big the pointers need to be, or even have a guess of their range. something like

char encryptedDeck[52][something ridiculous];

I omitted some code, but I believe this should still compile (provided you have the openssl library, and link it when compiling) and fill in the BN_new() for all the other BIGNUM pointers that I didn’t initialize.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:10:00+00:00Added an answer on June 13, 2026 at 12:10 am

    Just above your for-loop:

    BIGNUM *encryptedCard = BN_new();
    

    You never change what this points to. You just keep dropping new data into the same card, then save that card into the current slot of the for-loop.

    My surmise is to move the card inside the loop.

    for(lcv; lcv < 52; lcv++){
        BIGNUM *encryptedCard = BN_new();
        BN_bin2bn(deck[lcv],strlen(deck[lcv]),temp);
        BN_mod_exp(encryptedCard,temp,beta,P,ctx);
        printf("ec: %p: %s\n\n",encryptedCard, BN_bn2dec(encryptedCard));
        encryptedDeck[lcv] = encryptedCard;
    }
    

    Noted: I don’t use this crypto library, so I can’t tell you if temp needs the same locality in the loop, but seems like where your problem may be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I am using (encrypt/decrypt) javax.crypto.Cipher class for long string, some characters in output
I am using this code: http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des for encrypting my zip files used in android
Talking about javax.crypto.Cipher I was trying to encrypt data using Cipher.getInstance(RSA/None/NoPadding, BC) but I
I am trying to implement a ElGamal-like crypto algorithm using Java's BigInteger objects. q
Is it as simple as using FIPS 140 compliant crypto providers or is there
How do encrypt/decrypt a long or int using the Bouncy Castle crypto routines for
Hi im trying to get a uniform random number generator using a crypto algorithm
I need to implement some crypto protocol on C# and want to say that
I've created a class for encrypting and decrypting using AES. public class AesEncryptionProvider {
Does anyone know whether it might be possible to use the javax.crypto.Cipher class to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.