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 3317668
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:36:51+00:00 2026-05-17T22:36:51+00:00

I was wondering if it is possible that a big number modulo a small

  • 0

I was wondering if it is possible that a big number modulo a small integer in Openssl?

Say I generate two big prime numbers:

BN_generate_prime(p,512,0,0,0,0,0);
BN_generate_prime(q,512,0,0,0,0,0);

and calculate the product N:

BN_mul(N,p,q,ctx);

I would like to test if N is a “Blum integer” (N mod 4==3), however I can’t figure out how to do this since function BN_mod only support big numbers.

  • 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-05-17T22:36:52+00:00Added an answer on May 17, 2026 at 10:36 pm

    Yes it’s possible.

    The best and efficient way is given in jww’s answer, which is to call BN_mod_word().

    A less efficient way is to do it by converting a small integer a BIGNUM first. It’s cumbersome, but not difficult. I’ll show you two ways to create the BIGNUMs by computing 11 mod 3 with BN_mod. First, declare a BIGNUM for your numbers.

    BIGNUM *N = BN_new();
    BIGNUM *M = BN_new();
    

    Method 1: Convert your number to a string, and then the string to a BIGNUM.

    #include <sstream>
    int n = 11;
    std::ostringstream num_str;
    num_str << n;
    BN_dec2bn( &N, num_str.str().c_str() );
    

    (In C you can do char buf[12]; sprintf(buf, "%d", n); BN_dec2bn(&N, buf);)

    Method 2: Give your number as an array of bytes, but beware that OpenSSL wants your bytes in big endian format, and will always interpret your bytes as a positive number.

    #include <arpa/inet.h>   // For htonl to make the integer big endian
    int m = 3;
    m = htonl(m);
    BN_bin2bn( (unsigned char *) &m, sizeof(m), M);
    

    And then just use your OpenSSL function as normal.

    BN_mod(rem, N, M, ctx);
    BN_print_fp(stdout, rem);  // (Using N=11 and M=3 above, this line prints 2)
    

    And free your BIGNUMs.

    BN_free(N);
    BN_free(M);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am wondering is that possible (best practice) to run two long running query
I was wondering ( if possible ) if there was a program/tool/utility that when
I was wondering - is it possible to change files that are stored on
I was wondering if it's possible to achieve that in CSS 2/3 (or if
I am wondering if it is possible to see stored procs that are being
I was wondering if it is possible to create a flash movie that rotates
I'm wondering if it's possible to recover a RSA public key that I have
I was wondering if it was possible to read a text file that was
I'm wondering if it is possible to have unique characters that cannot be seen
I was wondering if it is possible to set up an app that will

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.