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).

-

October 31, 2018

Michigan Gerrymandering Proposal

In the upcoming election, in Michigan there is a proposal to change the way that districts for congressional elections are created (Proposal 2).

Currently, the map of districts is drawn by the state legislature. In 2010 there was a backlash from the Obama administration and the Republicans took complete control of the Michigan legislature. They then proceeded to draw some questionable districts which favor the Republican incumbents, and so even though the State elects Democratic senators the Republicans control a large majority of Michigan's delegation to the House of Representatives.

The proposal on the ballot would change this so that an "independent committee" would instead draw the district lines.

I thought it would interesting to see how different the map would look if made in a way that was not so partisan. First, let's take a look at the current district map.


Some things to note:
  • Districts 2 and 3 meet in the Grand Rapids area, the way that the line is drawn makes both districts lean strongly Republican, since the Democrat leaning areas are split. If the line was straight then district 3 would be more of a toss-up.
  • Districts 4 and 10 lean Republican, all of the Democrat-leaning areas of Flint, Saginaw, and Bay City were combined into one district to make the other two strongly Republican, rather than having 3 toss-up districts.
  • District 8 includes most of the very left-leaning Lansing, but conveniently stretches around the top of the Detroit suburbs to reach the right-leaning Rochester Hills, making a consistently Republican district.
  • The way districts 9, 11, and 14 spiral around each other just screams Gerrymandering.
So I made my own map. First I tried to follow county lines as much as possible, grouping adjacent counties together to get close to the population of a representative district, and only splitting up counties that contained a higher population than allowed in a district (Macomb, Oakland, and Wayne counties). This worked nicely, getting each district pretty close to the right population. The result is shown below.

The lines around the Detroit area within counties I left rather vague, for the actual map a similar approach would be taken, trying to follow city and township lines to make the district as compact as possible. For example, Macomb county has its population concentrated at the south end, so the actual line would be much farther south.

My initial guess would be that Democrats would control districts 8, 12, and 13, Republicans would control districts 1, 2, and 9, and that there would be more of a toss-up in the other eight districts.

Update: The redistricting will take place after the next census. Estimates are showing that Michigan will lose one congressional district. So I decided to make a second map using only 13 districts.



September 11, 2018

Security Theater

The other day I was at the hardware store with my wife. She has been thinking of installing cameras around her business to keep an eye on things, and so we were looking at the store's section of security cameras. I noticed on the shelf they had a couple boxes that were pretty cheap, only ten bucks, and so I picked one up to look at it. To my dismay, I found out that this is not an actual camera, it is a decoy. It even comes with a little blinking red led so that it looks like it is on. Not only did they have decoy cameras, but these are offered by multiple brands.

This is just silly security theater. These decoy cameras project a sad facade of security with no actual security behind them.

July 30, 2018

Fasting Prayer of a Young Boy

My Sunday school teacher said to me
That fasting is good for the soul.
And though I'm a lad of tender years,
I thought I'd give it a go.

My stomach rumbles, my head is faint;
Oh, this is how I'm brought low.
I perish! Unless I break this fast
I started ten minutes ago.

-

July 11, 2018

vdiff_sha_define_swap.vpatch

Recently I tried building vtools on a windows system running cygwin. I found that there was one function it barfed on, SWAP_BE64. I did some digging, and I found the code was taken from busybox. I dug around a bit there, and I found where the thing is defined, so I copied that definition into my copy of the program, and it worked.

Keep in mind, this function seems to depend on the endianness of the machine, so in the busybox code there are a bunch of #IFDEFs surrounding this definition. If you are using a big-endian machine then you would want to apply a different definition for this function.

This is a patch using sha hashing. There seems to be some movement leaning towards using the Keccak hash for vpatches (see this discussion and that following it), so I might have to get a Keccak hasher and regrind this later.

File vdiff_sha_define_swap.vpatch :

diff -uNr vdiff_a/vtools/manifest vdiff_b/vtools/manifest
--- vdiff_a/vtools/manifest cece6cf281356c63d1f0a935d8f772345b51f63bc77ada2b70646b395036a22a88962e06661dee77977e1d434290adec5d76e540597bbd2213a36cb5890a8cf8
+++ vdiff_b/vtools/manifest 2e651c3ae3f563a3ee7f6a0cfbd3f18e76bf57f81615643e6df3c60f6d6a2d868a5ff9809de76184ee9779091d621ef088d5f695c2c7d9d5b0fd040d7173ab8f
@@ -6,3 +6,5 @@
Fixes C99 compatibity for __attribute__((noreturn)), vdiff support for "No newline at end of file" directive.
2018-04-07 phf
Fixes for xalloc's use of static inline courtesy of spyked.
+2018-06-28 PeterL
+Added definition for SWAP_BE64 in sha.c (valid for littleendian system).
\ No newline at end of file
diff -uNr vdiff_a/vtools/src/sha.c vdiff_b/vtools/src/sha.c
--- vdiff_a/vtools/src/sha.c 8ef7baea0ae21e44b34318a0202e3a7c4ca1fe4df6c1a8a29d8a5eeee930926968ea9bd062c514460208bf89e2fa4ec958950c3776b47513cd5979961e4182c6
+++ vdiff_b/vtools/src/sha.c 3eac373f23f903ef55354750cf8921a705aefa2cb61a1e8acc0fc091fc357b434fd0598822f90beaa1d1c4ecf4ede4d2184eb12764f806d304fc70575967a4a5
@@ -3,6 +3,9 @@
#include
#include

+/* SWAP_BEnn means "convert CPU<->big_endian by swapping bytes" */
+# define SWAP_BE64(x) __bswap64(x)
+
/* \url{https://git.busybox.net/busybox/tree/libbb/hash_md5_sha.c} */

static inline uint64_t rotr64(uint64_t x, unsigned n) {


And here is the signature for the file, vdiff_sha_define_swap.vpatch.PeterL.sig :

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAABAgAGBQJbRsWTAAoJELTi4Nystj0ltSUP/A9V+5pjBVYr6qOZLOYCOF6c
/pU4YvdVW9sMc6EZ/p0Vdq6bWGr/RIhkgMiPsHhnxsdHS6xSpEFGWOMj+mzOBjRd
7sJl3GEZ14kKbweP+Z/Uwky/yYG5MAKORLBGb24HF+aBdShq3GqQFcd2B9Rb/F3g
YgIwLY4gVBsFFgjTBR47/9rXJAgpJKb3S/dPQ3sdWoLXb1ZO4ayZfzcjeCmEpuyq
DbjSbPiiHvfoTSJ4/N8UdNSAccV1UKofnpnnhQ4A43mEQ3T00Q7tnI7NzW3wLD3K
3PPEQOduAffdrPbliigVLQhDOzHiIyuQhENVI7N8IQwUxvjF6RJ3A+YWHeMAvLf9
yTOf7DSIUWMee4YX02ZhPvclomrG9+PRJUkDsk7LqwoNxVEo5ZeXlPFIE4zBYQZg
F+my5bNl4OqJzJT/0voMMza6oDNXIigX/kSqJuCEuQ+dMX0XgbiejX94GmAWO+qB
DuyQuYCdslH8dVmEd1UBKQKL/6or6HFxTOSDDUUdfcRBbrWLFdToyaWMxIz3Ea5z
m8hcDi+olE5yTKz6DAvy0SDrOwlOk0cCXoeo1XuiVVwfdzRiYPFKWkWFqFleZghm
FIZif8TuRJl6LunzV2L9P2RZn2sNuN59cuwC0e7+7XW1XroP1VPmLNP+/yaeK/gR
kdTB76aB/ebzaUXqV+U4
=rxQr
-----END PGP SIGNATURE-----

-

Chicken Potato Soup

This is a yummy soup with lots of flavors. I made this soup in an InstaPot (electronic pressure cooker), but you could also make it more traditionally in a pot on the stove.

Ingredients

  • 1 Tab butter
  • 1 Tab cooking oil
  • 3 cloves garlic, chopped finely
  • About a pound of chicken breast, cubed into about 1 inch pieces
  • About a pound of potatoes, cubed into about 1 inch pieces 
  • 1 yellow squash, cubed into about 1 inch pieces
  • 2 cups chicken broth
  • 1 tsp pepper
  • 1 tsp thyme
  • 1 tsp Garam Masala
  • 1 lemon

Procedure - InstaPot

  1. Turn the InstaPot on with "Saute" mode. Add butter, oil, and garlic, stirring frequently. Once the oil is hot, let the garlic cook a minute until it gets soft.
  2. Add the chicken. Stir frequently, cook until the chicken is slightly browned on the outside.
  3. Add the potatoes, squash, broth, pepper, thyme, and Garam Masala. Stir everything together.
  4. Cut the lemon in half, squeeze the juice out of both sides into the pot.
  5. Close the InstaPot, cook on the poultry setting for 12 minutes.

Procedure - Stovetop

Proceed as above, saute the garlic and chicken on medium-high heat. Add all other ingredients, and add water to cover all ingredients, bring to a boil. Reduce the heat to a simmer and cook until the potatoes are soft (check by poking them with a fork).

-