April 26, 2019

Go See my New Blog

I have a new blog, you can go see it over at peterl.xyz.

There may be some duplication of content as I post some of my favorite old stuff there.

-

April 8, 2019

Cygwin clipboard

If you happen to find yourself on Cygwin and want to use the clipboard, you will find it at /dev/clipboard.

This can be used like any other file with pipes and such. For example, if you copy something, you can then print it out at the Cygwin command line by using cat /dev/clipboard. Or you can send things to the clipboard, for example cat myfile > /dev/clipboard.

(This is mostly a note to myself in case I forget this information later)

-

March 8, 2019

VirtualBox Bridge to Cuntoo

In the course of events, after comments like this and this (and yes, getting off Blogspot is still on my todo list), I have been doing some thinking and I have determined that as my first step I need a real computer - that is, a computer running a Linux operating system. I have been limping by with a Mac and CyGWin (the sort-of Posixy appendage grafted onto a Winblows machine), but it is time to grow up and get a real machine stood up. To this end, I decided that I would install a Gentoo system in a virtualbox and use this as a beachhead to create a Cuntoo system, which I could then install on an older computer I have decided to resurect for this purpose. In this article I will try to share what I have learned during this process.

I am starting with a Windows 10 box (conveniently provided by my employer), which I use for unrelated things, so I wanted this to be as unobtrusive as possible on this machine. The first thing I did was download VirtualBox from https://www.virtualbox.org/wiki/Downloads and ran the install script. I ended up with VirtualBox Version 6.0.4 r128413 (Qt5.6.2).

I followed this instruction set to get Gentoo on Virtualbox hosted on Windows, with a couple modifications:
  • In Part 3, when I downloaded the tarball, it was in /home/gentoo not /home/gentoo/Downloads
  • then "cd /mnt/gentoo" before the next step, "tar -xpf stage3-..."
  • there is a typo, "$nano /gentoo/mnt/etc/portage/make.conf" should be "$nano /mnt/gentoo/etc/portage/make.conf"
  • In Part 4, I had to run "etc-update" before "emerge genkernel".
  • For some unknown reason, it seemed to hang (for days) while on the step "compiling modules", it may have been related to the fact that I locked the host computer just after starting the genkernel process. I did a ctrl-C to stop it and restarted "genkernel all". It ran overnight and finished this time.
Once I had the Gentoo up and running, I added the package to use the VirtualBox guest additions (as root):
emerge virtualbox-guest-additions

Install Musl:
download www.musl-libc.org/releases/musl-1.1.21.tar.gz
 tar -zxpvf musl-1.1.21.tar.gz
 cd musl-1.1.21
 ./configure
 make
 make install
 export PATH=$PATH:/usr/local/musl/bin 

I noticed that the heathen Gentoo came with Python 3 set as the default. Check which Python is set as the default:
python --version
If version 2 is set, then you can move on to the next section. If version 3 is selected:
eselect python list
If Python 2 is not on the list:
emerge --ask dev-lang/python:2.7
Otherwise, there should be a list of Pythons, find the option python 2.7, mine was number 2, then:
eselect python set 2

Install Ada:
download http://dianacoman.com/available_resources/gnat-gpl-2016-x86_64-linux-bin.tar.gz
 tar -zxvpf gnat-gpl-2016-x86_64-linux-bin.tar.gz
 cd gnat-gpl-2016-x86_64-linux-bin
 ./doinstall
 export PATH="/usr/gnat/bin:$PATH"

 download (I used curl -o FILENAME WEBSITEADDRESS
  ave1.org/tarpit/ada-musl-cross-2018-05-29.tgz
  ave1.org/tarpit/ada-musl-cross-2018-05-29.txt
  
 downloaded ave1 gpg pubkey: http://wot.deedbot.org/57EE94EA6F2049A47DAFA8568F4CE8F777BC59F9.asc
  saved as ave1.asc
  gpg --import ave1.asc
  gpg --verify ave1.org/tarpit/ada-musl-cross-2018-05-29.txt
  
  once verified, the text includes instructions to verify the .tgz
  
  unpack the archive
   tar -zxpvf ada-musl-cross-2018-05-29.tgz
  
  ./build-ada.sh PREFIX-DIRECTORY > build.output 2>&1
At first I tried to just emerge ada, but that pulled in a different version. I then got the version hosted on Diana Coman's site, but getting Ave1's to build seems to not have worked.

You can add a simple browser using:
emerge lynx

Then you can easily grab people's pubkeys off wot.deedbot.org

Add a version of V. I used the one from Diana Coman, which is just a v-ified version of mod6's v, which is hosted over at thebitcoin.foundation, but also adds keccak hashing. I went in and switched the defaults from .seals and .wot to seals and wot, but that is just my own personal preference. There is a bit of a chicken-egg problem here, so at some point you might end up with some vpatches without a working v yet, so to manually apply these things first manually check the signature using:
gpg --verify patchname.vpatch.WOTNAME.sig patchname.vpatch
And if that checks out,
patch -p0 < patchname.vpatch

Add Vtools (vdiff, vpatch, and ksum):
Download the vpatch and sig files from phf's site.
Either manually verify and patch as mentioned above, or use v to press.
in the pressed vtools directory, gprbuild ksum.gpr vdiff.gpr vpatch.gpr
copy the executable to somewhere on the path or add this directory to path (use export PATH="/path/to/this/dir:$PATH", where /path/to/this/dir is the directory where the vtools executables are)

Need parted for the Cuntoo build:
emerge parted

Grab the cuntoo tarball and Sig from Trinque:
curl -o cuntoo.tar http://trinque.org/cuntoo.tar
curl -o cuntoo.tar.sig http://trinque.org/cuntoo.tar.sig


Check the sig:
gpg --verify cuntoo.tar.sig cuntoo.tar

Unpack:
tar -xpvf cuntoo.tar.sig

I copied the config file from the running Gentoo into the cuntoo/config directory, I am not sure if that was the right thing to do?
cp /usr/src/linux/.config cuntoo/config/myconfig

Then go in and run the build. I am building it onto a thumb drive. It took me a minute (and a quick internet search) to figure out how to get my virtualbox to see the drive in question. There is a little USB icon at the bottom of the host window of the virtualbox, right click on that and select the thumbdrive. Check ls /dev/sd* before and after this and it should be obvious which disk it is, my hard drive is sda and the thumb drive is sdb.
cd cuntoo
./bootstrap.sh -k config/myconfig -d /dev/sdb > ../cuntoo-build-log.txt 2>&1

Well, it has been running a few hours, I will update once the script finishes...

Update: It ran for a while and then stopped with an error. I tried running it again without having it send everything to a file, and this time is stopped and asked me some questions about various things in the kernel build that were not covered by the config file. Then it had an error again and stopped, so I still don't have a finished build, and there is no obvious way to restart it without having to start back over at the very beginning of the script.

-

January 17, 2019

Walden by Henry David Thoreau

I recently finished reading Walden, by Henry David Thoreau.

The book describes Thoreau's time as he lived in a small cabin he built in the woods of Massachusetts, on the shores of Walden Pond. He describes building the cabin, living a simple life mostly separate from others, and the beauty of the environment throughout the seasons.

Thoreau could be described as a minimalist. He lives in a simple cabin, works a small garden in the mornings, and spends the afternoons taking walks through the woods or swimming in the pond. He lives on the bare necessities, and does the minimal amount of work to feed himself through the year, which leaves time for enjoyment of the little things.

The book was written in a different time, the are brief passages of narrative widely spaced between philosophical wanderings and vivid descriptions of the natural world. Some might call the book "boring", but I would rather call it "peaceful". He has a very down-to-earth, methodically rational worldview that is very different from the rushing, conclusion-jumping world of today's popular culture.

This is an example of classic American Literature, and I recommend that everyone should read it once.

-

January 16, 2019

A Simple Introduction to Crypto

Last weekend I was visiting with my grandmother and she said to me and my brothers "Can anybody explain crypto? I keep hearing about crypto on the news and I don't know what that is?"

We tried to briefly explain, but I don't think we did a good job. So I decided to lay out a simple groundwork to understand crypto that could be understood by anybody, even my grandmother.

The first thing to understand is that when the guys on the news talk about "crypto" they are probably talking about "cryptocurrencies", like Bitcoin, which could also be called cryptographic-currencies.

Let's start at the beginning: if you have a message written as letters, you can rewrite that as a big number. Here, let me demonstrate: lets's use a simple system where each letter corresponds to a two digit number, a is 01 on up to z is 26, make 00 a space and 27 a period and we can write a sentence. So to write "abc" we could use the number 010203, and 101112 would be "jkl".  Or the number 160529051800091900071805012027 is the message "peter is great." Actual cryptography will use ASCII or a similar system so that you have the whole alphabet, upper and lower case letters, a wide variety of punctuation, and numerals; but the underlying idea is the same - any message can be written as a really big number.

The next thing to understand is the idea of one-way or "trapdoor" functions. Let's take prime factoring as an example: what are the prime factors of 527 ? You might start by noticing it is odd, so not 2; then you start dividing each prime number going up - 3 does not work (if it is a multiple of 3 then the sum of the digits will also be); it's not a multiple of 5 (does not end in a 5 or 0); I don't know a trick for 7 but that does not divide evenly either; some people make it to 11 and then quit. But if I say what is 17 x 31 you might even be able to do it in your head: 10(17 x 3) + (17 x 1) -->  51_ + 17 -> 527. So you see that going one way (finding the prime factorization) takes much more work than going the other way (multiplying two primes). You can use a computer to make it easier, up to a point. If you have a "small" number the computer can factor it quickly, but as the number gets bigger the factorization takes longer and longer, so if you have a big enough number then not even the world's largest supercomputer can crack that prime factorization. (4096 bits should be enough for everybody)

People can then use such a one-way function to create what is called asymmetric cryptography. The idea here is that each person creates a pair of keys with a "public key" portion and a "private key" portion. A message is stored as a large number, a one-way function is used on it using the private key, and then anybody can check using the public key with the one-way function to prove that the message was made by that person. (Alternately, a message created using the public key can only be read by the person holding the private key, so this is also useful for secure communication).

As an example of a digital signature, the RSA system uses prime factorization, as mentioned above, to keep the private key secure. In RSA, a private key is made by taking two large primes (2048 bits long) and publishing their product (N) as part of the public key, along with an unrelated number (e). Using the two primes, the key generator also calculates e's modular inverse (d), which is a unique number, and stores that as the private key. Since you need the two primes to calculate d, and the number N is so large that it is impossible to factor, you can give other people the public key (e, N) and still the private key (d, N) will stay a secret. A message m (remember, the message is converted from letters to a really big number) is then signed by taking the modular exponentiation c = m^d mod N, and anybody can check that you signed it because they can easily calculate m = c^e mod N (this is true because e and d are modular inverses).

Once you have an asymmetric cryptographic system like RSA, or elliptic curve cryptography (ECC) which is more complicated but the basic idea is the same, then you can create a cryptocurrency. This is as simple as each person having a key-pair, and people can sign messages, or transactions, like "move $1 from {Peter's key} to {John's key}" - signed by {Peter's key}. Then everybody can check to see that was, in fact, signed by Peter. And if Peter had $1, then it is subtracted from his account and added to John's.

In a centralized system, with one company keeping a ledger with all the accounts, that will be sufficient. But if you are running a world-wide, peer-to-peer system and you receive such a transaction, how do you know Peter did not just sign a transaction giving all his money to Rachel instead and give that transaction to everybody else? You could say whichever message is received first is valid, but it is hard to get people spread around the world to agree on things like the order of messages because somebody else could have seen the messages in a different order.

The innovation of Bitcoin was to introduce the idea of a "blockchain" to serve as a secure, trustable ledger for transactions of digital money. Anybody can create transactions to move their own money within the system, called bitcoins, and these are shared with all users. A block is created by collecting valid transactions together and also lists the previous block. Thus a chain of these blocks is created, and balances are updated based on the transactions that are included in the blocks. So if Peter, who has 1 bitcoin in his account, creates one transaction that says "move 1 to John", and another that says "move 1 to Rachel", the person who creates the block will only include the one they heard first, and everybody will update the accounts based on the transaction that ends up in the blockchain; the other transaction will then be rejected by everybody.

In systems like Bitcoin, the people who publish these blocks to the blockchain are sometimes called "miners" because of the particular way in which Bitcoin introduces new money into the system: Each block is created with a certain amount of new bitcoin (started as 50 per block, cuts in half every 4 years, now at 12.5), and people making transactions include a "fee" to get their transaction included, these all go to the one person who makes the block (so people doing the work to check that transactions are valid and making the blocks are rewarded with a supply of new money, like people who work in mines are rewarded with a supply of new gold).

Naturally this incentivizes each person to have their own block included in the blockchain so they get the "miner reward", and if two different blocks are created at the same time which gets included? This is solved by the idea of "difficulty": each block is identified by a "hash function", another one-way function, which converts the contents into a number. The function is chosen to give an essentially random distribution. The difficulty is then calculated as a function of the number of leading zeros in the number. So 1234 would have a difficulty of 0, 0234 has a difficulty of 1 (probability of 1 in 10), and 0056 has a difficulty of 10 (1 in 100, ten times as hard as previous). Anyway, the next block has to meet a minimum difficulty score, which is adjusted periodically so that a new block is found roughly every ten minutes. If there are two competing blocks, the one included is always the one that has the greatest difficulty score. So the miners will build slightly different versions of a block and calculate the hash function until they find one with the right score.

The hash function is designed to be computationally difficult for computers. But a stronger computer will calculate it faster, and so in the beginning of bitcoin anybody could have their computer working on hashing blocks and expect to find a valid one every once in a while, a computer that was twice as fast would just get twice as many hits over a long period of time. Within a couple years of bitcoin starting, though, people had discovered that graphics cards could be programmed to do the hash calculation much faster (by orders of magnitude) than a normal computer CPU. So for a while people would buy high end graphics cards and stack them together. Within a few more years, though, specialty circuits were made which could do this calculation faster by a couple more orders of magnitude. Because of the way that the difficulty requirement is periodically redefined, these application specific circuits still generate about one block every ten minutes, while the chance that a normal computer will find a valid block is essentially 0, and all mining is controlled by a few companies in China that have built their own custom bitcoin-mining supercomputers.

The rule is that the only valid cryptocurrency blockchain is the one with the highest difficulty score, and for that there is nothing close to Bitcoin, which has been running since 2009. However, all those blocks add up, so to store the bitcoin blockchain requires several hundred gigabytes of memory. There are 1 TB disk drives available (1024 GB), so anybody can build a computer that is capable of holding all this data, and then they can run the check themself to show that any Bitcoin transaction is valid or not. This peer-to-peer structure makes Bitcoin more resilient than other types of digital currency which have a central point of failure. Because of this resiliency, the fact that Bitcoins can easily be sent anywhere around the globe instantly, and the fact that there is a defined limit to the total number of bitcoin (unlike US dollars, which can be printed whenever the US needs more money, causing inflation), Bitcoin can be used as a secure store of value or as a way to securely transfer funds globally, which is why the exchange rate has consistently increased over time (current exchange rate is about 3600 US dollars per bitcoin).

-