Just Visiting This Planet..


AlphaZero, the new Chess Prodigy

In December of this year (2018), Google released 1000 games of AlphaZero versus Stockfish – both chess programs.  Until now Stockfish was the reigning king of chess programs, but AlphaZero is the new kid on the block it soundly beat Stockfish.  Yes, that should scare all of us. It should scare all of us because it is the way AlphaZero works.

Deep Blue versus Gary Kaparov was the beginning of machine domination of the game.  Today, the highest rated human player (Carlsen) is 2800+ and the highest rated program (Stockfish) is about 3400 to 3600!  Stockfish would beat Carlsen every day of the week and twice on Sundays.  It would not even be a competition.  Such is the power of today’s chess engines.

Humans have played chess for over 1,000 years and today’s chess engines are finely tuned computing machines that have been coded with all the knowledge humans have gained about chess through these years. These engines have broad and deep opening databases, end-game strategies, they are fine-tuned by grandmasters, they understand piece valuation, and so on.  For example, an engine knows that a rook is 5 points worth and a bishop or a knight is 3 points worth.  An engine knows that certain opening favors white statistically and others not.

But then DeepMind – a company founded in London 5 years ago and now acquired by Google – went even further.  They wrote the first artificial intelligence based program to play chess.  It is called AlphaZero.

Unlike chess engines of today (like Stockfish), AlphaZero understands nothing about game.  Let me say it again – it understands NOTHING.  It only knows the rules of the game and conditions for winning (checkmate).  It has no opening database, no end-game strategies, no grandmaster wisdom, no historical knowledge of which openings are better for white statistically, and so on.  NADA.

So how does it get better?

It plays against itself to learn the game, using the rules of the game.  In the beginning it makes random moves, makes horrible mistakes– just like a novice. But then soon it learns – just like a human and improves its game.  Eventually, after playing a few million games, it becomes really really good.  But you see, it takes very little time to play these games.  Before playing StockFish, AlphaZero played against itself for only four hours!  In four hours, it acquired all there is to learn to play the game.  And it has soundly beaten Stockfish!  It plays like no other human and it plays like no other engine. It makes moves we have not seen before and yet it wins the games against the most powerful engines of today.

The AlphaZero versus StockFish games are being analyzed on YouTube.  In fours hours of play AlphaZero beat 1000 years of chess knowhow humans had acquired.  And that should give all of us a pause.

But here is the real scary part.  AlphaZero taught itself to play other games too!  It has mastered GO – a Chinese game that is far more complex than chess, and most recently it mastered a Japanese game Shogi (another board game).  AlphaZero is the world champion in GO, CHESS, and SHOGI.  It has beaten world champions in all these three games.

AlphaZero uses deep neural networks and reinforcement learning AI techniques to learn – in fact teach itself – how to play games.  I find that astonishing that all the human knowhow of chess and all the research in building great chess engines is soundly beaten by AlphaZero after four hours of training.

I am sure the field of AI has many such surprises for us.


FIPS Compliance, AES, and .NET Crypto

FIPS compliance of the .Net crypto API, something I never thought a client would be bothered about.  Right?

Of course, I was wrong.

A client, whose system I was reviewing late last year, wanted to use FIPS compliant .NET crypto APIs due to reasons not directly related to security as it turns out (it was in support of a claim in their patent application).

The client intended to use the AES encryption in the CBC mode, a 256-bit key, and a randomized IV.  All good stuff.  The not-so-good stuff, however, was the use ofRijndaelManaged class in the System.Security.Cryptography module for the AES encryption.  The RijndaelManaged class implements the Rijndael algorithm and can be used for the AES encryption in some restrictive cases. As it turns out, the .NET class library containing this class is not FIPS compliant.

First and foremost, what is the difference between AES and Rijndael?

AES and Rijndael
AES is a standard; Rijndael is an algorithm.

When NIST wanted an alternative to DES (3-DES) algorithms, they requested proposals for algorithms that would be the new AES standard. The winning algorithm had to support key sizes of 128, 192, and 256 bits, and a block-size of 128 bits. The Rijndael algorithm won and its specific implementation (with block-size/key-length restrictions) was adopted as the AES standard. Whereas, Rijndael allows for both key and block-sizes to be chosen independently from the set of {128, 160, 192, 224, 256} bits, AES is a Rijndael implementation that allows key sizes from {128, 192, 256} bits and the block-size of 128 bits.

FIPS-197 publication has the gory details of the AES specification.

What is FIPS compliance?
Any cryptographic implementation module (usually a library) can be certified for FIPS compliance within the Cryptographic Module Validation Program (CMVP).  FIPS compliance guarantees that if an implementation is certified, algorithms within it (say AES) will comply with the standard specification and therefore will be interoperable with other standard implementations.

In the land of .NET, there are many ways to perform AES encryption, unfortunately, not all of them are FIPS compliant.

  • AESCryptoServiceProvider in the System.Security.Cryptography module: This class uses Windows CryptoAPI (CAPI) which uses RSAENH.DLL which is FIPS-compliant. In the .NET world, this is the best option for using AES in any mode of operation (e.g. CBC, CFB, OFB).
  • RijndaelManaged in the System.Security.Cryptography module:  This module is not FIPS compliant.  However, this class can be used to perform AES encryption in CBC mode only if the block-size is set to 128 bits and key length is in {128, 192, 256} bits. Due to feedback size issues, this class cannot be used to perform encryption in CFB/OFB modes. In essence, do not use this class unless you want to support block-sizes other than 128 bits.
  • AESManaged in the System.Security.Cryptography module: This is just a wrapper for the RijndaelManaged class where the block-size is fixed to 128 bits.   Obviously, this is not FIPS compliant and is only good for the CBC mode encryption of AES.  As anticipated, it does not support the feedback size and therefore cannot be used for CFB or OFB modes of AES.  Do not use this class.

If you turn on the registry flag
only the FIPS compliant .NET crypto classes will work. In general, none of the classes ending with “Managed” will work since none of them, at least so far, are FIPS compliant.

In conclusion,

  • If FIPS compliance is required turn on the registry flag referenced in the previous paragraph
  • For AES encryption, always use the AESCryptoServiceProvider class
  • Do not use AESManaged or RijndaelManaged unless you require a block size other than 128 bits.