Modify RAND_bytes calls to handle -1 return code.

Bug: 20554394
Change-Id: I54dce88f7bb90bd5660e9d3a7be9b9646bcc12bd
(cherry picked from commit 9ee79fb55049c242b12e067df1a824f18622ccfd)
diff --git a/aead_mode_operation.cpp b/aead_mode_operation.cpp
index 1e697eb..357dce6 100644
--- a/aead_mode_operation.cpp
+++ b/aead_mode_operation.cpp
@@ -159,7 +159,7 @@
 }
 
 keymaster_error_t AeadModeOperation::GenerateNonce() {
-    if (RAND_bytes(nonce_, nonce_length_))
+    if (RAND_bytes(nonce_, nonce_length_) == 1)
         return KM_ERROR_OK;
     LOG_S("Failed to generate %d-byte nonce", nonce_length_);
     return TranslateLastOpenSslError();
diff --git a/aes_operation.cpp b/aes_operation.cpp
index 37a45c3..54652e8 100644
--- a/aes_operation.cpp
+++ b/aes_operation.cpp
@@ -303,7 +303,7 @@
     iv_.reset(new uint8_t[AES_BLOCK_SIZE]);
     if (!iv_.get())
         return KM_ERROR_MEMORY_ALLOCATION_FAILED;
-    if (!RAND_bytes(iv_.get(), AES_BLOCK_SIZE))
+    if (RAND_bytes(iv_.get(), AES_BLOCK_SIZE) != 1)
         return TranslateLastOpenSslError();
     return KM_ERROR_OK;
 }
diff --git a/operation_table.cpp b/operation_table.cpp
index 14ca2dd..e4b9e33 100644
--- a/operation_table.cpp
+++ b/operation_table.cpp
@@ -38,7 +38,7 @@
     }
 
     UniquePtr<Operation> op(operation);
-    if (RAND_bytes(reinterpret_cast<uint8_t*>(op_handle), sizeof(*op_handle)) == 0)
+    if (RAND_bytes(reinterpret_cast<uint8_t*>(op_handle), sizeof(*op_handle)) != 1)
         return TranslateLastOpenSslError();
     if (*op_handle == 0) {
         // Statistically this is vanishingly unlikely, which means if it ever happens in practice,
diff --git a/symmetric_key.cpp b/symmetric_key.cpp
index 8b84dd7..8066b10 100644
--- a/symmetric_key.cpp
+++ b/symmetric_key.cpp
@@ -36,7 +36,7 @@
     if (!key.get())
         return NULL;
 
-    if (!RAND_bytes(key->key_data_.get(), key->key_data_size_)) {
+    if (RAND_bytes(key->key_data_.get(), key->key_data_size_) != 1) {
         LOG_E("Error %ul generating %d bit AES key", ERR_get_error(), key->key_data_size_ * 8);
         *error = TranslateLastOpenSslError();
         return NULL;