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

  • SEARCH
  • Home
  • 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 8480467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:18:09+00:00 2026-06-10T19:18:09+00:00

I am having some issues coming up with the correct answer using OpenSSL’s BIGNUM

  • 0

I am having some issues coming up with “the correct answer” using OpenSSL’s BIGNUM library. I am using OpenSSL 1.0.1c (May 2012, latest package available in the standard Mint repos).

I am using BIGNUMs for a cryptography project that uses finite fields (aka Galois fields). Basically i have a large prime (q) and a safe prime (p, where p = 2q + 1). My field is Fp of order q.

I need to generate a “g”. The easiest way i’ve found to do this is to pick a random “h” (1 < h < p-1), then do g = h^((p-1)/q) mod p. With the “g” i get out of that, i should be able to prove that it is in the FF by doing g^q mod p = 1.

When I do this for any reasonable small numbers on paper it holds true. However, when I do it using OpenSSL and big, prime numbers, it doesn’t work! When I test whether my result of g^q mod p == 1, it constantly fails using BN_is_one(). If I print out the value, it’s always a large unrelated prime.

What is going on? I’m not sure what’s going on here, or if I’m misunderstanding something.

Snippets of my code below:

BN_generate_prime(q, KEYSIZE - 1, 0, 0, 0, 0, 0); //generate "q"

// Calculate "p" = 2q + 1 
BN_lshift1(p, q);
BN_add(p, p, one);  //one = BN_one()

// 1: gExp = (p-1)/q
// 2: h =>   1 < h < (p-1)
// 3: g = h^gExp mod p
BN_div(gExp, NULL, pMinusOne, q, ctx);      // (1)
BN_pseudo_rand_range(h, pMinusOne);         // (2)
BN_mod_exp(g, h, gExp, p, ctx);             // (3)

BN_mod_exp(temp, g, q, p, ctx); // g^q mod p = 1, or it should
  • 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-10T19:18:10+00:00Added an answer on June 10, 2026 at 7:18 pm

    As you are computing it in your snippet, p is not necessarily prime, it’s just a number that is of the form 2*q+1 with q prime. For many small values of q, this p happens to be prime, but that is mostly coincidence and if you checked with BN_is_prime you will likely find the ps you are generating do not pass the tests.

    Instead, generate p directly by setting the safe parameter of BN_generate_prime and then compute q by a right shift, as with safe the prime will be of the form you need, and chopping off the lowest bit gives you a prime q.

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

Sidebar

Related Questions

I am having some issues with setting values using MacRuby and Cocoa. I have
Having some issues getting my head around the differences between UTF-8, UTF-16, ASCII and
Having some issues with the ... in ObjectiveC. I'm basically wrapping a method and
I am having some issues passing commands through to flash from javascript. My code
I am having some issues with multiple form submissions with a jQuery/ajax form. I
I'm having some issues to deserialize a Json array that follows this format: [
I am having some issues with a code that is occasionally and sporadically throwing
I am having some issues with consuming an XML and applying multiple conditions on
Recently I was having some issues with a singelton class that was lazy initializing
I'm having some issues getting file uploads to work correctly and the following code

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.