Safety is a critical property for control systems in medicine, transportation, manufacturing, and other applications, and can be defined as ensuring positive invariance of a predefined safe set. One approach to ensuring safety is to construct a Control Barrier Function (CBF) such that the system is safe when the CBF is nonnegative, and then choose a control input to ensure nonnegativity of the CBF at each time step, provided that such an input exists. This paper investigates the problems of verification and synthesis of control barrier functions. In the area of verification, we use the algebraic-geometric Positivstellensatz to construct convex equivalent conditions for a CBF to ensure safety. We extend these conditions to control policies based on unions and intersections of CBFs, highorder CBFs, and systems with trigonometric dynamics, actuation constraints, and Euler-Lagrange dynamics. In the area of synthesis, we propose algorithms for constructing CBFs, namely, an alternating-descent approach, a local CBF approach, and a Newton's method approach. We prove that the latter algorithm guarantees local convergence to a CBF at a quadratic rate.