GCM code from https://code.google.com/p/gcm/