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 if it is possible to see stored procs that are being
I was sitting here wondering if it's possible to write a greasemonkey script that
I was wondering if it is possible to generate a core file, copy if
I am wondering if such thing is possible: I have a java program that
I'm wondering if its possible to do this. The issue being that im trying
I was wondering if it's possible to have a function in a class, that
I'm wondering if its possible to add new class data members at run-time in
I was wondering if its possible to inject a thread into a remote app
I am wondering if it is possible to extract the index position in a
I was wondering if it is possible to not attach Excel sheet if it

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.