Whether it would be fair to expect, that the Debian libc6-dev package work, on an ARM-64 CPU-based device.

One of the facts which I had posted about before was, that I had installed Debian 10 / Buster on a Google Pixel C Tablet, not because that tablet has any special properties, but just to document that with that one specific configuration, the solution ‘works’. And I had gotten to the subject of wanting to install ‘libc6-dev’, which would normally install Development Libraries, on top of Run-Time Libraries, with the ultimate intention of being able to compile or custom-compile C or C++, from in front of this ARM-64 -CPU Device, for use on the same device. And even one major Debian Update later, from 10.0 to 10.1, this facility still doesn’t work.

What I’d like to comment is the idea, that this is not a fair expectation, and that the naming of these packages cannot always be expected to remain canonical. What this expectation would assume is that the general-purpose GNU Compiler will work, even though that compiler is highly optimized for targeting code that runs, either on ‘amd64′ or ‘i386′ architecture, in that order.

If the goal really was, to compile code from in front of an ARM-64 -based machine, to run on it, then a compiler would need to be selected which is meant to target the ARM-64 CPU, and this might involve installing the correct cross-compiler, even though it’s to be executed on an ARM-64. The fact that an ARM-64 version of ‘libc6-dev’ is available, really just stems from the rather nonsensical idea, that the compiler using it should run on an ARM-64, but that the linked code should not.

And then, if one has installed the correct cross-compilers, because those packages are available in ‘arm64′ versions, they will run in spite of being named cross-compilers, and then installing them will also pull in the correct development libraries. Only then, in order actually to compile anything, one would need to specify yay-long commands from the command-line. And the main reason I’ll have none of this, is the simple fact that entering many non-standard ASCII characters using an Android-oriented keyboard, does not appeal to me for the moment.

This is similar to why I don’t install ‘Web-development software’, that is compiled and available from the repositories, but that would require a long sequence of special characters to be typed in, in order to allow any sort of Web-development. And it remains consistent with having LibreOffice installed, where what gets typed, is consistent with the English language, just as what the Google Pixel C’s OEM Keyboard offers, is…

There’s an added level of weirdness that would result, if somebody was just to write and compile C or C++ to run on an ARM-64 CPU in that way: The resulting binary wouldn’t be Android-compatible. It would assume that the O/S is Linux, but with an ARM-64 CPU, just like the Guest System. Writing Android-compatible code would require, that the ‘Android Development Kit’ be installed. Due to cross-compiling by the Debian package maintainers, there just might be ‘arm64′ packages of that available, but again, with no further guarantee that it all works…


 

(Update 9/08/2019, 10h20 : )

Unfortunately, this recognition does not negate the fact, that the way certain packages have been compiled to run on an ARM-64 CPU, still contain a bug…

Continue reading Whether it would be fair to expect, that the Debian libc6-dev package work, on an ARM-64 CPU-based device.

Generating a Germain Prime efficiently, using Python and an 8-core CPU.

I have spent extensive time, as well as previous blog postings, exploring the subject of how to generate a Germain prime (number), in the Python (3.5) programming language, but taking advantage of parallel computing to some slight degree.

Before I go any further with this subject, I’d like to point out that generally, for production-ready applications, Python is not the best language to use. The main reason is the fact that Python is an interpreted language, even though many modern interpreted languages are compiled into bytecode before being interpreted. This makes a Python script slower by nature, than very well-written C or even C++. But what I aim to do is to use Lego-Blocks to explore this exercise, yet, to use tools which would be used professionally.

The main way I am generating prime numbers is, to start with a pseudo-random, 512-bit number (just as a default, the user can specify different bit-lengths), and then to attempt to divide this number by a list of known, definite primes, that by now only extend to 4096 (exclusively, of course), in an attempt to disprove that number prime. In about 1/8 of all cases, the number survives this test, after which I undertake a more robust, Miller-Rabin approach to try disproving it prime 192 times, probabilistically. If the number has survived these tests, my program assumes it to be prime.

Even though I’ve never been told this, the probability of a non-prime Candidate surviving even a single Miller-Rabin Test, or Witness, is very small, smaller than 1/8. This could be due to the fact that the Witness in question is raised to a high, odd exponent, in its 512-bit modulus etc., after which it would be squared some number of times. Because the first Candidate in the modulus of 4 is 3, that one actually gets squared a subsequent total of zero times. And after each exponentiation, the result could be any number in the modulus, with the possible exception of zero. It needs to become either (1) or (n-1) in the modulus of (n), for the Candidate to survive the test. (:1)

Further, there is no need for the numbers that get used as witnesses, which are pseudo-random, to be of the same, high, cryptographic quality of pseudo-random, as the candidate is, which is being tested.

But there is a sub-category of prime numbers which have recently been of greater interest to me, which is known as the Germain prime numbers, such that the Totient of that main candidate, divided by two, should also be prime. And so, if the density of prime numbers roughly equal to (n) is (1 / log(n)), and if we can assume a uniform distribution of random numbers, then the probability of finding a Germain prime is roughly (1 / (log (n))2), assuming that our code was inefficient enough actually to test all numbers. The efficiency can be boosted by making sure that the random number modulo 4 equals 3.

But one early difficulty I had with this project was, that if I needed to start with a new pseudo-random number for each candidate, on my Linux computers, I’d actually break ‘/dev/urandom’ ! Therefore, the slightly better approach which I needed to take next was, to make my initial random number the pseudo-random one, and then just to keep incrementing it by 4, until the code plodded into a Germain prime.

Even when all this is incorporated into the solution I find that with Python, I need the added advantage of parallel computing. Thus, I next learned about the GIL – The Global Interpreter Lock – and the resulting pitfalls of multi-threaded Python, which is not concurrent. Multi-threading under Python tells the O/S to allocate CPU cores as usual, but then only allows 1 core to be running at any one time! But, even under those constraints, I found that I was benefiting from the fact that my early code was able to test at least 2 candidates for primality simultaneously, those being the actual candidate, as well as its Totient divided by 2. And as soon as either candidate was disproved prime, testing on the other could be stopped quickly. This reduced the necessary number of computations dramatically, to make up for the slowness of multi-threaded Python, and I felt that I was on the right track.

The only hurdle which remained was, how to convert my code into multi-processing code, no longer merely multi-threaded, while keeping the ability for two processes, then, to send each other a shutdown-command, as soon as the present process disproved its number to be prime.

(Updated 6/01/2019, 17h35 … )

Continue reading Generating a Germain Prime efficiently, using Python and an 8-core CPU.

My personal answer, to whether Hyper-Threading works under Linux.

I have been exploring this subject, through a series of experiments written in Python, and through what I learned when I was studying the subject of System Hardware, at Concordia University.

When a person uses a Windows computer, this O/S provides all the details of scheduling processes and threads. And arguably, it does well. But when a person is using Linux, the kernel makes all the required information available, but does not take care of optimizing how threads are scheduled, specifically. It becomes the responsibility of the application, or any other user-space program, to optimize how it will take up threads, using CPU affinity, or using low-level C functions that instruct the CPU to replace a single line in the L1 cache

In the special case when a person is writing scripts in Python, because this is an interpreted language, the program which is actually running, is the Python interpreter. How well the scheduling of threads works in that case, depends on how well this Python interpreter has been coded to do so. In addition, how well certain Python modules have been coded, has a strong effect on how efficiently they schedule threads. It just so happens that I’ve been lucky, in that the Python versions I get from the Debian repositories, happen to be programmed very well. By other people.

Dirk

 

Refining my Python, for generating strong prime numbers…

According to an earlier posting, I had applied the (probabilistic) Miller-Rabin test, after testing whether large prime number candidates are divisible by any in a list of smaller, definite prime numbers, to generate pseudo-random numbers first, and then to continue until one was found to be prime.

That earlier effort had numerous issues, including the fact that it did not generate the kind of strong prime numbers needed for Diffie-Hellman key exchange. I have broadened my horizons slightly, and written more-up-to-date Python 3, which will generate such strong primes, as well as computing the resulting, Primitive Root, which would be used as the generator (g), if the results were ever actually used in cryptography.

I’d like to thank my friend, François Dionne, for giving me help with this project.

The resulting Python script can be downloaded from this URL:

http://dirkmittler.homeip.net/text/Generate_Prime_DMFD_ITC.py

(Updated 5/23/2019, 18h40 : )

Continue reading Refining my Python, for generating strong prime numbers…