Add visibility rules.

This change marks public symbols as dynamically exported. This means
that it becomes viable to build a shared library of libcrypto and libssl
with -fvisibility=hidden.

On Windows, one not only needs to mark functions for export in a
component, but also for import when using them from a different
component. Because of this we have to build with
|BORINGSSL_IMPLEMENTATION| defined when building the code. Other
components, when including our headers, won't have that defined and then
the |OPENSSL_EXPORT| tag becomes an import tag instead. See the #defines
in base.h

In the asm code, symbols are now hidden by default and those that need
to be exported are wrapped by a C function.

In order to support Chromium, a couple of libssl functions were moved to
ssl.h from ssl_locl.h: ssl_get_new_session and ssl_update_cache.

Change-Id: Ib4b76e2f1983ee066e7806c24721e8626d08a261
Reviewed-on: https://boringssl-review.googlesource.com/1350
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/include/openssl/sha.h b/include/openssl/sha.h
index 2eda284..bc10d38 100644
--- a/include/openssl/sha.h
+++ b/include/openssl/sha.h
@@ -78,24 +78,24 @@
 #define SHA_LONG uint32_t
 
 /* SHA1_Init initialises |sha| and returns one. */
-int SHA1_Init(SHA_CTX *sha);
+OPENSSL_EXPORT int SHA1_Init(SHA_CTX *sha);
 
 /* SHA1_Update adds |len| bytes from |data| to |sha| and returns one. */
-int SHA1_Update(SHA_CTX *sha, const void *data, size_t len);
+OPENSSL_EXPORT int SHA1_Update(SHA_CTX *sha, const void *data, size_t len);
 
 /* SHA1_Final adds the final padding to |sha| and writes the resulting digest
  * to |md|, which must have at least |SHA_DIGEST_LENGTH| bytes of space. It
  * returns one. */
-int SHA1_Final(uint8_t *md, SHA_CTX *sha);
+OPENSSL_EXPORT int SHA1_Final(uint8_t *md, SHA_CTX *sha);
 
 /* SHA1 writes the digest of |len| bytes from |data| to |out| and returns
  * |out|. There must be at least |SHA_DIGEST_LENGTH| bytes of space in
  * |out|. */
-uint8_t *SHA1(const uint8_t *data, size_t len, uint8_t *out);
+OPENSSL_EXPORT uint8_t *SHA1(const uint8_t *data, size_t len, uint8_t *out);
 
 /* SHA1_Transform is a low-level function that performs a single, SHA-1 block
  * transformation using the state from |sha| and 64 bytes from |block|. */
-void SHA1_Transform(SHA_CTX *sha, const uint8_t *block);
+OPENSSL_EXPORT void SHA1_Transform(SHA_CTX *sha, const uint8_t *block);
 
 struct sha_state_st {
   uint32_t h0, h1, h2, h3, h4;
@@ -114,19 +114,19 @@
 #define SHA224_DIGEST_LENGTH 28
 
 /* SHA224_Init initialises |sha| and returns 1. */
-int SHA224_Init(SHA256_CTX *sha);
+OPENSSL_EXPORT int SHA224_Init(SHA256_CTX *sha);
 
 /* SHA224_Update adds |len| bytes from |data| to |sha|. */
-int SHA224_Update(SHA256_CTX *sha, const void *data, size_t len);
+OPENSSL_EXPORT int SHA224_Update(SHA256_CTX *sha, const void *data, size_t len);
 
 /* SHA224_Final adds the final padding to |sha| and writes the resulting digest
  * to |md|, which must have at least |SHA_DIGEST_LENGTH| bytes of space. */
-int SHA224_Final(uint8_t *md, SHA256_CTX *sha);
+OPENSSL_EXPORT int SHA224_Final(uint8_t *md, SHA256_CTX *sha);
 
 /* SHA224 writes the digest of |len| bytes from |data| to |out| and returns
  * |out|. There must be at least |SHA_DIGEST_LENGTH| bytes of space in
  * |out|. */
-uint8_t *SHA224(const uint8_t *data, size_t len, uint8_t *out);
+OPENSSL_EXPORT uint8_t *SHA224(const uint8_t *data, size_t len, uint8_t *out);
 
 
 /* SHA-256. */
@@ -138,23 +138,23 @@
 #define SHA256_DIGEST_LENGTH 32
 
 /* SHA256_Init initialises |sha| and returns 1. */
-int SHA256_Init(SHA256_CTX *sha);
+OPENSSL_EXPORT int SHA256_Init(SHA256_CTX *sha);
 
 /* SHA256_Update adds |len| bytes from |data| to |sha|. */
-int SHA256_Update(SHA256_CTX *sha, const void *data, size_t len);
+OPENSSL_EXPORT int SHA256_Update(SHA256_CTX *sha, const void *data, size_t len);
 
 /* SHA256_Final adds the final padding to |sha| and writes the resulting digest
  * to |md|, which must have at least |SHA_DIGEST_LENGTH| bytes of space. */
-int SHA256_Final(uint8_t *md, SHA256_CTX *sha);
+OPENSSL_EXPORT int SHA256_Final(uint8_t *md, SHA256_CTX *sha);
 
 /* SHA256 writes the digest of |len| bytes from |data| to |out| and returns
  * |out|. There must be at least |SHA_DIGEST_LENGTH| bytes of space in
  * |out|. */
-uint8_t *SHA256(const uint8_t *data, size_t len ,uint8_t *out);
+OPENSSL_EXPORT uint8_t *SHA256(const uint8_t *data, size_t len, uint8_t *out);
 
 /* SHA256_Transform is a low-level function that performs a single, SHA-1 block
  * transformation using the state from |sha| and 64 bytes from |block|. */
-void SHA256_Transform(SHA256_CTX *sha, const uint8_t *data);
+OPENSSL_EXPORT void SHA256_Transform(SHA256_CTX *sha, const uint8_t *data);
 
 struct sha256_state_st {
   uint32_t h[8];
@@ -173,23 +173,23 @@
 #define SHA384_DIGEST_LENGTH 48
 
 /* SHA384_Init initialises |sha| and returns 1. */
-int SHA384_Init(SHA512_CTX *sha);
+OPENSSL_EXPORT int SHA384_Init(SHA512_CTX *sha);
 
 /* SHA384_Update adds |len| bytes from |data| to |sha|. */
-int SHA384_Update(SHA512_CTX *sha, const void *data, size_t len);
+OPENSSL_EXPORT int SHA384_Update(SHA512_CTX *sha, const void *data, size_t len);
 
 /* SHA384_Final adds the final padding to |sha| and writes the resulting digest
  * to |md|, which must have at least |SHA_DIGEST_LENGTH| bytes of space. */
-int SHA384_Final(uint8_t *md, SHA512_CTX *sha);
+OPENSSL_EXPORT int SHA384_Final(uint8_t *md, SHA512_CTX *sha);
 
 /* SHA384 writes the digest of |len| bytes from |data| to |out| and returns
  * |out|. There must be at least |SHA_DIGEST_LENGTH| bytes of space in
  * |out|. */
-uint8_t *SHA384(const uint8_t *data, size_t len ,uint8_t *out);
+OPENSSL_EXPORT uint8_t *SHA384(const uint8_t *data, size_t len, uint8_t *out);
 
 /* SHA384_Transform is a low-level function that performs a single, SHA-1 block
  * transformation using the state from |sha| and 64 bytes from |block|. */
-void SHA384_Transform(SHA512_CTX *sha, const uint8_t *data);
+OPENSSL_EXPORT void SHA384_Transform(SHA512_CTX *sha, const uint8_t *data);
 
 
 /* SHA-512. */
@@ -201,23 +201,23 @@
 #define SHA512_DIGEST_LENGTH 64
 
 /* SHA512_Init initialises |sha| and returns 1. */
-int SHA512_Init(SHA512_CTX *sha);
+OPENSSL_EXPORT int SHA512_Init(SHA512_CTX *sha);
 
 /* SHA512_Update adds |len| bytes from |data| to |sha|. */
-int SHA512_Update(SHA512_CTX *sha, const void *data, size_t len);
+OPENSSL_EXPORT int SHA512_Update(SHA512_CTX *sha, const void *data, size_t len);
 
 /* SHA512_Final adds the final padding to |sha| and writes the resulting digest
  * to |md|, which must have at least |SHA_DIGEST_LENGTH| bytes of space. */
-int SHA512_Final(uint8_t *md, SHA512_CTX *sha);
+OPENSSL_EXPORT int SHA512_Final(uint8_t *md, SHA512_CTX *sha);
 
 /* SHA512 writes the digest of |len| bytes from |data| to |out| and returns
  * |out|. There must be at least |SHA_DIGEST_LENGTH| bytes of space in
  * |out|. */
-uint8_t *SHA512(const uint8_t *data, size_t len ,uint8_t *out);
+OPENSSL_EXPORT uint8_t *SHA512(const uint8_t *data, size_t len, uint8_t *out);
 
 /* SHA512_Transform is a low-level function that performs a single, SHA-1 block
  * transformation using the state from |sha| and 64 bytes from |block|. */
-void SHA512_Transform(SHA512_CTX *sha, const uint8_t *data);
+OPENSSL_EXPORT void SHA512_Transform(SHA512_CTX *sha, const uint8_t *data);
 
 struct sha512_state_st {
   uint64_t h[8];